001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2009 Sun Microsystems, Inc. 015 * Portions Copyright 2012-2016 ForgeRock AS. 016 */ 017package org.opends.server.extensions; 018 019import java.util.List; 020 021import org.forgerock.i18n.LocalizableMessage; 022import org.forgerock.opendj.ldap.ByteString; 023import org.forgerock.opendj.ldap.ConditionResult; 024import org.forgerock.opendj.ldap.ResultCode; 025import org.forgerock.opendj.server.config.server.StructuralObjectClassVirtualAttributeCfg; 026import org.opends.server.api.VirtualAttributeProvider; 027import org.opends.server.core.SearchOperation; 028import org.opends.server.types.Attribute; 029import org.opends.server.types.Attributes; 030import org.opends.server.types.Entry; 031import org.opends.server.types.VirtualAttributeRule; 032 033import static org.opends.messages.ExtensionMessages.*; 034 035/** 036 * This class implements a virtual attribute provider that is meant to serve 037 * the structuralObjectClass operational attribute as described in RFC 4512. 038 */ 039public class StructuralObjectClassVirtualAttributeProvider 040 extends VirtualAttributeProvider<StructuralObjectClassVirtualAttributeCfg> 041{ 042 /** Creates a new instance of this structuralObjectClass virtual attribute provider. */ 043 public StructuralObjectClassVirtualAttributeProvider() 044 { 045 super(); 046 047 // All initialization should be performed in the 048 // initializeVirtualAttributeProvider method. 049 } 050 051 @Override 052 public boolean isMultiValued() 053 { 054 return false; 055 } 056 057 @Override 058 public Attribute getValues(Entry entry, VirtualAttributeRule rule) 059 { 060 return Attributes.create(rule.getAttributeType(), entry 061 .getStructuralObjectClass().getNameOrOID()); 062 } 063 064 @Override 065 public boolean hasValue(Entry entry, VirtualAttributeRule rule) 066 { 067 return entry.getStructuralObjectClass() != null; 068 } 069 070 @Override 071 public ConditionResult matchesSubstring(Entry entry, 072 VirtualAttributeRule rule, 073 ByteString subInitial, 074 List<ByteString> subAny, 075 ByteString subFinal) 076 { 077 //Substring matching is not supported. 078 return ConditionResult.UNDEFINED; 079 } 080 081 @Override 082 public ConditionResult greaterThanOrEqualTo(Entry entry, 083 VirtualAttributeRule rule, 084 ByteString value) 085 { 086 // An object class can not be used for ordering. 087 return ConditionResult.UNDEFINED; 088 } 089 090 @Override 091 public ConditionResult lessThanOrEqualTo(Entry entry, 092 VirtualAttributeRule rule, 093 ByteString value) 094 { 095 // An object class can not be used for ordering. 096 return ConditionResult.UNDEFINED; 097 } 098 099 @Override 100 public ConditionResult approximatelyEqualTo(Entry entry, 101 VirtualAttributeRule rule, 102 ByteString value) 103 { 104 // An object class can not be used in approximate matching. 105 return ConditionResult.UNDEFINED; 106 } 107 108 @Override 109 public boolean isSearchable(VirtualAttributeRule rule, 110 SearchOperation searchOperation, 111 boolean isPreIndexed) 112 { 113 // This attribute is not searchable, since it will have the same value in 114 // tons of entries. 115 return false; 116 } 117 118 @Override 119 public void processSearch(VirtualAttributeRule rule, 120 SearchOperation searchOperation) 121 { 122 searchOperation.setResultCode(ResultCode.UNWILLING_TO_PERFORM); 123 124 LocalizableMessage message = ERR_VATTR_NOT_SEARCHABLE.get( 125 rule.getAttributeType().getNameOrOID()); 126 searchOperation.appendErrorMessage(message); 127 } 128}