Use AttributeDescription in Entry and Attribute
Entry.java, Attribute.java:
Generally speaking, the methods that previously accepted both AttributeType and Collection<String> parameters
have been changed to now accept AttributeDescription instead.
AttributeDescription.java: REMOVED
1 files deleted
36 files modified
| | |
| | | import org.opends.server.core.ServerContext; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeBuilder; |
| | | import org.opends.server.types.AttributeDescriptions; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.ObjectClass; |
| | |
| | | final Attribute attribute) throws DirectoryException |
| | | { |
| | | // Re-use or allocate a new ID. |
| | | int id = getAttributeId(AttributeDescriptions.create(attribute)); |
| | | int id = getAttributeId(attribute.getAttributeDescription()); |
| | | |
| | | // Encode the attribute. |
| | | final byte[] idBytes = encodeId(id); |
| | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.admin.std.server.DseeCompatAccessControlHandlerCfg; |
| | | import org.opends.server.api.AccessControlHandler; |
| | | import org.opends.server.api.ClientConnection; |
| | |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.protocols.ldap.LDAPControl; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.workflowelement.localbackend.*; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeBuilder; |
| | | import org.opends.server.types.AuthenticationInfo; |
| | | import org.opends.server.types.Control; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.InitializationException; |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.types.Operation; |
| | | import org.opends.server.types.Privilege; |
| | | import org.opends.server.types.RDN; |
| | | import org.opends.server.types.SearchFilter; |
| | | import org.opends.server.types.SearchResultEntry; |
| | | import org.opends.server.types.SearchResultReference; |
| | | import org.opends.server.workflowelement.localbackend.LocalBackendAddOperation; |
| | | import org.opends.server.workflowelement.localbackend.LocalBackendCompareOperation; |
| | | import org.opends.server.workflowelement.localbackend.LocalBackendDeleteOperation; |
| | | import org.opends.server.workflowelement.localbackend.LocalBackendModifyOperation; |
| | | import org.opends.server.workflowelement.localbackend.LocalBackendSearchOperation; |
| | | |
| | | import static org.opends.messages.AccessControlMessages.*; |
| | | import static org.opends.server.authorization.dseecompat.Aci.*; |
| | |
| | | && resourceEntry.hasAttribute(modAttrType)) |
| | | { |
| | | container.setCurrentAttributeType(modAttrType); |
| | | for (Attribute a : resourceEntry.getAttribute(modAttrType, modAttr.getOptions())) |
| | | for (Attribute a : resourceEntry.getAttribute(modAttr.getAttributeDescription())) |
| | | { |
| | | for (ByteString v : a) |
| | | { |
| | |
| | | break; |
| | | case INCREMENT: |
| | | Entry modifiedEntry = operation.getModifiedEntry(); |
| | | for (Attribute attr : modifiedEntry.getAttribute(modAttrType, modAttr.getOptions())) |
| | | for (Attribute attr : modifiedEntry.getAttribute(modAttr.getAttributeDescription())) |
| | | { |
| | | for (ByteString val : attr) |
| | | { |
| | |
| | | logger.debug(INFO_ACI_ADD_FAILED_PRIVILEGE, entry.getName(), clientDN); |
| | | return false; |
| | | } |
| | | List<Attribute> attributeList = |
| | | entry.getOperationalAttribute(aciType, null); |
| | | List<Attribute> attributeList = entry.getOperationalAttribute(AttributeDescription.create(aciType)); |
| | | for (Attribute attribute : attributeList) |
| | | { |
| | | for (ByteString value : attribute) |
| | |
| | | if (!result.isEmpty()) { |
| | | ByteString val= ByteString.valueOfUtf8(attrVal); |
| | | SearchResultEntry resultEntry = result.getFirst(); |
| | | if(resultEntry.hasValue(attrType, null, val)) { |
| | | if(resultEntry.hasValue(attrType, val)) { |
| | | Entry e=evalCtx.getResourceEntry(); |
| | | if(e.hasValue(attrType, null, val)) |
| | | if(e.hasValue(attrType, val)) |
| | | { |
| | | matched=EnumEvalResult.TRUE; |
| | | } |
| | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizableMessageDescriptor.Arg2; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | |
| | | logMessages.add(messageString); |
| | | |
| | | final AttributeType type = DirectoryServer.getAttributeType(ATTR_TASK_LOG_MESSAGES); |
| | | final Attribute attr = taskEntry.getExactAttribute(type, Collections.<String> emptySet()); |
| | | final Attribute attr = taskEntry.getExactAttribute(AttributeDescription.create(type)); |
| | | final AttributeBuilder builder = attr != null ? new AttributeBuilder(attr) : new AttributeBuilder(type); |
| | | builder.add(messageString); |
| | | taskEntry.putAttribute(type, builder.toAttributeList()); |
| | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.api.ClientConnection; |
| | | import org.opends.server.protocols.ldap.LDAPAttribute; |
| | | import org.opends.server.protocols.ldap.LDAPResultCode; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.types.AbstractOperation; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeBuilder; |
| | | import org.opends.server.types.CancelResult; |
| | | import org.opends.server.types.CanceledOperationException; |
| | | import org.opends.server.types.Control; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.LDAPException; |
| | | import org.opends.server.types.ObjectClass; |
| | | import org.opends.server.types.Operation; |
| | | import org.opends.server.types.OperationType; |
| | | import org.opends.server.types.RawAttribute; |
| | | import org.opends.server.types.operation.PostResponseAddOperation; |
| | | import org.opends.server.types.operation.PreParseAddOperation; |
| | | import org.opends.server.workflowelement.localbackend.LocalBackendAddOperation; |
| | |
| | | boolean attributeSeen = false; |
| | | for (int i = 0; i < attrs.size(); i++) { |
| | | Attribute ea = attrs.get(i); |
| | | if (ea.optionsEqual(attr.getOptions())) |
| | | if (ea.getAttributeDescription().equals(attr.getAttributeDescription())) |
| | | { |
| | | AttributeBuilder builder = new AttributeBuilder(ea); |
| | | builder.addAll(attr); |
| | |
| | | if(e.hasAttribute(type)) |
| | | { |
| | | ByteString value = ByteString.valueOfUtf8(oldEntryDN.toString()); |
| | | if (e.hasValue(type, null, value)) |
| | | if (e.hasValue(type, value)) |
| | | { |
| | | mods.add(new Modification(ModificationType.DELETE, Attributes |
| | | .create(type, value))); |
| | |
| | | break; |
| | | } |
| | | |
| | | AttributeType attrType = mod.getAttribute().getAttributeType(); |
| | | Set<String> attrOptions = mod.getAttribute().getOptions(); |
| | | Attribute modifiedAttribute = entry.getExactAttribute(attrType, |
| | | attrOptions); |
| | | Attribute modifiedAttribute = entry.getExactAttribute(mod.getAttribute().getAttributeDescription()); |
| | | if (modifiedAttribute != null) |
| | | { |
| | | PluginResult.PreOperation result = |
| | |
| | | */ |
| | | package org.opends.server.plugins; |
| | | |
| | | import java.util.*; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.admin.server.ConfigurationChangeListener; |
| | | import org.opends.server.admin.std.meta.PluginCfgDefn; |
| | | import org.opends.server.admin.std.server.PluginCfg; |
| | |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.schema.SchemaConstants; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.types.operation.*; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.IndexType; |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.types.RDN; |
| | | import org.opends.server.types.SearchFilter; |
| | | import org.opends.server.types.SearchResultEntry; |
| | | import org.opends.server.types.operation.PluginOperation; |
| | | import org.opends.server.types.operation.PostOperationAddOperation; |
| | | import org.opends.server.types.operation.PostOperationModifyDNOperation; |
| | | import org.opends.server.types.operation.PostOperationModifyOperation; |
| | | import org.opends.server.types.operation.PostSynchronizationAddOperation; |
| | | import org.opends.server.types.operation.PostSynchronizationModifyDNOperation; |
| | | import org.opends.server.types.operation.PostSynchronizationModifyOperation; |
| | | import org.opends.server.types.operation.PreOperationAddOperation; |
| | | import org.opends.server.types.operation.PreOperationModifyDNOperation; |
| | | import org.opends.server.types.operation.PreOperationModifyOperation; |
| | | |
| | | import static org.opends.messages.PluginMessages.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | |
| | | { |
| | | for (DN baseDN : cfgBaseDNs) |
| | | { |
| | | Backend b = DirectoryServer.getBackend(baseDN); |
| | | Backend<?> b = DirectoryServer.getBackend(baseDN); |
| | | if (b != null && ! b.isIndexed(t, IndexType.EQUALITY)) |
| | | { |
| | | throw new ConfigException(ERR_PLUGIN_UNIQUEATTR_ATTR_UNINDEXED.get( |
| | |
| | | |
| | | case INCREMENT: |
| | | // We could calculate the new value, but we'll just take it from the updated entry. |
| | | for (Attribute updatedAttr : modifyOperation.getModifiedEntry().getAttribute(t, a.getOptions())) |
| | | Attribute updatedAttr = modifyOperation.getModifiedEntry().getExactAttribute(a.getAttributeDescription()); |
| | | if (updatedAttr != null) |
| | | { |
| | | if (! updatedAttr.optionsEqual(a.getOptions())) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | for (ByteString v : updatedAttr) |
| | | { |
| | | PreOperation stop = checkUniqueness(entryDN, t, v, baseDNs, recordedValues, config); |
| | |
| | | |
| | | case INCREMENT: |
| | | // We could calculate the new value, but we'll just take it from the updated entry. |
| | | for (Attribute updatedAttr : modifyOperation.getModifiedEntry().getAttribute(t, a.getOptions())) |
| | | Attribute updatedAttr = modifyOperation.getModifiedEntry().getExactAttribute(a.getAttributeDescription()); |
| | | if (updatedAttr != null) |
| | | { |
| | | if (! updatedAttr.optionsEqual(a.getOptions())) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | for (ByteString v : updatedAttr) |
| | | { |
| | | sendAlertForUnresolvedConflict(modifyOperation, entryDN, |
| | |
| | | { |
| | | for (DN baseDN : cfgBaseDNs) |
| | | { |
| | | Backend b = DirectoryServer.getBackend(baseDN); |
| | | Backend<?> b = DirectoryServer.getBackend(baseDN); |
| | | if (b != null && ! b.isIndexed(t, IndexType.EQUALITY)) |
| | | { |
| | | unacceptableReasons.add(ERR_PLUGIN_UNIQUEATTR_ATTR_UNINDEXED.get( |
| | |
| | | |
| | | case INCREMENT: |
| | | // We could calculate the new value, but we'll just take it from the updated entry. |
| | | for (Attribute updatedAttr : modifyOperation.getModifiedEntry().getAttribute(t, a.getOptions())) |
| | | Attribute updatedAttr = modifyOperation.getModifiedEntry().getExactAttribute(a.getAttributeDescription()); |
| | | if (updatedAttr != null) |
| | | { |
| | | if (!updatedAttr.optionsEqual(a.getOptions())) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | for (ByteString v : updatedAttr) |
| | | { |
| | | uniqueAttrValue2Dn.remove(v); |
| | |
| | | import java.util.Map; |
| | | |
| | | import org.forgerock.opendj.io.ASN1Writer; |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.core.DirectoryServer; |
| | |
| | | for (LDAPAttribute a : getAttributes()) |
| | | { |
| | | Attribute attr = a.toAttribute(); |
| | | AttributeType attrType = attr.getAttributeType(); |
| | | AttributeDescription attrDesc = attr.getAttributeDescription(); |
| | | AttributeType attrType = attrDesc.getAttributeType(); |
| | | |
| | | if (attrType.isObjectClass()) |
| | | { |
| | |
| | | boolean attributeSeen = false; |
| | | for (int i = 0; i < attrs.size(); i++) { |
| | | Attribute ea = attrs.get(i); |
| | | if (ea.optionsEqual(attr.getOptions())) |
| | | if (ea.getAttributeDescription().equals(attrDesc)) |
| | | { |
| | | AttributeBuilder builder = new AttributeBuilder(ea); |
| | | builder.addAll(attr); |
| | |
| | | * MOD to make sure the delete is going to succeed |
| | | */ |
| | | if (!deleteIt |
| | | || (!modifiedEntry.hasValue(modAttr.getAttributeType(), modAttr |
| | | .getOptions(), val) && ! addedInCurrentOp)) |
| | | || (!modifiedEntry.hasValue(modAttr.getAttributeDescription(), val) && ! addedInCurrentOp)) |
| | | { |
| | | // this value was already deleted before and therefore |
| | | // this should not be replayed. |
| | |
| | | modsIterator.remove(); |
| | | } |
| | | else if (newValue != null && |
| | | !modifiedEntry.hasValue(type, modAttr.getOptions(), newValue)) |
| | | !modifiedEntry.hasValue(modAttr.getAttributeDescription(), newValue)) |
| | | { |
| | | conflict = true; |
| | | modsIterator.remove(); |
| | |
| | | import org.opends.server.replication.protocol.OperationContext; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeBuilder; |
| | | import org.opends.server.types.AttributeDescriptions; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Entry; |
| | |
| | | |
| | | // Read from this entryHistorical, |
| | | // Create one empty if none was existing in this entryHistorical. |
| | | AttributeDescription attrDesc = AttributeDescriptions.create(modAttr); |
| | | AttributeDescription attrDesc = modAttr.getAttributeDescription(); |
| | | AttrHistorical attrHist = attributesHistorical.get(attrDesc); |
| | | if (attrHist == null) |
| | | { |
| | |
| | | import java.util.TreeMap; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler; |
| | | import org.opends.server.extensions.ConfigFileHandler; |
| | | import org.opends.server.loggers.JDKLogging; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeBuilder; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | |
| | | import org.opends.server.types.LDIFExportConfig; |
| | | import org.opends.server.types.LDIFImportConfig; |
| | | import org.opends.server.types.Modification; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.opends.server.types.NullOutputStream; |
| | | import org.opends.server.types.ObjectClass; |
| | | import org.opends.server.util.LDIFReader; |
| | |
| | | import com.forgerock.opendj.cli.CommonArguments; |
| | | import com.forgerock.opendj.cli.StringArgument; |
| | | |
| | | import static com.forgerock.opendj.cli.ArgumentConstants.*; |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.server.protocols.ldap.LDAPResultCode.*; |
| | | |
| | | import static com.forgerock.opendj.cli.ArgumentConstants.*; |
| | | |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | |
| | | /** |
| | | * This class provides a program that may be used to determine the differences |
| | | * between two LDIF files, generating the output in LDIF change format. There |
| | |
| | | while (attrIterator.hasNext()) |
| | | { |
| | | Attribute a = attrIterator.next(); |
| | | if (a.optionsEqual(sourceAttr.getOptions())) |
| | | if (a.getAttributeDescription().equals(sourceAttr.getAttributeDescription())) |
| | | { |
| | | targetAttr = a; |
| | | attrIterator.remove(); |
| | |
| | | |
| | | import java.util.Collection; |
| | | import java.util.Set; |
| | | import java.util.SortedSet; |
| | | import java.util.TreeSet; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.opendj.ldap.schema.MatchingRule; |
| | | |
| | | /** An abstract base class for implementing new types of {@link Attribute}. */ |
| | |
| | | } |
| | | |
| | | Attribute a = (Attribute) o; |
| | | return getAttributeType().equals(a.getAttributeType()) |
| | | && valuesEqual(a) |
| | | && optionsEqual(a.getOptions()); |
| | | return getAttributeDescription().equals(a.getAttributeDescription()) && valuesEqual(a); |
| | | } |
| | | |
| | | private boolean valuesEqual(Attribute a) |
| | |
| | | return getAttributeType().getNameOrOID(); |
| | | } |
| | | |
| | | @Override |
| | | public AttributeType getAttributeType() |
| | | { |
| | | return getAttributeDescription().getAttributeType(); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | * <p> |
| | |
| | | return buffer.toString(); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | * <p> |
| | | * This implementation returns {@code true} if the provided |
| | | * collection of options is {@code null} or empty. If the |
| | | * collection is non-empty and this attribute does not have any |
| | | * options then it returns {@code false}. Otherwise, {@code true} is |
| | | * returned if all the provided options are present. |
| | | */ |
| | | @Override |
| | | public boolean hasAllOptions(Collection<String> options) |
| | | { |
| | | // FIXME use AttributeDescription instead |
| | | return containsAllOptions(getOptions(), options); |
| | | } |
| | | |
| | | private static boolean containsAllOptions(Collection<String> options1, Collection<String> options2) |
| | | { |
| | | if (options1 == options2) |
| | | { |
| | | return true; |
| | | } |
| | | else if (isEmpty(options2)) |
| | | { |
| | | return true; |
| | | } |
| | | else if (isEmpty(options1)) |
| | | { |
| | | return false; |
| | | } |
| | | // normalize all options before calling containsAll() |
| | | Set<String> set1 = toLowercaseSet(options1); |
| | | Set<String> set2 = toLowercaseSet(options2); |
| | | return set1.size() >= set2.size() && set1.containsAll(set2); |
| | | } |
| | | |
| | | private static boolean isEmpty(Collection<String> col) |
| | | { |
| | | return col == null || col.isEmpty(); |
| | | } |
| | | |
| | | private static SortedSet<String> toLowercaseSet(Collection<String> strings) |
| | | { |
| | | final SortedSet<String> results = new TreeSet<>(); |
| | | for (String s : strings) |
| | | { |
| | | results.add(toLowerCase(s)); |
| | | } |
| | | return results; |
| | | } |
| | | |
| | | @Override |
| | | public int hashCode() |
| | | { |
| | |
| | | return !isVirtual(); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | * <p> |
| | | * This implementation returns !{@link #hasOptions()} if the |
| | | * provided set of options is <code>null</code>. Otherwise it |
| | | * checks that the size of the provided set of options is equal to |
| | | * the size of this attribute's options, return <code>false</code> |
| | | * if the sizes differ. If the sizes are the same then each option |
| | | * in the provided set is checked using |
| | | * {@link #hasOption(String)} and <code>true</code> is |
| | | * returned if all the provided options are present. |
| | | */ |
| | | @Override |
| | | public boolean optionsEqual(Set<String> options) |
| | | { |
| | | if (options != null) |
| | | { |
| | | return getOptions().size() == options.size() |
| | | && hasAllOptions(options); |
| | | } |
| | | return !hasOptions(); |
| | | } |
| | | |
| | | @Override |
| | | public final String toString() |
| | | { |
| | |
| | | */ |
| | | package org.opends.server.types; |
| | | |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | |
| | | /** |
| | | * This class defines a data structure for storing and interacting |
| | |
| | | AttributeType getAttributeType(); |
| | | |
| | | /** |
| | | * Retrieves the attribute description for this attribute. |
| | | * |
| | | * @return The attribute description for this attribute. |
| | | */ |
| | | AttributeDescription getAttributeDescription(); |
| | | |
| | | /** |
| | | * Retrieves the user-provided name for this attribute. |
| | | * |
| | | * @return The user-provided name for this attribute. |
| | |
| | | String getNameWithOptions(); |
| | | |
| | | /** |
| | | * Retrieves the unmodifiable set of attribute options for this |
| | | * attribute. The returned set of options are not normalized. |
| | | * Retrieves the unmodifiable set of attribute options for this attribute. The returned set of |
| | | * options are not normalized. |
| | | * |
| | | * @return The unmodifiable set of attribute options for this |
| | | * attribute. |
| | | * @return The unmodifiable set of attribute options for this attribute. |
| | | * @Deprecated use {@link #getAttributeDescription()} |
| | | */ |
| | | Set<String> getOptions(); |
| | | |
| | |
| | | ConditionResult greaterThanOrEqualTo(ByteString assertionValue); |
| | | |
| | | /** |
| | | * Indicates whether this attribute has all of the options in the provided collection. |
| | | * |
| | | * @param options |
| | | * The collection of options for which to make the determination (may be {@code null}). |
| | | * @return {@code true} if this attribute has all of the specified options, |
| | | * or {@code false} if it does not have at least one of them. |
| | | */ |
| | | boolean hasAllOptions(Collection<String> options); |
| | | |
| | | /** |
| | | * Retrieves the hash code for this attribute. It will be calculated |
| | | * as the sum of the hash code for the attribute type and all values. |
| | | * Retrieves the hash code for this attribute. It will be calculated as the sum of the hash code |
| | | * for the attribute type and all values. |
| | | * |
| | | * @return The hash code for this attribute. |
| | | */ |
| | |
| | | List<ByteString> subAny, ByteString subFinal); |
| | | |
| | | /** |
| | | * Indicates whether this attribute has exactly the specified set of |
| | | * options. |
| | | * |
| | | * @param options |
| | | * The set of options for which to make the determination |
| | | * (may be {@code null}). |
| | | * @return {@code true} if this attribute has exactly the |
| | | * specified set of options. |
| | | */ |
| | | boolean optionsEqual(Set<String> options); |
| | | |
| | | /** |
| | | * Returns the number of attribute values in this attribute. |
| | | * |
| | | * @return The number of attribute values in this attribute. |
| | |
| | | import java.util.AbstractSet; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.HashSet; |
| | | import java.util.Iterator; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | |
| | | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.Assertion; |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | |
| | | { |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | /** The attribute type for this attribute. */ |
| | | private final AttributeType attributeType; |
| | | /** The attribute description for this attribute. */ |
| | | private final AttributeDescription attributeDescription; |
| | | |
| | | /** The name of this attribute as provided by the end user. */ |
| | | private final String name; |
| | |
| | | * @param values |
| | | * The attribute values. |
| | | */ |
| | | private RealAttribute(AttributeType attributeType, String name, Set<AttributeValue> values) |
| | | private RealAttribute(AttributeDescription attributeDescription, String name, Set<AttributeValue> values) |
| | | { |
| | | this.attributeType = attributeType; |
| | | this.attributeDescription = attributeDescription; |
| | | this.name = name; |
| | | this.values = values; |
| | | } |
| | |
| | | @Override |
| | | public final ConditionResult approximatelyEqualTo(ByteString assertionValue) |
| | | { |
| | | MatchingRule matchingRule = attributeType.getApproximateMatchingRule(); |
| | | MatchingRule matchingRule = getAttributeType().getApproximateMatchingRule(); |
| | | if (matchingRule == null) |
| | | { |
| | | return ConditionResult.UNDEFINED; |
| | |
| | | @Override |
| | | public final boolean contains(ByteString value) |
| | | { |
| | | return values.contains(createAttributeValue(attributeType, value)); |
| | | return values.contains(createAttributeValue(getAttributeType(), value)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public final AttributeType getAttributeType() |
| | | public AttributeDescription getAttributeDescription() |
| | | { |
| | | return attributeType; |
| | | return attributeDescription; |
| | | } |
| | | |
| | | @Override |
| | | public Set<String> getOptions() |
| | | { |
| | | return Collections.unmodifiableSet(toSet(attributeDescription.getOptions())); |
| | | } |
| | | |
| | | @Override |
| | | public boolean hasOption(String option) |
| | | { |
| | | return attributeDescription.hasOption(option); |
| | | } |
| | | |
| | | private Set<String> toSet(Iterable<String> options) |
| | | { |
| | | Set<String> results = new HashSet<>(); |
| | | for (String option : options) |
| | | { |
| | | results.add(option); |
| | | } |
| | | return results; |
| | | } |
| | | |
| | | @Override |
| | | public boolean hasOptions() |
| | | { |
| | | return attributeDescription.hasOptions(); |
| | | } |
| | | |
| | | @Override |
| | | public final String getName() |
| | |
| | | return name; |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public final ConditionResult greaterThanOrEqualTo(ByteString assertionValue) |
| | | { |
| | | MatchingRule matchingRule = attributeType.getOrderingMatchingRule(); |
| | | MatchingRule matchingRule = getAttributeType().getOrderingMatchingRule(); |
| | | if (matchingRule == null) |
| | | { |
| | | return ConditionResult.UNDEFINED; |
| | |
| | | @Override |
| | | public final ConditionResult lessThanOrEqualTo(ByteString assertionValue) |
| | | { |
| | | MatchingRule matchingRule = attributeType.getOrderingMatchingRule(); |
| | | MatchingRule matchingRule = getAttributeType().getOrderingMatchingRule(); |
| | | if (matchingRule == null) |
| | | { |
| | | return ConditionResult.UNDEFINED; |
| | |
| | | @Override |
| | | public final ConditionResult matchesSubstring(ByteString subInitial, List<ByteString> subAny, ByteString subFinal) |
| | | { |
| | | MatchingRule matchingRule = attributeType.getSubstringMatchingRule(); |
| | | MatchingRule matchingRule = getAttributeType().getSubstringMatchingRule(); |
| | | if (matchingRule == null) |
| | | { |
| | | return ConditionResult.UNDEFINED; |
| | |
| | | private static final class RealAttributeManyOptions |
| | | extends RealAttribute |
| | | { |
| | | |
| | | /** The normalized options. */ |
| | | private final SortedSet<String> normalizedOptions; |
| | | |
| | | /** The options. */ |
| | | private final Set<String> options; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new real attribute that has multiple options. |
| | | * |
| | |
| | | AttributeType attributeType, String name, Set<AttributeValue> values, Set<String> options, |
| | | SortedSet<String> normalizedOptions) |
| | | { |
| | | super(attributeType, name, values); |
| | | this.options = options; |
| | | this.normalizedOptions = normalizedOptions; |
| | | } |
| | | |
| | | @Override |
| | | public Set<String> getOptions() |
| | | { |
| | | return options; |
| | | } |
| | | |
| | | @Override |
| | | public boolean hasOption(String option) |
| | | { |
| | | String s = toLowerCase(option); |
| | | return normalizedOptions.contains(s); |
| | | } |
| | | |
| | | @Override |
| | | public boolean hasOptions() |
| | | { |
| | | return true; |
| | | super(AttributeDescription.create(attributeType, options), name, values); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | private RealAttributeNoOptions(AttributeType attributeType, String name, Set<AttributeValue> values) |
| | | { |
| | | super(attributeType, name, values); |
| | | super(AttributeDescription.create(attributeType), name, values); |
| | | } |
| | | |
| | | @Override |
| | |
| | | { |
| | | return Collections.emptySet(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean hasAllOptions(Collection<String> options) |
| | | { |
| | | return options == null || options.isEmpty(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean hasOption(String option) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public boolean hasOptions() |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public boolean optionsEqual(Set<String> options) |
| | | { |
| | | return options == null || options.isEmpty(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | private static final class RealAttributeSingleOption |
| | | extends RealAttribute |
| | | { |
| | | /** The normalized single option. */ |
| | | private final String normalizedOption; |
| | | |
| | | /** A singleton set containing the single option. */ |
| | | private final Set<String> option; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new real attribute that has a single option. |
| | | * |
| | |
| | | Set<AttributeValue> values, |
| | | String option) |
| | | { |
| | | super(attributeType, name, values); |
| | | this.option = Collections.singleton(option); |
| | | this.normalizedOption = toLowerCase(option); |
| | | } |
| | | |
| | | @Override |
| | | public Set<String> getOptions() |
| | | { |
| | | return option; |
| | | } |
| | | |
| | | @Override |
| | | public boolean hasOption(String option) |
| | | { |
| | | String s = toLowerCase(option); |
| | | return normalizedOption.equals(s); |
| | | } |
| | | |
| | | @Override |
| | | public boolean hasOptions() |
| | | { |
| | | return true; |
| | | super(AttributeDescription.create(attributeType, option), name, values); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | package org.opends.server.types; |
| | | |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | |
| | | /** |
| | | * This class defines a collective virtual attribute, which is a |
| | |
| | | return attribute.contains(value); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public ConditionResult matchesEqualityAssertion(ByteString assertionValue) |
| | | { |
| | | return attribute.matchesEqualityAssertion(assertionValue); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public AttributeDescription getAttributeDescription() |
| | | { |
| | | return attribute.getAttributeDescription(); |
| | | } |
| | | |
| | | @Override |
| | | public AttributeType getAttributeType() { |
| | | return attribute.getAttributeType(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Set<String> getOptions() { |
| | | return attribute.getOptions(); |
| | |
| | | |
| | | import java.io.BufferedWriter; |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.Iterator; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteSequenceReader; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | |
| | | */ |
| | | public boolean hasAttribute(AttributeType attributeType) |
| | | { |
| | | return hasAttribute(attributeType, null, true); |
| | | return hasAttribute(AttributeDescription.create(attributeType), true); |
| | | } |
| | | |
| | | |
| | |
| | | public boolean hasAttribute(AttributeType attributeType, |
| | | boolean includeSubordinates) |
| | | { |
| | | return hasAttribute(attributeType, null, includeSubordinates); |
| | | return hasAttribute(AttributeDescription.create(attributeType), includeSubordinates); |
| | | } |
| | | |
| | | |
| | |
| | | * attribute of the specified attribute will also be used in the |
| | | * determination. |
| | | * |
| | | * @param attributeType |
| | | * The attribute type for which to make the determination. |
| | | * @param options |
| | | * The set of options to use in the determination. |
| | | * @param attributeDescription |
| | | * The attribute description for which to make the determination. |
| | | * @return <CODE>true</CODE> if this entry contains the specified |
| | | * attribute, or <CODE>false</CODE> if not. |
| | | */ |
| | | public boolean hasAttribute(AttributeType attributeType, Set<String> options) |
| | | public boolean hasAttribute(AttributeDescription attributeDescription) |
| | | { |
| | | return hasAttribute(attributeType, options, true); |
| | | return hasAttribute(attributeDescription, true); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether this entry contains the specified attribute |
| | | * with all of the options in the provided set. |
| | | * Indicates whether this entry contains the specified attribute with all of the options in the |
| | | * provided set. |
| | | * |
| | | * @param attributeType |
| | | * The attribute type for which to make the determination. |
| | | * @param options |
| | | * The set of options to use in the determination. |
| | | * @param attributeDescription |
| | | * The attribute description for which to make the determination. |
| | | * @param includeSubordinates |
| | | * Whether to include any subordinate attributes of the |
| | | * attribute type being retrieved. |
| | | * @return <CODE>true</CODE> if this entry contains the specified |
| | | * attribute, or <CODE>false</CODE> if not. |
| | | * Whether to include any subordinate attributes of the attribute type being retrieved. |
| | | * @return <CODE>true</CODE> if this entry contains the specified attribute, or <CODE>false</CODE> |
| | | * if not. |
| | | */ |
| | | public boolean hasAttribute( |
| | | AttributeType attributeType, |
| | | Set<String> options, |
| | | boolean includeSubordinates) |
| | | public boolean hasAttribute(AttributeDescription attributeDescription, boolean includeSubordinates) |
| | | { |
| | | AttributeType attributeType = attributeDescription.getAttributeType(); |
| | | |
| | | // Handle object class. |
| | | if (attributeType.isObjectClass()) |
| | | { |
| | | return !objectClasses.isEmpty() && (options == null || options.isEmpty()); |
| | | return !objectClasses.isEmpty() && !attributeDescription.hasOptions(); |
| | | } |
| | | |
| | | if (!includeSubordinates) |
| | | { |
| | | // It's possible that there could be an attribute without any |
| | | // values, which we should treat as not having the requested attribute. |
| | | Attribute attribute = getExactAttribute(attributeType, options); |
| | | Attribute attribute = getExactAttribute(attributeDescription); |
| | | return attribute != null && !attribute.isEmpty(); |
| | | } |
| | | |
| | |
| | | { |
| | | // It's possible that there could be an attribute without any |
| | | // values, which we should treat as not having the requested attribute. |
| | | if (!attribute.isEmpty() && attribute.hasAllOptions(options)) |
| | | if (!attribute.isEmpty() && attribute.getAttributeDescription().isSubTypeOf(attributeDescription)) |
| | | { |
| | | return true; |
| | | } |
| | |
| | | { |
| | | // It's possible that there could be an attribute without any values, |
| | | // which we should treat as not having the requested attribute. |
| | | if (!attribute.isEmpty() && attribute.hasAllOptions(options)) |
| | | if (!attribute.isEmpty() && attribute.getAttributeDescription().isSubTypeOf(attributeDescription)) |
| | | { |
| | | return true; |
| | | } |
| | |
| | | * attribute type is not present in this entry with the |
| | | * provided set of options. |
| | | */ |
| | | public List<Attribute> getAttribute(AttributeType attributeType, |
| | | Set<String> options) |
| | | @Deprecated |
| | | public List<Attribute> getAttribute(AttributeType attributeType, Set<String> options) |
| | | { |
| | | return getAttribute(AttributeDescription.create(attributeType, options)); |
| | | } |
| | | |
| | | /** |
| | | * Retrieves the requested attribute element(s) for the specified |
| | | * attribute description. The list returned may include multiple elements |
| | | * if the same attribute exists in the entry multiple times with |
| | | * different sets of options. It may also include any subordinate |
| | | * attributes of the attribute being retrieved. |
| | | * |
| | | * @param attributeDescription The attribute description to retrieve. |
| | | * @return The requested attribute element(s) for the specified |
| | | * attribute type, or an empty list if the specified |
| | | * attribute type is not present in this entry with the |
| | | * provided set of options. |
| | | */ |
| | | public List<Attribute> getAttribute(AttributeDescription attributeDescription) |
| | | { |
| | | AttributeType attributeType = attributeDescription.getAttributeType(); |
| | | List<Attribute> attributes = new LinkedList<>(); |
| | | if (!attributeType.isObjectClass()) |
| | | { |
| | |
| | | { |
| | | if (attributeType.isObjectClass() |
| | | && !objectClasses.isEmpty() |
| | | && (options == null || options.isEmpty())) |
| | | && !attributeDescription.hasOptions()) |
| | | { |
| | | attributes.add(getObjectClassAttribute()); |
| | | return attributes; |
| | |
| | | attributes.addAll(attrs); |
| | | } |
| | | |
| | | onlyKeepAttributesWithAllOptions(attributes, options); |
| | | onlyKeepAttributesWithAllOptions(attributes, attributeDescription); |
| | | |
| | | return attributes; |
| | | } |
| | |
| | | * the attributes Map where to find the attributes |
| | | * @return the filtered List of attributes |
| | | */ |
| | | private List<Attribute> getAttribute(AttributeType attributeType, |
| | | Set<String> options, Map<AttributeType, List<Attribute>> attrs) |
| | | private List<Attribute> getAttribute(AttributeDescription attributeDescription, |
| | | Map<AttributeType, List<Attribute>> attrs) |
| | | { |
| | | AttributeType attributeType = attributeDescription.getAttributeType(); |
| | | List<Attribute> attributes = new LinkedList<>(); |
| | | addAllIfNotNull(attributes, attrs.get(attributeType)); |
| | | |
| | |
| | | addAllIfNotNull(attributes, attrs.get(at)); |
| | | } |
| | | |
| | | onlyKeepAttributesWithAllOptions(attributes, options); |
| | | onlyKeepAttributesWithAllOptions(attributes, attributeDescription); |
| | | return attributes; |
| | | } |
| | | |
| | |
| | | * |
| | | * @param attributes |
| | | * the attributes to filter. |
| | | * @param options |
| | | * the options to look for |
| | | * @param attributeDescription |
| | | * contains the options to look for |
| | | */ |
| | | private void onlyKeepAttributesWithAllOptions(List<Attribute> attributes, |
| | | Set<String> options) |
| | | private void onlyKeepAttributesWithAllOptions(List<Attribute> attributes, AttributeDescription attributeDescription) |
| | | { |
| | | Iterator<Attribute> iterator = attributes.iterator(); |
| | | while (iterator.hasNext()) |
| | | { |
| | | Attribute a = iterator.next(); |
| | | if (!a.hasAllOptions(options)) |
| | | if (!a.getAttributeDescription().isSubTypeOf(attributeDescription)) |
| | | { |
| | | iterator.remove(); |
| | | } |
| | |
| | | * elements if the same attribute exists in the entry multiple times |
| | | * with different sets of options. |
| | | * |
| | | * @param attributeType The attribute type to retrieve. |
| | | * @param options The set of attribute options to include in |
| | | * matching elements. |
| | | * @param attributeDescription The attribute description to retrieve. |
| | | * |
| | | * @return The requested attribute element(s) for the specified |
| | | * attribute type, or an empty list if there is no such |
| | | * operational attribute with the specified set of options. |
| | | */ |
| | | public List<Attribute> getOperationalAttribute( |
| | | AttributeType attributeType, |
| | | Set<String> options) |
| | | public List<Attribute> getOperationalAttribute(AttributeDescription attributeDescription) |
| | | { |
| | | return getAttribute(attributeType, options, operationalAttributes); |
| | | return getAttribute(attributeDescription, operationalAttributes); |
| | | } |
| | | |
| | | |
| | |
| | | * parsed as an integer of if the existing attribute |
| | | * values could not be parsed as integers. |
| | | */ |
| | | public void incrementAttribute( |
| | | Attribute attribute) throws DirectoryException |
| | | public void incrementAttribute(Attribute attribute) throws DirectoryException |
| | | { |
| | | // Get the attribute that is to be incremented. |
| | | AttributeType attributeType = attribute.getAttributeType(); |
| | | Attribute a = getExactAttribute(attributeType, attribute.getOptions()); |
| | | Attribute a = getExactAttribute(attribute.getAttributeDescription()); |
| | | if (a == null) |
| | | { |
| | | LocalizableMessage message = ERR_ENTRY_INCREMENT_NO_SUCH_ATTRIBUTE.get( |
| | |
| | | { |
| | | attachment = null; |
| | | |
| | | if (attribute.getAttributeType().isObjectClass()) |
| | | AttributeDescription attrDesc = attribute.getAttributeDescription(); |
| | | AttributeType attrType = attrDesc.getAttributeType(); |
| | | if (attrType.isObjectClass()) |
| | | { |
| | | if (attribute.isEmpty()) |
| | | { |
| | |
| | | |
| | | boolean allSuccessful = true; |
| | | |
| | | MatchingRule rule = |
| | | attribute.getAttributeType().getEqualityMatchingRule(); |
| | | MatchingRule rule = attrType.getEqualityMatchingRule(); |
| | | for (ByteString v : attribute) |
| | | { |
| | | String ocName = toLowerName(rule, v); |
| | |
| | | return allSuccessful; |
| | | } |
| | | |
| | | AttributeType attributeType = attribute.getAttributeType(); |
| | | List<Attribute> attributes = getAttributes(attributeType); |
| | | List<Attribute> attributes = getAttributes(attrType); |
| | | if (attributes == null) |
| | | { |
| | | // There are no attributes with the same attribute type. |
| | |
| | | } |
| | | |
| | | // There are already attributes with the same attribute type. |
| | | Set<String> options = attribute.getOptions(); |
| | | for (int i = 0; i < attributes.size(); i++) |
| | | { |
| | | Attribute a = attributes.get(i); |
| | | if (a.optionsEqual(options)) |
| | | if (a.getAttributeDescription().equals(attrDesc)) |
| | | { |
| | | if (attribute.isEmpty()) |
| | | { |
| | |
| | | // If the attribute list is now empty remove it. |
| | | if (attributes.isEmpty()) |
| | | { |
| | | removeAttributes(attributeType); |
| | | removeAttributes(attrType); |
| | | } |
| | | |
| | | return true; |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Indicates whether this entry contains the specified attribute value. |
| | | * |
| | | * @param attributeDescription |
| | | * The attribute description for the attribute. |
| | | * @param value |
| | | * The value for the attribute. |
| | | * @return {@code true} if this entry contains the specified attribute value, {@code false} |
| | | * otherwise. |
| | | */ |
| | | public boolean hasValue(AttributeDescription attributeDescription, ByteString value) |
| | | { |
| | | Attribute attr = getExactAttribute(attributeDescription); |
| | | return attr != null && attr.contains(value); |
| | | } |
| | | |
| | | /** |
| | | * Indicates whether this entry contains the specified attribute |
| | | * value. |
| | | * Indicates whether this entry contains the specified attribute value. |
| | | * |
| | | * @param attributeType The attribute type for the attribute. |
| | | * @param options The set of options for the attribute. |
| | | * @param value The value for the attribute. |
| | | * |
| | | * @return <CODE>true</CODE> if this entry contains the specified |
| | | * attribute value, or <CODE>false</CODE> if it does not. |
| | | * @param attributeType |
| | | * The attribute type for the attribute. |
| | | * @param value |
| | | * The value for the attribute. |
| | | * @return {@code true} if this entry contains the specified attribute value, {@code false} |
| | | * otherwise. |
| | | */ |
| | | public boolean hasValue(AttributeType attributeType, Set<String> options, ByteString value) |
| | | public boolean hasValue(AttributeType attributeType, ByteString value) |
| | | { |
| | | for (Attribute a : getAttribute(attributeType)) |
| | | { |
| | | if (a.optionsEqual(options) && a.contains(value)) |
| | | if (!a.hasOptions() && a.contains(value)) |
| | | { |
| | | return true; |
| | | } |
| | |
| | | for (int i = 0; i < targetList.size(); i++) |
| | | { |
| | | Attribute otherAttribute = targetList.get(i); |
| | | if (otherAttribute.optionsEqual(a.getOptions())) |
| | | if (otherAttribute.getAttributeDescription().equals(a.getAttributeDescription())) |
| | | { |
| | | targetList.set(i, Attributes.merge(a, otherAttribute)); |
| | | found = true; |
| | |
| | | { |
| | | if (inheritFromEntry != null) |
| | | { |
| | | collectiveAttr = inheritFromEntry.getExactAttribute( |
| | | collectiveAttr.getAttributeType(), |
| | | collectiveAttr.getOptions()); |
| | | collectiveAttr = inheritFromEntry.getExactAttribute(collectiveAttr.getAttributeDescription()); |
| | | if (collectiveAttr == null || collectiveAttr.isEmpty()) |
| | | { |
| | | continue; |
| | |
| | | * does not contain an attribute with the specified attribute type |
| | | * and options. |
| | | * |
| | | * @param attributeType |
| | | * The attribute type to retrieve. |
| | | * @param options |
| | | * The set of attribute options. |
| | | * @param attributeDescription |
| | | * The attribute description to retrieve. |
| | | * @return The requested attribute element for the specified |
| | | * attribute type and options, or <code>null</code> if the |
| | | * specified attribute type is not present in this entry |
| | | * with the provided set of options. |
| | | */ |
| | | public Attribute getExactAttribute(AttributeType attributeType, |
| | | Set<String> options) |
| | | public Attribute getExactAttribute(AttributeDescription attributeDescription) |
| | | { |
| | | List<Attribute> attributes = getAttributes(attributeType); |
| | | List<Attribute> attributes = getAttributes(attributeDescription.getAttributeType()); |
| | | if (attributes != null) |
| | | { |
| | | for (Attribute attribute : attributes) |
| | | { |
| | | if (attribute.optionsEqual(options)) |
| | | if (attribute.getAttributeDescription().equals(attributeDescription)) |
| | | { |
| | | return attribute; |
| | | } |
| | |
| | | { |
| | | attachment = null; |
| | | |
| | | AttributeType attributeType = attribute.getAttributeType(); |
| | | |
| | | if (attribute.getAttributeType().isObjectClass()) |
| | | AttributeDescription attrDesc = attribute.getAttributeDescription(); |
| | | AttributeType attrType = attrDesc.getAttributeType(); |
| | | if (attrType.isObjectClass()) |
| | | { |
| | | // We will not do any validation of the object classes - this is |
| | | // left to the caller. |
| | |
| | | objectClasses.clear(); |
| | | } |
| | | |
| | | MatchingRule rule = |
| | | attribute.getAttributeType().getEqualityMatchingRule(); |
| | | MatchingRule rule = attrType.getEqualityMatchingRule(); |
| | | for (ByteString v : attribute) |
| | | { |
| | | String name = v.toString(); |
| | | String lowerName = toLowerName(rule, v); |
| | | |
| | | // Create a default object class if necessary. |
| | | ObjectClass oc = |
| | | DirectoryServer.getObjectClass(lowerName, true); |
| | | ObjectClass oc = DirectoryServer.getObjectClass(lowerName, true); |
| | | |
| | | if (replace) |
| | | { |
| | |
| | | return; |
| | | } |
| | | |
| | | List<Attribute> attributes = getAttributes(attributeType); |
| | | List<Attribute> attributes = getAttributes(attrType); |
| | | if (attributes == null) |
| | | { |
| | | // Do nothing if we are deleting a non-existing attribute. |
| | |
| | | } |
| | | |
| | | // We are adding the first attribute with this attribute type. |
| | | putAttributes(attributeType, newArrayList(attribute)); |
| | | putAttributes(attrType, newArrayList(attribute)); |
| | | return; |
| | | } |
| | | |
| | | // There are already attributes with the same attribute type. |
| | | Set<String> options = attribute.getOptions(); |
| | | for (int i = 0; i < attributes.size(); i++) |
| | | { |
| | | Attribute a = attributes.get(i); |
| | | if (a.optionsEqual(options)) |
| | | if (a.getAttributeDescription().equals(attrDesc)) |
| | | { |
| | | if (replace) |
| | | { |
| | |
| | | |
| | | if (attributes.isEmpty()) |
| | | { |
| | | removeAttributes(attributeType); |
| | | removeAttributes(attrType); |
| | | } |
| | | } |
| | | } |
| | |
| | | AttributeType attrType, String attrName, Set<String> options, |
| | | boolean omitValues, boolean omitReal, boolean omitVirtual) |
| | | { |
| | | AttributeDescription attrDesc = AttributeDescription.create(attrType, options); |
| | | mergeAttributeLists(sourceList, destMap, attrDesc, attrName, omitValues, omitReal, omitVirtual); |
| | | } |
| | | |
| | | private void mergeAttributeLists(List<Attribute> sourceList, |
| | | Map<AttributeType, List<Attribute>> destMap, |
| | | AttributeDescription attrDesc, String attrName, |
| | | boolean omitValues, boolean omitReal, boolean omitVirtual) |
| | | { |
| | | if (sourceList == null) |
| | | { |
| | | return; |
| | |
| | | if (attribute.isEmpty() |
| | | || (omitReal && attribute.isReal()) |
| | | || (omitVirtual && attribute.isVirtual()) |
| | | || !attribute.hasAllOptions(options)) |
| | | || !attribute.getAttributeDescription().isSubTypeOf(attrDesc)) |
| | | { |
| | | continue; |
| | | } |
| | |
| | | // If a non-default attribute name was provided or if the |
| | | // attribute has options then we will need to rebuild the |
| | | // attribute so that it contains the user-requested names and options. |
| | | AttributeType subAttrType = attribute.getAttributeType(); |
| | | AttributeDescription subAttrDesc = attribute.getAttributeDescription(); |
| | | AttributeType subAttrType = subAttrDesc.getAttributeType(); |
| | | |
| | | if ((attrName != null && !attrName.equals(attribute.getName())) |
| | | || (options != null && !options.isEmpty())) |
| | | || attrDesc.hasOptions()) |
| | | { |
| | | AttributeBuilder builder = new AttributeBuilder(); |
| | | |
| | |
| | | // the same type as the requested type. This might not be the case for |
| | | // sub-types e.g. requesting "name" and getting back "cn" - we don't |
| | | // want to rename "name" to "cn". |
| | | if (attrName == null || !subAttrType.equals(attrType)) |
| | | if (attrName == null || !subAttrType.equals(attrDesc.getAttributeType())) |
| | | { |
| | | builder.setAttributeType(subAttrType, attribute.getName()); |
| | | } |
| | |
| | | builder.setAttributeType(subAttrType, attrName); |
| | | } |
| | | |
| | | if (options != null) |
| | | { |
| | | builder.setOptions(options); |
| | | } |
| | | builder.setOptions(attrDesc.getOptions()); |
| | | |
| | | // Now add in remaining options from original attribute |
| | | // (this will not overwrite options already present). |
| | |
| | | for (int i = 0; i < attrList.size(); i++) |
| | | { |
| | | Attribute otherAttribute = attrList.get(i); |
| | | if (otherAttribute.optionsEqual(attribute.getOptions())) |
| | | if (otherAttribute.getAttributeDescription().equals(subAttrDesc)) |
| | | { |
| | | // Assume that wildcards appear first in an attribute |
| | | // list with more specific attribute names afterwards: |
| | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.Assertion; |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | |
| | | |
| | | private static SearchFilter objectClassPresent; |
| | | |
| | | /** The attribute description for this filter. */ |
| | | private final AttributeDescription attributeDescription; |
| | | /** The attribute type for this filter. */ |
| | | private final AttributeType attributeType; |
| | | |
| | |
| | | /** The not filter component for this search filter. */ |
| | | private final SearchFilter notComponent; |
| | | |
| | | /** The set of options for the attribute type in this filter. */ |
| | | private final Set<String> attributeOptions; |
| | | |
| | | /** The matching rule ID for this search filter. */ |
| | | private final String matchingRuleID; |
| | | |
| | |
| | | this.filterType = filterType; |
| | | this.filterComponents = new LinkedHashSet<>(filterComponents); |
| | | this.notComponent = notComponent; |
| | | this.attributeDescription = attributeType != null |
| | | ? AttributeDescription.create(attributeType, attributeOptions) |
| | | : null; |
| | | this.attributeType = attributeType; |
| | | this.attributeOptions = attributeOptions; |
| | | this.assertionValue = assertionValue; |
| | | this.subInitialElement = subInitialElement; |
| | | this.subAnyElements = subAnyElements; |
| | |
| | | } |
| | | |
| | | // See if the entry has an attribute with the requested type. |
| | | List<Attribute> attrs = entry.getAttribute(attributeType, attributeOptions); |
| | | List<Attribute> attrs = entry.getAttribute(attributeDescription); |
| | | if (attrs.isEmpty()) |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | |
| | | } |
| | | |
| | | // See if the entry has an attribute with the requested type. |
| | | List<Attribute> attrs = entry.getAttribute(attributeType, attributeOptions); |
| | | List<Attribute> attrs = entry.getAttribute(attributeDescription); |
| | | if (attrs.isEmpty()) |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | |
| | | } |
| | | |
| | | // See if the entry has an attribute with the requested type. |
| | | List<Attribute> attrs = entry.getAttribute(attributeType, attributeOptions); |
| | | List<Attribute> attrs = entry.getAttribute(attributeDescription); |
| | | if (attrs.isEmpty()) |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | |
| | | } |
| | | |
| | | // See if the entry has an attribute with the requested type. |
| | | List<Attribute> attrs = entry.getAttribute(attributeType, attributeOptions); |
| | | List<Attribute> attrs = entry.getAttribute(attributeDescription); |
| | | if (attrs.isEmpty()) |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | |
| | | |
| | | // See if the entry has an attribute with the requested type. |
| | | // If so, then it's a match. If not, then it's not a match. |
| | | ConditionResult result = ConditionResult.valueOf( |
| | | entry.hasAttribute(attributeType, attributeOptions)); |
| | | ConditionResult result = ConditionResult.valueOf(entry.hasAttribute(attributeDescription)); |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | logger.trace( |
| | |
| | | } |
| | | |
| | | // See if the entry has an attribute with the requested type. |
| | | List<Attribute> attrs = entry.getAttribute(attributeType, attributeOptions); |
| | | List<Attribute> attrs = entry.getAttribute(attributeDescription); |
| | | if (attrs.isEmpty()) |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | |
| | | } |
| | | else |
| | | { |
| | | for (Attribute a : entry.getAttribute(attributeType, attributeOptions)) |
| | | for (Attribute a : entry.getAttribute(attributeDescription)) |
| | | { |
| | | for (ByteString v : a) |
| | | { |
| | |
| | | return andOrEqual(f); |
| | | case NOT: |
| | | return notComponent.equals(f.notComponent); |
| | | case EQUALITY: |
| | | return typeAndOptionsAndAssertionEqual(f); |
| | | case SUBSTRING: |
| | | return substringEqual(f); |
| | | case GREATER_OR_EQUAL: |
| | | return typeAndOptionsAndAssertionEqual(f); |
| | | case LESS_OR_EQUAL: |
| | | return typeAndOptionsAndAssertionEqual(f); |
| | | case PRESENT: |
| | | return attributeType.equals(f.attributeType) && |
| | | optionsEqual(attributeOptions, f.attributeOptions); |
| | | case APPROXIMATE_MATCH: |
| | | return typeAndOptionsAndAssertionEqual(f); |
| | | return attributeDescription.equals(f.attributeDescription); |
| | | case EXTENSIBLE_MATCH: |
| | | return extensibleEqual(f); |
| | | case EQUALITY: |
| | | case APPROXIMATE_MATCH: |
| | | case GREATER_OR_EQUAL: |
| | | case LESS_OR_EQUAL: |
| | | return attributeDescription.equals(f.attributeDescription) |
| | | && assertionValue.equals(f.assertionValue); |
| | | default: |
| | | return false; |
| | | } |
| | |
| | | return true; |
| | | } |
| | | |
| | | |
| | | private boolean typeAndOptionsAndAssertionEqual(SearchFilter f) |
| | | { |
| | | return attributeType.equals(f.attributeType) |
| | | && optionsEqual(attributeOptions, f.attributeOptions) |
| | | && assertionValue.equals(f.assertionValue); |
| | | } |
| | | |
| | | |
| | | private boolean substringEqual(SearchFilter other) |
| | | { |
| | | if (! attributeType.equals(other.attributeType)) |
| | | if (!attributeDescription.equals(other.attributeDescription)) |
| | | { |
| | | return false; |
| | | } |
| | |
| | | { |
| | | return false; |
| | | } |
| | | if (! optionsEqual(attributeOptions, other.attributeOptions)) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | boolean initialCheck = subInitialElement == null ? |
| | | other.subInitialElement == null : subInitialElement.equals(other.subInitialElement); |
| | |
| | | return false; |
| | | } |
| | | } |
| | | else |
| | | else if (!attributeDescription.equals(f.attributeDescription)) |
| | | { |
| | | if (! attributeType.equals(f.attributeType)) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | if (! optionsEqual(attributeOptions, f.attributeOptions)) |
| | | { |
| | | return false; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | if (dnAttributes != f.dnAttributes) |
| | |
| | | return true; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the two provided sets of attribute options |
| | | * should be considered equal. |
| | | * |
| | | * @param options1 The first set of attribute options for which to |
| | | * make the determination. |
| | | * @param options2 The second set of attribute options for which |
| | | * to make the determination. |
| | | * |
| | | * @return {@code true} if the sets of attribute options are equal, |
| | | * or {@code false} if not. |
| | | */ |
| | | private static boolean optionsEqual(Set<String> options1, |
| | | Set<String> options2) |
| | | { |
| | | if (options1 == null || options1.isEmpty()) |
| | | { |
| | | return options2 == null || options2.isEmpty(); |
| | | } |
| | | else if (options2 == null || options2.isEmpty()) |
| | | { |
| | | return false; |
| | | } |
| | | else |
| | | { |
| | | if (options1.size() != options2.size()) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | HashSet<String> lowerOptions = new HashSet<>(options1.size()); |
| | | for (String option : options1) |
| | | { |
| | | lowerOptions.add(toLowerCase(option)); |
| | | } |
| | | |
| | | for (String option : options2) |
| | | { |
| | | if (! lowerOptions.remove(toLowerCase(option))) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | return lowerOptions.isEmpty(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Retrieves the hash code for this search filter. |
| | | * |
| | |
| | | buffer.append(")"); |
| | | break; |
| | | case EQUALITY: |
| | | buffer.append("("); |
| | | buffer.append(attributeType.getNameOrOID()); |
| | | appendOptions(buffer); |
| | | buffer.append("="); |
| | | valueToFilterString(buffer, assertionValue); |
| | | buffer.append(")"); |
| | | appendEquation(buffer, "="); |
| | | break; |
| | | case SUBSTRING: |
| | | buffer.append("("); |
| | | buffer.append(attributeType.getNameOrOID()); |
| | | appendOptions(buffer); |
| | | buffer.append(attributeDescription); |
| | | buffer.append("="); |
| | | |
| | | if (subInitialElement != null) |
| | |
| | | buffer.append(")"); |
| | | break; |
| | | case GREATER_OR_EQUAL: |
| | | buffer.append("("); |
| | | buffer.append(attributeType.getNameOrOID()); |
| | | appendOptions(buffer); |
| | | buffer.append(">="); |
| | | valueToFilterString(buffer, assertionValue); |
| | | buffer.append(")"); |
| | | appendEquation(buffer, ">="); |
| | | break; |
| | | case LESS_OR_EQUAL: |
| | | buffer.append("("); |
| | | buffer.append(attributeType.getNameOrOID()); |
| | | appendOptions(buffer); |
| | | buffer.append("<="); |
| | | valueToFilterString(buffer, assertionValue); |
| | | buffer.append(")"); |
| | | appendEquation(buffer, "<="); |
| | | break; |
| | | case PRESENT: |
| | | buffer.append("("); |
| | | buffer.append(attributeType.getNameOrOID()); |
| | | appendOptions(buffer); |
| | | buffer.append(attributeDescription); |
| | | buffer.append("=*)"); |
| | | break; |
| | | case APPROXIMATE_MATCH: |
| | | buffer.append("("); |
| | | buffer.append(attributeType.getNameOrOID()); |
| | | appendOptions(buffer); |
| | | buffer.append("~="); |
| | | valueToFilterString(buffer, assertionValue); |
| | | buffer.append(")"); |
| | | appendEquation(buffer, "~="); |
| | | break; |
| | | case EXTENSIBLE_MATCH: |
| | | buffer.append("("); |
| | | |
| | | if (attributeType != null) |
| | | if (attributeDescription != null) |
| | | { |
| | | buffer.append(attributeType.getNameOrOID()); |
| | | appendOptions(buffer); |
| | | buffer.append(attributeDescription); |
| | | } |
| | | |
| | | if (dnAttributes) |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | private void appendOptions(StringBuilder buffer) |
| | | private void appendEquation(StringBuilder buffer, String operator) |
| | | { |
| | | if (attributeOptions != null && !attributeOptions.isEmpty()) |
| | | { |
| | | for (String option : attributeOptions) |
| | | { |
| | | buffer.append(";"); |
| | | buffer.append(option); |
| | | } |
| | | } |
| | | buffer.append("("); |
| | | buffer.append(attributeDescription); |
| | | buffer.append(operator); |
| | | valueToFilterString(buffer, assertionValue); |
| | | buffer.append(")"); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Appends a properly-cleaned version of the provided value to the |
| | | * given buffer so that it can be safely used in string |
| | |
| | | */ |
| | | package org.opends.server.types; |
| | | |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.util.Utils; |
| | | import org.opends.server.api.VirtualAttributeProvider; |
| | | |
| | |
| | | public final class VirtualAttribute |
| | | extends AbstractAttribute |
| | | { |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | /** The attribute type. */ |
| | | private final AttributeType attributeType; |
| | | /** The attribute description. */ |
| | | private final AttributeDescription attributeDescription; |
| | | /** The entry with which this virtual attribute is associated. */ |
| | | private final Entry entry; |
| | | /** The virtual attribute provider for this virtual attribute. */ |
| | |
| | | public VirtualAttribute(AttributeType attributeType, Entry entry, |
| | | VirtualAttributeRule rule) |
| | | { |
| | | this.attributeType = attributeType; |
| | | this.attributeDescription = AttributeDescription.create(attributeType); |
| | | this.entry = entry; |
| | | this.rule = rule; |
| | | this.provider = rule.getProvider(); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public AttributeType getAttributeType() |
| | | { |
| | | return attributeType; |
| | | } |
| | | |
| | | @Override |
| | | public String getNameWithOptions() |
| | | { |
| | | return getName(); |
| | | } |
| | | |
| | | @Override |
| | | public AttributeDescription getAttributeDescription() |
| | | { |
| | | return attributeDescription; |
| | | } |
| | | |
| | | @Override |
| | | public Set<String> getOptions() |
| | | { |
| | | return Collections.emptySet(); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean hasAllOptions(Collection<String> options) |
| | | { |
| | | return options == null || options.isEmpty(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean hasOption(String option) |
| | | { |
| | | return false; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean optionsEqual(Set<String> options) |
| | | { |
| | | return options == null || options.isEmpty(); |
| | | } |
| | | |
| | | @Override |
| | | public int size() |
| | | { |
| | | if (provider.isMultiValued()) |
| | |
| | | RDN rdn = modifiedEntry.getName().rdn(); |
| | | if (rdn != null |
| | | && rdn.hasAttributeType(t) |
| | | && !modifiedEntry.hasValue(t, attr.getOptions(), rdn.getAttributeValue(t))) |
| | | && !modifiedEntry.hasValue(attr.getAttributeDescription(), rdn.getAttributeValue(t))) |
| | | { |
| | | throw newDirectoryException(currentEntry, |
| | | ResultCode.NOT_ALLOWED_ON_RDN, |
| | |
| | | RDN rdn = modifiedEntry.getName().rdn(); |
| | | if (rdn != null |
| | | && rdn.hasAttributeType(t) |
| | | && !modifiedEntry.hasValue(t, attr.getOptions(), rdn.getAttributeValue(t))) |
| | | && !modifiedEntry.hasValue(attr.getAttributeDescription(), rdn.getAttributeValue(t))) |
| | | { |
| | | throw newDirectoryException(modifiedEntry, ResultCode.NOT_ALLOWED_ON_RDN, |
| | | ERR_MODIFY_DELETE_RDN_ATTR.get(entryDN, attr.getName())); |
| | |
| | | } |
| | | |
| | | // Get the attribute that is to be incremented. |
| | | Attribute a = modifiedEntry.getExactAttribute(t, attr.getOptions()); |
| | | Attribute a = modifiedEntry.getExactAttribute(attr.getAttributeDescription()); |
| | | if (a == null) |
| | | { |
| | | throw newDirectoryException(modifiedEntry, |
| | |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.util.Reject; |
| | | import org.mockito.invocation.InvocationOnMock; |
| | | import org.mockito.stubbing.Answer; |
| | |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.types.BackupConfig; |
| | | import org.opends.server.types.BackupDirectory; |
| | | import org.opends.server.types.DN; |
| | |
| | | ModifyOperation modifyOp = mock(ModifyOperation.class); |
| | | when(modifyOp.getModifications()).thenReturn(mods); |
| | | backend.replaceEntry(oldEntry, newEntry, modifyOp); |
| | | assertTrue(backend.getEntry(oldEntry.getName()).hasValue(modifyAttribute, null, modifyValue)); |
| | | assertTrue(backend.getEntry(oldEntry.getName()).hasValue(modifyAttribute, modifyValue)); |
| | | |
| | | final List<Entry> returnedEntries = new ArrayList<>(); |
| | | backend.search(createSearchOperation( |
| | |
| | | boolean found = false; |
| | | |
| | | for (Attribute attrAfter : listAfter) { |
| | | if (attrAfter.optionsEqual(attrBefore.getOptions())) { |
| | | if (attrAfter.getAttributeDescription().equals(attrBefore.getAttributeDescription())) { |
| | | // Found the corresponding attribute |
| | | assertEquals(attrBefore, attrAfter); |
| | | found = true; |
| | |
| | | */ |
| | | package org.opends.server.core; |
| | | |
| | | |
| | | |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.admin.server.AdminTestCaseUtils; |
| | | import org.opends.server.admin.std.meta.PasswordPolicyCfgDefn; |
| | |
| | | import org.opends.server.config.ConfigEntry; |
| | | import org.opends.server.schema.UserPasswordSyntax; |
| | | import org.opends.server.tools.LDAPModify; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.InitializationException; |
| | | import org.opends.server.util.TimeThread; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.assertj.core.api.Assertions.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A set of generic test cases for the Directory Server password policy class. |
| | | */ |
| | |
| | | assertNotNull(entry); |
| | | AttributeType pwdHistory = DirectoryServer.getAttributeType("pwdhistory"); |
| | | assertNotNull(pwdHistory); |
| | | Attribute historyAttr = entry.getExactAttribute(pwdHistory, null); |
| | | Attribute historyAttr = entry.getExactAttribute(AttributeDescription.create(pwdHistory)); |
| | | assertNotNull(historyAttr); |
| | | assertThat(historyAttr).hasSize(3); |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | |
| | | import org.opends.server.tools.LDAPDelete; |
| | | import org.opends.server.tools.LDAPModify; |
| | | import org.opends.server.types.Attribute; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | |
| | | assertTrue(entry.hasAttribute(attrType)); |
| | | for (String value : values) |
| | | { |
| | | assertTrue(entry.hasValue(attrType, null, ByteString.valueOfUtf8(value))); |
| | | assertTrue(entry.hasValue(attrType, ByteString.valueOfUtf8(value))); |
| | | } |
| | | } |
| | | |
| | |
| | | assertTrue(entry.hasAttribute(attrType)); |
| | | for (String value : values) |
| | | { |
| | | assertFalse(entry.hasValue(attrType, null, ByteString.valueOfUtf8(value))); |
| | | assertFalse(entry.hasValue(attrType, ByteString.valueOfUtf8(value))); |
| | | } |
| | | } |
| | | |
| | |
| | | assertEquals(searchOperation.getEntriesSent(), 1); |
| | | AttributeType attrType = DirectoryServer.getAttributeType("collectiveattributesubentries"); |
| | | Entry e = searchOperation.getSearchEntries().getFirst(); |
| | | assertTrue(e.hasValue(attrType, null, ByteString.valueOfObject(collectiveSubentry.getName()))); |
| | | assertTrue(e.hasValue(attrType, ByteString.valueOfObject(collectiveSubentry.getName()))); |
| | | } |
| | | |
| | | @Test |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.api.AuthenticationPolicy; |
| | | import org.opends.server.api.PasswordValidator; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.util.StaticUtils; |
| | |
| | | // Make sure that default policy is in effect |
| | | // for the user entry. |
| | | assertTrue(testEntry.hasAttribute(attrType)); |
| | | assertTrue(testEntry.hasValue(attrType, null, |
| | | assertTrue(testEntry.hasValue(attrType, |
| | | ByteString.valueOfUtf8(defaultPolicy.getDN().toString()))); |
| | | |
| | | // Add new subentry policy with the |
| | |
| | | assertNotNull(testEntry); |
| | | |
| | | assertTrue(testEntry.hasAttribute(attrType)); |
| | | assertTrue(testEntry.hasValue(attrType, null, ByteString.valueOfUtf8("cn=Temp Policy," + SUFFIX))); |
| | | assertTrue(testEntry.hasValue(attrType, ByteString.valueOfUtf8("cn=Temp Policy," + SUFFIX))); |
| | | |
| | | // Remove subentry policy and make sure |
| | | // default policy is in effect again. |
| | |
| | | assertNotNull(testEntry); |
| | | |
| | | assertTrue(testEntry.hasAttribute(attrType)); |
| | | assertTrue(testEntry.hasValue(attrType, null, |
| | | assertTrue(testEntry.hasValue(attrType, |
| | | ByteString.valueOfUtf8(defaultPolicy.getDN().toString()))); |
| | | } |
| | | } |
| | |
| | | for (int i = 0; i < rdn.getNumValues(); i++) |
| | | { |
| | | AttributeType attribute = rdn.getAttributeType(i); |
| | | assertEquals(newEntry.hasValue(attribute, null, b("user.0")), user0Exists); |
| | | assertEquals(newEntry.hasValue(attribute, null, b("user.test0")), userTest0Exists); |
| | | assertEquals(newEntry.hasValue(attribute, b("user.0")), user0Exists); |
| | | assertEquals(newEntry.hasValue(attribute, b("user.test0")), userTest0Exists); |
| | | } |
| | | } |
| | | |
| | |
| | | import org.opends.server.api.Group; |
| | | import org.opends.server.api.plugin.PluginType; |
| | | import org.opends.server.controls.SubtreeDeleteControl; |
| | | import org.opends.server.core.*; |
| | | import org.opends.server.core.AddOperation; |
| | | import org.opends.server.core.DeleteOperation; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.GroupManager; |
| | | import org.opends.server.core.ModifyDNOperation; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | | * Unit test to test Referential Integrity plugin. |
| | | */ |
| | | /** Unit test to test Referential Integrity plugin. */ |
| | | @SuppressWarnings("javadoc") |
| | | public class ReferentialIntegrityPluginTestCase extends PluginTestCase { |
| | | |
| | |
| | | for (SearchResultEntry entry : operation.getSearchEntries()) { |
| | | for(String dn : dns) { |
| | | ByteString value = ByteString.valueOfUtf8(dn); |
| | | assertEquals(entry.hasValue(type, null, value), expected); |
| | | assertEquals(entry.hasValue(type, value), expected); |
| | | } |
| | | } |
| | | } |
| | |
| | | import java.io.File; |
| | | import java.net.SocketTimeoutException; |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.SortedSet; |
| | | import java.util.TreeSet; |
| | | import java.util.UUID; |
| | |
| | | import org.assertj.core.api.SoftAssertions; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.backends.MemoryBackend; |
| | | import org.opends.server.core.DirectoryServer; |
| | |
| | | import org.opends.server.replication.service.ReplicationBroker; |
| | | import org.opends.server.tasks.LdifFileWriter; |
| | | import org.opends.server.types.Attribute; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | |
| | | debugInfo("Entry found <" + baseDN + ">"); |
| | | |
| | | AttributeType synchronizationGenIDType = DirectoryServer.getAttributeType(REPLICATION_GENERATION_ID); |
| | | Attribute attr = resultEntry.getExactAttribute(synchronizationGenIDType, new HashSet<String>()); |
| | | Attribute attr = resultEntry.getExactAttribute(AttributeDescription.create(synchronizationGenIDType)); |
| | | return Long.valueOf(attr.iterator().next().toString()); |
| | | } |
| | | return -1; |
| | |
| | | */ |
| | | package org.opends.server.replication.plugin; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | import java.util.concurrent.Callable; |
| | | |
| | | import org.assertj.core.api.Assertions; |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.TestCaseUtils; |
| | |
| | | import org.opends.server.replication.protocol.ModifyMsg; |
| | | import org.opends.server.replication.service.ReplicationBroker; |
| | | import org.opends.server.tools.LDAPModify; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.types.Operation; |
| | | import org.opends.server.util.TestTimer; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | |
| | | final DN dn2 = DN.valueOf("cn=test2," + TEST_ROOT_DN_STRING); |
| | | final DN baseDN = DN.valueOf(TEST_ROOT_DN_STRING); |
| | | final AttributeType attrType = DirectoryServer.getAttributeType("displayname"); |
| | | final AttributeDescription attrDesc = AttributeDescription.create(attrType); |
| | | final AttributeType entryuuidType = DirectoryServer.getAttributeType("entryuuid"); |
| | | final AttributeDescription entryuuidDesc = AttributeDescription.create(entryuuidType); |
| | | |
| | | /* |
| | | * Open a session to the replicationServer using the broker API. |
| | |
| | | openReplicationSession(baseDN, 2, 100, replServerPort, 1000); |
| | | |
| | | |
| | | // Clear the backend and create top entrye |
| | | // Clear the backend and create top entry |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | // Add the first test entry. |
| | |
| | | ); |
| | | |
| | | // Read the entry back to get its UUID. |
| | | String entryuuid = getEntryValue(dn1, entryuuidType); |
| | | String entryuuid = getEntryValue(dn1, entryuuidDesc); |
| | | |
| | | // Add the second test entry. |
| | | TestCaseUtils.addEntry( |
| | |
| | | ); |
| | | |
| | | // Read the entry back to get its UUID. |
| | | String entryuuid2 = getEntryValue(dn2, entryuuidType); |
| | | String entryuuid2 = getEntryValue(dn2, entryuuidDesc); |
| | | |
| | | long now = System.currentTimeMillis(); |
| | | final int serverId1 = 3; |
| | |
| | | |
| | | // Replay an add of a value A at time t1 on a first server. |
| | | publishModify(broker, t1, dn1, entryuuid, attrType, "A"); |
| | | waitUntilEntryValueEquals(dn1, attrType, "A"); |
| | | waitUntilEntryValueEquals(dn1, attrDesc, "A"); |
| | | |
| | | // Replay an add of a value B at time t2 on a second server. |
| | | publishModify(broker, t2, dn1, entryuuid, attrType, "B"); |
| | |
| | | t2 = new CSN(now+4, 0, serverId2); |
| | | |
| | | publishModify(broker, t2, dn2, entryuuid2, attrType, "B"); |
| | | waitUntilEntryValueEquals(dn2, attrType, "B"); |
| | | waitUntilEntryValueEquals(dn2, attrDesc, "B"); |
| | | |
| | | // Replay an add of a value A at time t1 on a first server. |
| | | publishModify(broker, t1, dn2, entryuuid2, attrType, "A"); |
| | | |
| | | // See how the conflicts were resolved. |
| | | // The two values should be the first value added. |
| | | waitUntilEntryValueEquals(dn1, attrType, "A"); |
| | | waitUntilEntryValueEquals(dn2, attrType, "A"); |
| | | waitUntilEntryValueEquals(dn1, attrDesc, "A"); |
| | | waitUntilEntryValueEquals(dn2, attrDesc, "A"); |
| | | |
| | | TestCaseUtils.deleteEntry(dn1); |
| | | TestCaseUtils.deleteEntry(dn2); |
| | | } |
| | | |
| | | private void waitUntilEntryValueEquals(final DN entryDN, final AttributeType attrType, final String expectedValue) |
| | | throws Exception |
| | | private void waitUntilEntryValueEquals(final DN entryDN, final AttributeDescription attrDesc, |
| | | final String expectedValue) throws Exception |
| | | { |
| | | final TestTimer timer = new TestTimer.Builder() |
| | | .maxSleep(2, SECONDS) |
| | |
| | | @Override |
| | | public Void call() throws Exception |
| | | { |
| | | assertEquals(getEntryValue(entryDN, attrType), expectedValue); |
| | | assertEquals(getEntryValue(entryDN, attrDesc), expectedValue); |
| | | return null; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private String getEntryValue(final DN dn, final AttributeType attrType) throws Exception |
| | | private String getEntryValue(final DN dn, AttributeDescription attrDesc) throws DirectoryException |
| | | { |
| | | Entry entry = DirectoryServer.getEntry(dn); |
| | | Attribute attr = entry.getExactAttribute(attrType, Collections.<String> emptySet()); |
| | | Attribute attr = entry.getExactAttribute(attrDesc); |
| | | Assertions.assertThat(attr).hasSize(1); |
| | | return attr.iterator().next().toString(); |
| | | } |
| | |
| | | */ |
| | | package org.opends.server.replication.plugin; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.HashMap; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | |
| | | |
| | | private void assertContainsOnlyValues(Entry entry, String attrName, String... expectedValues) |
| | | { |
| | | Attribute attr = entry.getExactAttribute(getAttributeType(attrName), Collections.<String> emptySet()); |
| | | Attribute attr = entry.getExactAttribute(AttributeDescription.create(getAttributeType(attrName))); |
| | | assertThat(attr).hasSize(expectedValues.length); |
| | | for (String value : expectedValues) |
| | | { |
| | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.replication.ReplicationTestCase; |
| | | import org.opends.server.replication.common.CSN; |
| | |
| | | entryHistorical.replayOperation(op, entry); |
| | | entry.applyModification(new Modification(REPLACE, entryHistorical.encodeAndPurge())); |
| | | |
| | | AttributeType attrType = expectedDsSyncHist.getAttributeType(); |
| | | Attribute actual = entry.getExactAttribute(attrType, Collections.<String> emptySet()); |
| | | |
| | | Attribute actual = entry.getExactAttribute(expectedDsSyncHist.getAttributeDescription()); |
| | | Assert.assertEquals(actual, expectedDsSyncHist, "wrong final value for ds-sync-hist attribute"); |
| | | } |
| | | |
| | |
| | | entry.applyModification(new Modification(REPLACE, entryHistorical.encodeAndPurge())); |
| | | } |
| | | |
| | | AttributeType attrType = expectedDsSyncHist.getAttributeType(); |
| | | Attribute actual = entry.getExactAttribute(attrType, Collections.<String> emptySet()); |
| | | |
| | | Attribute actual = entry.getExactAttribute(expectedDsSyncHist.getAttributeDescription()); |
| | | Assert.assertEquals(actual, expectedDsSyncHist, "wrong final value for ds-sync-hist attribute"); |
| | | } |
| | | |
| | |
| | | import java.util.TreeSet; |
| | | |
| | | import org.forgerock.opendj.ldap.Assertion; |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | |
| | | |
| | | void add(Entry entry) throws DecodeException |
| | | { |
| | | Attribute attribute = entry.getExactAttribute(attrType, Collections.<String>emptySet()); |
| | | Attribute attribute = entry.getExactAttribute(AttributeDescription.create(attrType)); |
| | | for (ByteString key : index(attribute)) |
| | | { |
| | | Set<Entry> entries = index.get(key); |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.GregorianCalendar; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.TimeZone; |
| | | |
| | | import org.forgerock.opendj.ldap.Assertion; |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | |
| | | Collection<DN> results = new ArrayList<>(); |
| | | for (Entry entry : makeEntries()) |
| | | { |
| | | Attribute attribute = entry.getExactAttribute(attrType, Collections.<String> emptySet()); |
| | | Attribute attribute = entry.getExactAttribute(AttributeDescription.create(attrType)); |
| | | if (attribute != null) |
| | | { |
| | | ByteString attrValue = rule.normalizeAttributeValue(attribute.iterator().next()); |
| | |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.HashSet; |
| | | import java.util.Iterator; |
| | |
| | | import java.util.NoSuchElementException; |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.TestCaseUtils; |
| | |
| | | * The expected attribute values. |
| | | */ |
| | | @Test(dataProvider = "createAttributes", dependsOnMethods = "testAttributeNotNull") |
| | | public void testAttributeHasAllOptions(int testCase, Attribute a, |
| | | public void testAttributeDescriptionIsSubTypeOf(int testCase, Attribute a, |
| | | AttributeType type, String name, String[] options, String[] values) |
| | | throws Exception |
| | | { |
| | | Assert.assertTrue(a.hasAllOptions(null)); |
| | | Assert.assertTrue(a.hasAllOptions(Collections.<String> emptySet())); |
| | | Assert.assertTrue(a.hasAllOptions(Arrays.asList(options))); |
| | | AttributeDescription attrDesc = a.getAttributeDescription(); |
| | | Assert.assertTrue(attrDesc.isSubTypeOf(AttributeDescription.create(type))); |
| | | Assert.assertTrue(attrDesc.isSubTypeOf(AttributeDescription.create(type, options))); |
| | | |
| | | if (options.length > 1) |
| | | { |
| | | Assert.assertTrue(a.hasAllOptions(Arrays.asList(options).subList(1, options.length))); |
| | | List<String> options2 = Arrays.asList(options).subList(1, options.length); |
| | | Assert.assertTrue(attrDesc.isSubTypeOf(AttributeDescription.create(type, options2))); |
| | | } |
| | | |
| | | List<String> tmp = newArrayList(options); |
| | | tmp.add("xxxx"); |
| | | Assert.assertFalse(a.hasAllOptions(tmp)); |
| | | Assert.assertFalse(attrDesc.isSubTypeOf(AttributeDescription.create(type, tmp))); |
| | | |
| | | Assert.assertFalse(a.hasAllOptions(newHashSet("xxxx"))); |
| | | Assert.assertFalse(attrDesc.isSubTypeOf(AttributeDescription.create(type, "xxxx"))); |
| | | |
| | | tmp.clear(); |
| | | for (String option : options) |
| | |
| | | // Assumes internal normalization to lower-case. |
| | | tmp.add(option.toUpperCase()); |
| | | } |
| | | Assert.assertTrue(a.hasAllOptions(tmp)); |
| | | Assert.assertTrue(attrDesc.isSubTypeOf(AttributeDescription.create(type, tmp))); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests {@link Attribute#hashCode()}. |
| | | * |
| | |
| | | * The expected attribute values. |
| | | */ |
| | | @Test(dataProvider = "createAttributes", dependsOnMethods = "testAttributeNotNull") |
| | | public void testAttributeOptionsEquals(int testCase, Attribute a, |
| | | public void testAttributeDescriptionEquals(int testCase, Attribute a, |
| | | AttributeType type, String name, String[] options, String[] values) |
| | | throws Exception |
| | | { |
| | | // Check optionsEquals. |
| | | Assert.assertTrue(a.optionsEqual(newHashSet(options))); |
| | | // Check attributeDescription.equals() |
| | | AttributeDescription attrDesc = a.getAttributeDescription(); |
| | | Assert.assertTrue(attrDesc.equals(AttributeDescription.create(type, options))); |
| | | |
| | | if (options.length > 1) |
| | | { |
| | | Assert.assertFalse(a.optionsEqual(Collections.singleton(options[0]))); |
| | | Assert.assertFalse(attrDesc.equals(AttributeDescription.create(type, options[0]))); |
| | | } |
| | | |
| | | Set<String> stmp = newHashSet(options); |
| | | stmp.add("xxxx"); |
| | | Assert.assertFalse(a.optionsEqual(stmp)); |
| | | Assert.assertFalse(attrDesc.equals(AttributeDescription.create(type, stmp))); |
| | | |
| | | stmp.clear(); |
| | | for (String option : options) |
| | |
| | | // Assumes internal normalization to lower-case. |
| | | stmp.add(option.toUpperCase()); |
| | | } |
| | | Assert.assertTrue(a.optionsEqual(stmp)); |
| | | Assert.assertTrue(attrDesc.equals(AttributeDescription.create(type, stmp))); |
| | | } |
| | | |
| | | |
| | |
| | | import org.assertj.core.api.Assertions; |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.TestCaseUtils; |
| | |
| | | assertTrue(e.hasAttribute(mnType)); |
| | | |
| | | LinkedHashSet<String> options = null; |
| | | assertTrue(e.hasAttribute(ocType, options)); |
| | | assertTrue(e.hasAttribute(cnType, options)); |
| | | assertTrue(e.hasAttribute(nameType, options)); |
| | | assertFalse(e.hasAttribute(nameType, options, false)); |
| | | assertFalse(e.hasAttribute(uidType, options)); |
| | | assertTrue(e.hasAttribute(mnType, options)); |
| | | assertTrue(e.hasAttribute(AttributeDescription.create(ocType, options), true)); |
| | | assertTrue(e.hasAttribute(AttributeDescription.create(cnType, options), true)); |
| | | assertTrue(e.hasAttribute(AttributeDescription.create(nameType, options), true)); |
| | | assertFalse(e.hasAttribute(AttributeDescription.create(nameType, options), false)); |
| | | assertFalse(e.hasAttribute(AttributeDescription.create(uidType, options), true)); |
| | | assertTrue(e.hasAttribute(AttributeDescription.create(mnType, options), true)); |
| | | |
| | | options = new LinkedHashSet<>(); |
| | | assertTrue(e.hasAttribute(ocType, options)); |
| | | assertTrue(e.hasAttribute(cnType, options)); |
| | | assertTrue(e.hasAttribute(nameType, options)); |
| | | assertFalse(e.hasAttribute(nameType, options, false)); |
| | | assertFalse(e.hasAttribute(uidType, options)); |
| | | assertTrue(e.hasAttribute(mnType, options)); |
| | | assertTrue(e.hasAttribute(AttributeDescription.create(ocType, options), true)); |
| | | assertTrue(e.hasAttribute(AttributeDescription.create(cnType, options), true)); |
| | | assertTrue(e.hasAttribute(AttributeDescription.create(nameType, options), true)); |
| | | assertFalse(e.hasAttribute(AttributeDescription.create(nameType, options), false)); |
| | | assertFalse(e.hasAttribute(AttributeDescription.create(uidType, options), true)); |
| | | assertTrue(e.hasAttribute(AttributeDescription.create(mnType, options), true)); |
| | | |
| | | options.add("lang-en-US"); |
| | | assertFalse(e.hasAttribute(ocType, options)); |
| | | assertTrue(e.hasAttribute(cnType, options)); |
| | | assertTrue(e.hasAttribute(nameType, options)); |
| | | assertFalse(e.hasAttribute(nameType, options, false)); |
| | | assertFalse(e.hasAttribute(uidType, options)); |
| | | assertFalse(e.hasAttribute(mnType, options)); |
| | | assertFalse(e.hasAttribute(AttributeDescription.create(ocType, options), true)); |
| | | assertTrue(e.hasAttribute(AttributeDescription.create(cnType, options), true)); |
| | | assertTrue(e.hasAttribute(AttributeDescription.create(nameType, options), true)); |
| | | assertFalse(e.hasAttribute(AttributeDescription.create(nameType, options), false)); |
| | | assertFalse(e.hasAttribute(AttributeDescription.create(uidType, options), true)); |
| | | assertFalse(e.hasAttribute(AttributeDescription.create(mnType, options), true)); |
| | | |
| | | options.add("lang-en-GB"); |
| | | assertFalse(e.hasAttribute(ocType, options)); |
| | | assertFalse(e.hasAttribute(cnType, options)); |
| | | assertFalse(e.hasAttribute(nameType, options)); |
| | | assertFalse(e.hasAttribute(nameType, options, false)); |
| | | assertFalse(e.hasAttribute(uidType, options)); |
| | | assertFalse(e.hasAttribute(mnType, options)); |
| | | assertFalse(e.hasAttribute(AttributeDescription.create(ocType, options), true)); |
| | | assertFalse(e.hasAttribute(AttributeDescription.create(cnType, options), true)); |
| | | assertFalse(e.hasAttribute(AttributeDescription.create(nameType, options), true)); |
| | | assertFalse(e.hasAttribute(AttributeDescription.create(nameType, options), false)); |
| | | assertFalse(e.hasAttribute(AttributeDescription.create(uidType, options), true)); |
| | | assertFalse(e.hasAttribute(AttributeDescription.create(mnType, options), true)); |
| | | |
| | | options.clear(); |
| | | options.add("lang-en-GB"); |
| | | assertFalse(e.hasAttribute(ocType, options)); |
| | | assertFalse(e.hasAttribute(cnType, options)); |
| | | assertFalse(e.hasAttribute(nameType, options)); |
| | | assertFalse(e.hasAttribute(nameType, options, false)); |
| | | assertFalse(e.hasAttribute(uidType, options)); |
| | | assertFalse(e.hasAttribute(mnType, options)); |
| | | assertFalse(e.hasAttribute(AttributeDescription.create(ocType, options), true)); |
| | | assertFalse(e.hasAttribute(AttributeDescription.create(cnType, options), true)); |
| | | assertFalse(e.hasAttribute(AttributeDescription.create(nameType, options), true)); |
| | | assertFalse(e.hasAttribute(AttributeDescription.create(nameType, options), false)); |
| | | assertFalse(e.hasAttribute(AttributeDescription.create(uidType, options), true)); |
| | | assertFalse(e.hasAttribute(AttributeDescription.create(mnType, options), true)); |
| | | } |
| | | |
| | | |
| | |
| | | assertThat(e.getOperationalAttribute(mnType)).hasSize(1); |
| | | |
| | | LinkedHashSet<String> options = null; |
| | | assertThat(e.getOperationalAttribute(ocType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(cnType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(nameType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(uidType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(mnType, options)).hasSize(1); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(ocType, options))).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(cnType, options))).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(nameType, options))).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(uidType, options))).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(mnType, options))).hasSize(1); |
| | | |
| | | options = new LinkedHashSet<>(); |
| | | assertThat(e.getOperationalAttribute(ocType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(cnType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(nameType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(uidType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(mnType, options)).hasSize(1); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(ocType, options))).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(cnType, options))).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(nameType, options))).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(uidType, options))).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(mnType, options))).hasSize(1); |
| | | |
| | | options.add("lang-en-US"); |
| | | assertThat(e.getOperationalAttribute(ocType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(cnType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(nameType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(uidType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(mnType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(ocType, options))).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(cnType, options))).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(nameType, options))).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(uidType, options))).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(mnType, options))).isEmpty(); |
| | | |
| | | options.add("lang-en-GB"); |
| | | assertThat(e.getOperationalAttribute(ocType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(cnType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(nameType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(uidType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(mnType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(ocType, options))).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(cnType, options))).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(nameType, options))).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(uidType, options))).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(mnType, options))).isEmpty(); |
| | | |
| | | options.clear(); |
| | | options.add("lang-en-GB"); |
| | | assertThat(e.getOperationalAttribute(ocType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(cnType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(nameType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(uidType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(mnType, options)).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(ocType, options))).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(cnType, options))).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(nameType, options))).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(uidType, options))).isEmpty(); |
| | | assertThat(e.getOperationalAttribute(AttributeDescription.create(mnType, options))).isEmpty(); |
| | | } |
| | | } |
| | |
| | | + "objectClass: top\n" + "objectClass: person\n" + "cn: john\n" |
| | | + "sn: smith\n"; |
| | | |
| | | LDIFReader reader = createLDIFReader(ldifString); |
| | | |
| | | try { |
| | | try (LDIFReader reader = createLDIFReader(ldifString)) { |
| | | Entry entry = reader.readEntry(); |
| | | Assert.assertNotNull(entry); |
| | | |
| | | Assert.assertEquals(entry.getName(), DN |
| | | .valueOf("cn=john, dc=foo, dc=com")); |
| | | Assert.assertEquals(entry.getName(), DN.valueOf("cn=john, dc=foo, dc=com")); |
| | | Assert.assertTrue(entry.hasObjectClass(OC_TOP)); |
| | | Assert.assertTrue(entry.hasObjectClass(OC_PERSON)); |
| | | Assert.assertTrue(entry.hasValue(AT_CN, null, ByteString.valueOfUtf8("john"))); |
| | | Assert.assertTrue(entry.hasValue(AT_SN, null, ByteString.valueOfUtf8("smith"))); |
| | | Assert.assertTrue(entry.hasValue(AT_CN, ByteString.valueOfUtf8("john"))); |
| | | Assert.assertTrue(entry.hasValue(AT_SN, ByteString.valueOfUtf8("smith"))); |
| | | |
| | | Assert.assertNull(reader.readEntry()); |
| | | |
| | |
| | | Assert.assertEquals(reader.getEntriesRead(), 1); |
| | | Assert.assertEquals(reader.getEntriesRejected(), 0); |
| | | Assert.assertEquals(reader.getLastEntryLineNumber(), 1); |
| | | } finally { |
| | | reader.close(); |
| | | } |
| | | } |
| | | |
| | |
| | | + "sn: smith\n" + "description: once upon a time\n" |
| | | + " in the west\n"; |
| | | |
| | | LDIFReader reader = createLDIFReader(ldifString); |
| | | |
| | | try { |
| | | try (LDIFReader reader = createLDIFReader(ldifString)) { |
| | | Entry entry = reader.readEntry(); |
| | | Assert.assertNotNull(entry); |
| | | Assert.assertTrue(entry.hasValue(AT_DESCR, null, ByteString.valueOfUtf8("once upon a time in the west"))); |
| | | } finally { |
| | | reader.close(); |
| | | Assert.assertTrue(entry.hasValue(AT_DESCR, ByteString.valueOfUtf8("once upon a time in the west"))); |
| | | } |
| | | } |
| | | |
| | |
| | | + "sn: smith\n" |
| | | + "description:: b25jZSB1cG9uIGEgdGltZSBpbiB0aGUgd2VzdA==\n"; |
| | | |
| | | LDIFReader reader = createLDIFReader(ldifString); |
| | | |
| | | try { |
| | | try (LDIFReader reader = createLDIFReader(ldifString)) { |
| | | Entry entry = reader.readEntry(); |
| | | Assert.assertNotNull(entry); |
| | | Assert.assertTrue(entry.hasValue(AT_DESCR, null, ByteString.valueOfUtf8("once upon a time in the west"))); |
| | | } finally { |
| | | reader.close(); |
| | | Assert.assertTrue(entry.hasValue(AT_DESCR, ByteString.valueOfUtf8("once upon a time in the west"))); |
| | | } |
| | | } |
| | | |
| | |
| | | + "objectClass: top\n" + "objectClass: person\n" + "cn: anne\n" |
| | | + "sn: other\n" + "\n"; |
| | | |
| | | LDIFReader reader = createLDIFReader(ldifString); |
| | | |
| | | try { |
| | | try (LDIFReader reader = createLDIFReader(ldifString)) { |
| | | reader.readEntry(); |
| | | Entry entry = reader.readEntry(); |
| | | |
| | | Assert.assertNotNull(entry); |
| | | |
| | | Assert.assertEquals(entry.getName(), DN |
| | | .valueOf("cn=anne, dc=foo, dc=com")); |
| | | Assert.assertEquals(entry.getName(), DN.valueOf("cn=anne, dc=foo, dc=com")); |
| | | Assert.assertTrue(entry.hasObjectClass(OC_TOP)); |
| | | Assert.assertTrue(entry.hasObjectClass(OC_PERSON)); |
| | | Assert.assertTrue(entry.hasValue(AT_CN, null, ByteString.valueOfUtf8("anne"))); |
| | | Assert.assertTrue(entry.hasValue(AT_SN, null, ByteString.valueOfUtf8("other"))); |
| | | Assert.assertTrue(entry.hasValue(AT_CN, ByteString.valueOfUtf8("anne"))); |
| | | Assert.assertTrue(entry.hasValue(AT_SN, ByteString.valueOfUtf8("other"))); |
| | | |
| | | Assert.assertNull(reader.readEntry()); |
| | | |
| | |
| | | Assert.assertEquals(reader.getEntriesRead(), 2); |
| | | Assert.assertEquals(reader.getEntriesRejected(), 0); |
| | | Assert.assertEquals(reader.getLastEntryLineNumber(), 7); |
| | | } finally { |
| | | reader.close(); |
| | | } |
| | | } |
| | | |