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-2015 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.opends.server.admin.std.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 /** 043 * Creates a new instance of this structuralObjectClass virtual attribute 044 * provider. 045 */ 046 public StructuralObjectClassVirtualAttributeProvider() 047 { 048 super(); 049 050 // All initialization should be performed in the 051 // initializeVirtualAttributeProvider method. 052 } 053 054 /** {@inheritDoc} */ 055 @Override 056 public boolean isMultiValued() 057 { 058 return false; 059 } 060 061 /** {@inheritDoc} */ 062 @Override 063 public Attribute getValues(Entry entry, VirtualAttributeRule rule) 064 { 065 return Attributes.create(rule.getAttributeType(), entry 066 .getStructuralObjectClass().getNameOrOID()); 067 } 068 069 /** {@inheritDoc} */ 070 @Override 071 public boolean hasValue(Entry entry, VirtualAttributeRule rule) 072 { 073 return entry.getStructuralObjectClass() != null; 074 } 075 076 /** {@inheritDoc} */ 077 @Override 078 public ConditionResult matchesSubstring(Entry entry, 079 VirtualAttributeRule rule, 080 ByteString subInitial, 081 List<ByteString> subAny, 082 ByteString subFinal) 083 { 084 //Substring matching is not supported. 085 return ConditionResult.UNDEFINED; 086 } 087 088 /** {@inheritDoc} */ 089 @Override 090 public ConditionResult greaterThanOrEqualTo(Entry entry, 091 VirtualAttributeRule rule, 092 ByteString value) 093 { 094 // An object class can not be used for ordering. 095 return ConditionResult.UNDEFINED; 096 } 097 098 /** {@inheritDoc} */ 099 @Override 100 public ConditionResult lessThanOrEqualTo(Entry entry, 101 VirtualAttributeRule rule, 102 ByteString value) 103 { 104 // An object class can not be used for ordering. 105 return ConditionResult.UNDEFINED; 106 } 107 108 /** {@inheritDoc} */ 109 @Override 110 public ConditionResult approximatelyEqualTo(Entry entry, 111 VirtualAttributeRule rule, 112 ByteString value) 113 { 114 // An object class can not be used in approximate matching. 115 return ConditionResult.UNDEFINED; 116 } 117 118 /** {@inheritDoc} */ 119 @Override 120 public boolean isSearchable(VirtualAttributeRule rule, 121 SearchOperation searchOperation, 122 boolean isPreIndexed) 123 { 124 // This attribute is not searchable, since it will have the same value in 125 // tons of entries. 126 return false; 127 } 128 129 /** {@inheritDoc} */ 130 @Override 131 public void processSearch(VirtualAttributeRule rule, 132 SearchOperation searchOperation) 133 { 134 searchOperation.setResultCode(ResultCode.UNWILLING_TO_PERFORM); 135 136 LocalizableMessage message = ERR_VATTR_NOT_SEARCHABLE.get( 137 rule.getAttributeType().getNameOrOID()); 138 searchOperation.appendErrorMessage(message); 139 } 140} 141