| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2012 ForgeRock AS |
| | | * Portions Copyright 2012-2013 ForgeRock AS |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | | |
| | | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | |
| | | import org.opends.server.admin.std.server. |
| | | GoverningStructureRuleVirtualAttributeCfg; |
| | | import org.opends.server.api.VirtualAttributeProvider; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.SearchOperation; |
| | | import org.opends.server.types.*; |
| | | |
| | | import static org.opends.messages.ExtensionMessages.*; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This class implements a virtual attribute provider that is meant to serve |
| | | * the governingStructuralRule operational attribute as described in RFC 4512. |
| | |
| | | // initializeVirtualAttributeProvider method. |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | public void initializeVirtualAttributeProvider( |
| | | GoverningStructureRuleVirtualAttributeCfg configuration) |
| | | throws ConfigException, InitializationException |
| | | { |
| | | // No initialization is required. |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override() |
| | | public boolean isMultiValued() |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override() |
| | | public Set<AttributeValue> getValues(Entry entry, |
| | | VirtualAttributeRule rule) |
| | |
| | | return Collections.<AttributeValue>emptySet(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override() |
| | | public boolean hasValue(Entry entry, VirtualAttributeRule rule) |
| | | { |
| | | return getDITStructureRule(entry)!=null; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override() |
| | | public ConditionResult matchesSubstring(Entry entry, |
| | | VirtualAttributeRule rule, |
| | |
| | | return ConditionResult.UNDEFINED; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override() |
| | | public ConditionResult greaterThanOrEqualTo(Entry entry, |
| | | VirtualAttributeRule rule, |
| | |
| | | return ConditionResult.UNDEFINED; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override() |
| | | public ConditionResult lessThanOrEqualTo(Entry entry, |
| | | VirtualAttributeRule rule, |
| | |
| | | return ConditionResult.UNDEFINED; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override() |
| | | public ConditionResult approximatelyEqualTo(Entry entry, |
| | | VirtualAttributeRule rule, |
| | |
| | | return ConditionResult.UNDEFINED; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override() |
| | | public boolean isSearchable(VirtualAttributeRule rule, |
| | | SearchOperation searchOperation, |
| | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override() |
| | | public void processSearch(VirtualAttributeRule rule, |
| | | SearchOperation searchOperation) |
| | |
| | | searchOperation.appendErrorMessage(message); |
| | | } |
| | | |
| | | |
| | | |
| | | //Checks if the entry matches the nameform. |
| | | /** Checks if the entry matches the nameform. */ |
| | | private boolean matchesNameForm(NameForm nameForm, |
| | | AcceptRejectWarn structuralPolicy, |
| | | Entry entry) |
| | |
| | | // Make sure that all the required attributes are present. |
| | | for (AttributeType t : nameForm.getRequiredAttributes()) |
| | | { |
| | | if (! rdn.hasAttributeType(t)) |
| | | if (!rdn.hasAttributeType(t) |
| | | && structuralPolicy == AcceptRejectWarn.REJECT) |
| | | { |
| | | if (structuralPolicy == AcceptRejectWarn.REJECT) |
| | | { |
| | | return false; |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | |
| | |
| | | for (int i = 0; i < numAVAs; i++) |
| | | { |
| | | AttributeType t = rdn.getAttributeType(i); |
| | | if (! nameForm.isRequiredOrOptional(t)) |
| | | if (!nameForm.isRequiredOrOptional(t) |
| | | && structuralPolicy == AcceptRejectWarn.REJECT) |
| | | { |
| | | if (structuralPolicy == AcceptRejectWarn.REJECT) |
| | | { |
| | | return false; |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | |
| | | |
| | | //Finds the appropriate DIT structure rule for an entry. |
| | | /** Finds the appropriate DIT structure rule for an entry. */ |
| | | private DITStructureRule getDITStructureRule(Entry entry) |
| | | { |
| | | ObjectClass oc = entry.getStructuralObjectClass(); |
| | |
| | | //select the first one that matches. Since the entry exists, the same |
| | | //algorithm should work fine to retrieve the nameform which was |
| | | //applied while creating the entry. |
| | | if(listForms != null) |
| | | if (listForms != null) |
| | | { |
| | | boolean obsolete = true; |
| | | AcceptRejectWarn structuralPolicy = |
| | | DirectoryServer.getSingleStructuralObjectClassPolicy(); |
| | | for(NameForm nf : listForms) |
| | | DirectoryServer.getSingleStructuralObjectClassPolicy(); |
| | | for (NameForm nf : listForms) |
| | | { |
| | | if(!nf.isObsolete()) |
| | | if (!nf.isObsolete()) |
| | | { |
| | | obsolete = false; |
| | | if(matchesNameForm(nf, |
| | | structuralPolicy, entry)) |
| | | if (matchesNameForm(nf, structuralPolicy, entry)) |
| | | { |
| | | nameForm = nf; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if( nameForm != null && !obsolete) |
| | | if (nameForm != null && !obsolete) |
| | | { |
| | | ditRule = |
| | | DirectoryServer.getDITStructureRule(nameForm); |
| | | ditRule = DirectoryServer.getDITStructureRule(nameForm); |
| | | } |
| | | } |
| | | return ditRule; |