mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noël Rouvignac
28.37.2016 e04805772f4e73c029bdd907c498f4affe15f04a
Use AttributeDescription in CompareOperation

CompareOperation*.java:
Converted use of both AttributeType and Collection<String> for paremeters, fields, etc. into using AttributeDescription instead.
11 files modified
336 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/core/CompareOperation.java 44 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/core/CompareOperationBasis.java 85 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/core/CompareOperationWrapper.java 50 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/loggers/CommonAuditAccessLogPublisher.java 4 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/loggers/TextAccessLogPublisher.java 27 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java 22 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/operation/PostOperationCompareOperation.java 8 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/operation/PostResponseCompareOperation.java 11 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/operation/PreOperationCompareOperation.java 8 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/workflowelement/localbackend/LocalBackendCompareOperation.java 27 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/types/TestEntry.java 50 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/core/CompareOperation.java
@@ -26,11 +26,10 @@
 */
package org.opends.server.core;
import java.util.Set;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.AttributeDescription;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.DN;
import org.opends.server.types.Operation;
/**
@@ -88,40 +87,13 @@
   */
  void setRawAttributeType(String rawAttributeType);
  /**
   * Retrieves the attribute type for this compare operation.  This should not
   * be called by pre-parse plugins because the processed attribute type will
   * not be available yet.
   * Retrieves the attribute description for this compare operation. This should not be called by
   * pre-parse plugins because the processed attribute description will not be available yet.
   *
   * @return  The attribute type for this compare operation.
   * @return The attribute description for this compare operation.
   */
  AttributeType getAttributeType();
  /**
   * Specifies the attribute type for this compare operation.
   *
   * @param attributeType  The attribute type for this compare operation.
   */
  void setAttributeType(AttributeType attributeType);
  /**
   * Retrieves the attribute options for this compare operation. This should
   * not be called by the pre-parse plugins because the processed attribute
   * options will not be available yet.
   *
   * @return  The attribute options for this compare operation.
   */
  Set<String> getAttributeOptions();
  /**
   * Specifies the attribute options for this compare operation.
   *
   * @param attributeOptions The attribute options for this compare operation.
   */
  void setAttributeOptions(Set<String> attributeOptions);
  AttributeDescription getAttributeDescription();
  /**
   * Retrieves the assertion value for this compare operation.
@@ -145,6 +117,7 @@
   *
   * @return  The proxied authorization target DN for this compare operation
   */
  @Override
  DN getProxiedAuthorizationDN();
@@ -154,6 +127,7 @@
   * @param proxiedAuthorizationDN  The proxied authorization target DN for
   *                                this compare operation
   */
  @Override
  void setProxiedAuthorizationDN(DN proxiedAuthorizationDN);
}
opendj-server-legacy/src/main/java/org/opends/server/core/CompareOperationBasis.java
@@ -27,16 +27,25 @@
package org.opends.server.core;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
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.ResultCode;
import org.opends.server.api.ClientConnection;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.opends.server.types.*;
import org.opends.server.api.ClientConnection;
import org.opends.server.types.AbstractOperation;
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.Operation;
import org.opends.server.types.OperationType;
import org.opends.server.types.operation.PostResponseCompareOperation;
import org.opends.server.types.operation.PreParseCompareOperation;
import org.opends.server.workflowelement.localbackend.LocalBackendCompareOperation;
@@ -59,15 +68,12 @@
{
  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
  /** The attribute type for this compare operation. */
  private AttributeType attributeType;
  /** The attribute description for this compare operation. */
  private AttributeDescription attributeDescription;
  /** The assertion value for the compare operation. */
  private ByteString assertionValue;
  /** The set of attribute options. */
  private Set<String> attributeOptions;
  /** The raw, unprocessed entry DN as included in the client request. */
  private ByteString rawEntryDN;
@@ -115,8 +121,7 @@
    responseControls       = new ArrayList<>();
    entryDN                = null;
    attributeType          = null;
    attributeOptions       = null;
    attributeDescription = null;
    cancelRequest          = null;
    proxiedAuthorizationDN = null;
  }
@@ -146,7 +151,7 @@
    this.entryDN        = entryDN;
    this.attributeType  = attributeType;
    this.attributeDescription = AttributeDescription.create(attributeType);
    this.assertionValue = assertionValue;
    responseControls       = new ArrayList<>();
@@ -154,7 +159,6 @@
    rawAttributeType       = attributeType.getNameOrOID();
    cancelRequest          = null;
    proxiedAuthorizationDN = null;
    attributeOptions       = new HashSet<>();
  }
  /** {@inheritDoc} */
@@ -200,23 +204,33 @@
    return rawAttributeType;
  }
  /** {@inheritDoc} */
  @Override
  public final void setRawAttributeType(String rawAttributeType)
  {
    this.rawAttributeType = rawAttributeType;
    attributeType = null;
    attributeOptions = null;
    attributeDescription = null;
  }
  private void getAttributeTypeAndOptions() {
  @Override
  public final AttributeDescription getAttributeDescription()
  {
    if (attributeDescription == null)
    {
      attributeDescription = getAttributeDescription0();
    }
    return attributeDescription;
  }
  private AttributeDescription getAttributeDescription0()
  {
    String baseName;
    int semicolonPos = rawAttributeType.indexOf(';');
    Set<String> attributeOptions;
    if (semicolonPos > 0) {
      baseName = toLowerCase(rawAttributeType.substring(0, semicolonPos));
      attributeOptions = new HashSet<>();
      attributeOptions = new LinkedHashSet<>();
      int nextPos = rawAttributeType.indexOf(';', semicolonPos+1);
      while (nextPos > 0)
      {
@@ -233,44 +247,9 @@
      baseName = toLowerCase(rawAttributeType);
      attributeOptions  = null;
    }
    attributeType = DirectoryServer.getAttributeType(baseName);
    return AttributeDescription.create(DirectoryServer.getAttributeType(baseName), attributeOptions);
  }
  /** {@inheritDoc} */
  @Override
  public final AttributeType getAttributeType()
  {
    if (attributeType == null) {
      getAttributeTypeAndOptions();
    }
    return attributeType;
  }
  /** {@inheritDoc} */
  @Override
  public void setAttributeType(AttributeType attributeType)
  {
    this.attributeType = attributeType;
  }
  /** {@inheritDoc} */
  @Override
  public Set<String> getAttributeOptions()
  {
    if (attributeOptions == null) {
      getAttributeTypeAndOptions();
    }
    return attributeOptions;
  }
  /** {@inheritDoc} */
  @Override
  public void setAttributeOptions(Set<String> attributeOptions)
  {
    this.attributeOptions = attributeOptions;
  }
  /** {@inheritDoc} */
  @Override
  public final ByteString getAssertionValue()
  {
opendj-server-legacy/src/main/java/org/opends/server/core/CompareOperationWrapper.java
@@ -26,9 +26,7 @@
 */
package org.opends.server.core;
import java.util.Set;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.forgerock.opendj.ldap.AttributeDescription;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.DN;
@@ -51,93 +49,51 @@
    super(compare);
  }
  /** {@inheritDoc} */
  @Override
  public ByteString getRawEntryDN()
  {
    return getOperation().getRawEntryDN();
  }
  /** {@inheritDoc} */
  @Override
  public void setRawEntryDN(ByteString rawEntryDN)
  {
    getOperation().setRawEntryDN(rawEntryDN);
  }
  /** {@inheritDoc} */
  @Override
  public DN getEntryDN()
  {
    return getOperation().getEntryDN();
  }
  /** {@inheritDoc} */
  @Override
  public String getRawAttributeType()
  {
    return getOperation().getRawAttributeType();
  }
  /** {@inheritDoc} */
  @Override
  public void setRawAttributeType(String rawAttributeType)
  {
    getOperation().setRawAttributeType(rawAttributeType);
  }
  /** {@inheritDoc} */
  @Override
  public AttributeType getAttributeType()
  public AttributeDescription getAttributeDescription()
  {
    return getOperation().getAttributeType();
    return getOperation().getAttributeDescription();
  }
  /** {@inheritDoc} */
  @Override
  public void setAttributeType(AttributeType attributeType)
  {
    getOperation().setAttributeType(attributeType);
  }
  /** {@inheritDoc} */
  @Override
  public Set<String> getAttributeOptions()
  {
    return getOperation().getAttributeOptions();
  }
  /** {@inheritDoc} */
  @Override
  public void setAttributeOptions(Set<String> attributeOptions)
  {
    getOperation().setAttributeOptions(attributeOptions);
  }
  /** {@inheritDoc} */
  @Override
  public ByteString getAssertionValue()
  {
    return getOperation().getAssertionValue();
  }
  /** {@inheritDoc} */
  @Override
  public void setAssertionValue(ByteString assertionValue)
  {
    getOperation().setAssertionValue(assertionValue);
  }
}
opendj-server-legacy/src/main/java/org/opends/server/loggers/CommonAuditAccessLogPublisher.java
@@ -21,7 +21,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2015 ForgeRock AS
 *      Copyright 2015-2016 ForgeRock AS
 */
package org.opends.server.loggers;
@@ -410,7 +410,7 @@
      final OpenDJAccessAuditEventBuilder<?> builder)
  {
    builder.ldapDn(compareOperation.getRawEntryDN().toString());
    builder.ldapAttr(compareOperation.getAttributeType().getNameOrOID());
    builder.ldapAttr(compareOperation.getAttributeDescription().getAttributeType().getNameOrOID());
  }
  private void appendDeleteRequest(final DeleteOperation deleteOperation,
opendj-server-legacy/src/main/java/org/opends/server/loggers/TextAccessLogPublisher.java
@@ -22,7 +22,7 @@
 *
 *
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 *      Portions Copyright 2011-2015 ForgeRock AS
 *      Portions Copyright 2011-2016 ForgeRock AS
 */
package org.opends.server.loggers;
@@ -49,8 +49,27 @@
import org.opends.server.api.ClientConnection;
import org.opends.server.api.ExtendedOperationHandler;
import org.opends.server.controls.TransactionIdControl;
import org.opends.server.core.*;
import org.opends.server.types.*;
import org.opends.server.core.AbandonOperation;
import org.opends.server.core.AddOperation;
import org.opends.server.core.BindOperation;
import org.opends.server.core.CompareOperation;
import org.opends.server.core.DeleteOperation;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ExtendedOperation;
import org.opends.server.core.ModifyDNOperation;
import org.opends.server.core.ModifyOperation;
import org.opends.server.core.SearchOperation;
import org.opends.server.core.ServerContext;
import org.opends.server.core.UnbindOperation;
import org.opends.server.types.AdditionalLogItem;
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.DisconnectReason;
import org.opends.server.types.FilePermission;
import org.opends.server.types.InitializationException;
import org.opends.server.types.Operation;
import org.opends.server.util.StaticUtils;
import org.opends.server.util.TimeThread;
@@ -818,7 +837,7 @@
  {
    appendLabel(buffer, "dn", compareOperation.getRawEntryDN());
    buffer.append(" attr=");
    buffer.append(compareOperation.getAttributeType().getNameOrOID());
    buffer.append(compareOperation.getAttributeDescription().getAttributeType().getNameOrOID());
    appendRequestControls(compareOperation, buffer);
    if (compareOperation.isSynchronizationOperation())
    {
opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java
@@ -702,28 +702,6 @@
  /**
   * Retrieves the requested attribute element(s) for the specified
   * attribute type.  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  attributeType       The attribute type to retrieve.
   * @param  options             The set of attribute options to
   *                             include in matching elements.
   *
   * @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.
   */
  @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
opendj-server-legacy/src/main/java/org/opends/server/types/operation/PostOperationCompareOperation.java
@@ -28,7 +28,7 @@
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.forgerock.opendj.ldap.AttributeDescription;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.DN;
import org.opends.server.types.Entry;
@@ -79,11 +79,11 @@
  /**
   * Retrieves the attribute type for this compare operation.
   * Retrieves the attribute description for this compare operation.
   *
   * @return  The attribute type for this compare operation.
   * @return The attribute description for this compare operation.
   */
  AttributeType getAttributeType();
  AttributeDescription getAttributeDescription();
opendj-server-legacy/src/main/java/org/opends/server/types/operation/PostResponseCompareOperation.java
@@ -28,9 +28,10 @@
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.AttributeDescription;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.DN;
import org.opends.server.types.Entry;
/**
@@ -77,11 +78,11 @@
  /**
   * Retrieves the attribute type for this compare operation.
   * Retrieves the attribute description for this compare operation.
   *
   * @return  The attribute type for this compare operation.
   * @return The attribute description for this compare operation.
   */
  AttributeType getAttributeType();
  AttributeDescription getAttributeDescription();
opendj-server-legacy/src/main/java/org/opends/server/types/operation/PreOperationCompareOperation.java
@@ -28,7 +28,7 @@
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.forgerock.opendj.ldap.AttributeDescription;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.DN;
import org.opends.server.types.Entry;
@@ -79,11 +79,11 @@
  /**
   * Retrieves the attribute type for this compare operation.
   * Retrieves the attribute description for this compare operation.
   *
   * @return  The attribute type for this compare operation.
   * @return The attribute description for this compare operation.
   */
  AttributeType getAttributeType();
  AttributeDescription getAttributeDescription();
opendj-server-legacy/src/main/java/org/opends/server/workflowelement/localbackend/LocalBackendCompareOperation.java
@@ -27,21 +27,30 @@
package org.opends.server.workflowelement.localbackend;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
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.ResultCode;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.opends.server.api.AccessControlHandler;
import org.opends.server.api.Backend;
import org.opends.server.api.ClientConnection;
import org.opends.server.controls.LDAPAssertionRequestControl;
import org.opends.server.core.*;
import org.opends.server.types.*;
import org.opends.server.core.AccessControlConfigManager;
import org.opends.server.core.CompareOperation;
import org.opends.server.core.CompareOperationWrapper;
import org.opends.server.core.DirectoryServer;
import org.opends.server.types.Attribute;
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.Privilege;
import org.opends.server.types.SearchFilter;
import org.opends.server.types.operation.PostOperationCompareOperation;
import org.opends.server.types.operation.PostResponseCompareOperation;
import org.opends.server.types.operation.PreOperationCompareOperation;
@@ -230,17 +239,13 @@
        return;
      }
      // Get the base attribute type and set of options.
      Set<String> options = getAttributeOptions();
      AttributeType attrType = getAttributeType();
      // Actually perform the compare operation.
      List<Attribute> attrList = entry.getAttribute(attrType, options);
      AttributeDescription attrDesc = getAttributeDescription();
      List<Attribute> attrList = entry.getAttribute(attrDesc);
      if (attrList.isEmpty())
      {
        setResultCode(ResultCode.NO_SUCH_ATTRIBUTE);
        Arg2<Object, Object> errorMsg = options == null
        Arg2<Object, Object> errorMsg = attrDesc.hasOptions()
            ? WARN_COMPARE_OP_NO_SUCH_ATTR
            : WARN_COMPARE_OP_NO_SUCH_ATTR_WITH_OPTIONS;
        appendErrorMessage(errorMsg.get(entryDN, getRawAttributeType()));
opendj-server-legacy/src/test/java/org/opends/server/types/TestEntry.java
@@ -488,43 +488,43 @@
    assertThat(e.getAttribute("modifiersname")).hasSize(1);
    LinkedHashSet<String> options = null;
    assertThat(e.getAttribute(ocType, options)).hasSize(1);
    assertThat(e.getAttribute(cnType, options)).hasSize(2);
    assertThat(e.getAttribute(nameType, options)).hasSize(6);
    assertThat(e.getAttribute(AttributeDescription.create(ocType, options))).hasSize(1);
    assertThat(e.getAttribute(AttributeDescription.create(cnType, options))).hasSize(2);
    assertThat(e.getAttribute(AttributeDescription.create(nameType, options))).hasSize(6);
    assertThat(e.getAttribute(uidType, options)).isEmpty();
    assertThat(e.getAttribute(mnType, options)).hasSize(1);
    assertThat(e.getAttribute(AttributeDescription.create(uidType, options))).isEmpty();
    assertThat(e.getAttribute(AttributeDescription.create(mnType, options))).hasSize(1);
    options = new LinkedHashSet<>();
    assertThat(e.getAttribute(ocType, options)).hasSize(1);
    assertThat(e.getAttribute(cnType, options)).hasSize(2);
    assertThat(e.getAttribute(nameType, options)).hasSize(6);
    assertThat(e.getAttribute(AttributeDescription.create(ocType, options))).hasSize(1);
    assertThat(e.getAttribute(AttributeDescription.create(cnType, options))).hasSize(2);
    assertThat(e.getAttribute(AttributeDescription.create(nameType, options))).hasSize(6);
    assertThat(e.getAttribute(uidType, options)).isEmpty();
    assertThat(e.getAttribute(mnType, options)).hasSize(1);
    assertThat(e.getAttribute(AttributeDescription.create(uidType, options))).isEmpty();
    assertThat(e.getAttribute(AttributeDescription.create(mnType, options))).hasSize(1);
    options.add("lang-en-US");
    assertThat(e.getAttribute(ocType, options)).isEmpty();
    assertThat(e.getAttribute(cnType, options)).hasSize(1);
    assertThat(e.getAttribute(nameType, options)).hasSize(3);
    assertThat(e.getAttribute(AttributeDescription.create(ocType, options))).isEmpty();
    assertThat(e.getAttribute(AttributeDescription.create(cnType, options))).hasSize(1);
    assertThat(e.getAttribute(AttributeDescription.create(nameType, options))).hasSize(3);
    assertThat(e.getAttribute(uidType, options)).isEmpty();
    assertThat(e.getAttribute(mnType, options)).isEmpty();
    assertThat(e.getAttribute(AttributeDescription.create(uidType, options))).isEmpty();
    assertThat(e.getAttribute(AttributeDescription.create(mnType, options))).isEmpty();
    options.add("lang-en-GB");
    assertThat(e.getAttribute(ocType, options)).isEmpty();
    assertThat(e.getAttribute(cnType, options)).isEmpty();
    assertThat(e.getAttribute(nameType, options)).isEmpty();
    assertThat(e.getAttribute(uidType, options)).isEmpty();
    assertThat(e.getAttribute(mnType, options)).isEmpty();
    assertThat(e.getAttribute(AttributeDescription.create(ocType, options))).isEmpty();
    assertThat(e.getAttribute(AttributeDescription.create(cnType, options))).isEmpty();
    assertThat(e.getAttribute(AttributeDescription.create(nameType, options))).isEmpty();
    assertThat(e.getAttribute(AttributeDescription.create(uidType, options))).isEmpty();
    assertThat(e.getAttribute(AttributeDescription.create(mnType, options))).isEmpty();
    options.clear();
    options.add("lang-en-GB");
    assertThat(e.getAttribute(ocType, options)).isEmpty();
    assertThat(e.getAttribute(cnType, options)).isEmpty();
    assertThat(e.getAttribute(nameType, options)).isEmpty();
    assertThat(e.getAttribute(uidType, options)).isEmpty();
    assertThat(e.getAttribute(mnType, options)).isEmpty();
    assertThat(e.getAttribute(AttributeDescription.create(ocType, options))).isEmpty();
    assertThat(e.getAttribute(AttributeDescription.create(cnType, options))).isEmpty();
    assertThat(e.getAttribute(AttributeDescription.create(nameType, options))).isEmpty();
    assertThat(e.getAttribute(AttributeDescription.create(uidType, options))).isEmpty();
    assertThat(e.getAttribute(AttributeDescription.create(mnType, options))).isEmpty();
  }