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

Jean-Noël Rouvignac
20.42.2016 61b9eb1be03fc03a9f4bb0013a08ff44a1059503
opendj-server-legacy/src/test/java/org/opends/server/api/AuthenticationPolicyTestCase.java
@@ -20,31 +20,24 @@
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.BindOperation;
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
 * Test authentication policy interaction.
 */
/** Test authentication policy interaction. */
public class AuthenticationPolicyTestCase extends APITestCase
{
  /**
   * A mock policy which records which methods have been called and their
   * parameters.
   */
  /** A mock policy which records which methods have been called and their parameters. */
  private final class MockPolicy extends AuthenticationPolicy
  {
    private final boolean isDisabled;
@@ -53,7 +46,6 @@
    private boolean isStateFinalized;
    private ByteString matchedPassword;
    /**
     * Returns {@code true} if {@code finalizeAuthenticationPolicy} was called.
     *
@@ -64,8 +56,6 @@
      return isPolicyFinalized;
    }
    /**
     * Returns {@code true} if {@code finalizeStateAfterBind} was called.
     *
@@ -76,8 +66,6 @@
      return isStateFinalized;
    }
    /**
     * Returns the password which was tested.
     *
@@ -88,8 +76,6 @@
      return matchedPassword;
    }
    /**
     * Creates a new mock policy.
     *
@@ -104,24 +90,20 @@
      this.isDisabled = isDisabled;
    }
    /** {@inheritDoc} */
    @Override
    public DN getDN()
    {
      return policyDN;
    }
    /** {@inheritDoc} */
    @Override
    public AuthenticationPolicyState createAuthenticationPolicyState(
        Entry userEntry, long time) throws DirectoryException
    {
      return new AuthenticationPolicyState(userEntry)
      {
        /** {@inheritDoc} */
        @Override
        public boolean passwordMatches(ByteString password)
            throws DirectoryException
        {
@@ -129,25 +111,19 @@
          return matches;
        }
        /** {@inheritDoc} */
        @Override
        public boolean isDisabled()
        {
          return MockPolicy.this.isDisabled;
        }
        /** {@inheritDoc} */
        @Override
        public void finalizeStateAfterBind() throws DirectoryException
        {
          isStateFinalized = true;
        }
        /** {@inheritDoc} */
        @Override
        public AuthenticationPolicy getAuthenticationPolicy()
        {
          return MockPolicy.this;
@@ -155,24 +131,17 @@
      };
    }
    /** {@inheritDoc} */
    @Override
    public void finalizeAuthenticationPolicy()
    {
      isPolicyFinalized = true;
    }
  }
  private final String policyDNString = "cn=test policy,o=test";
  private final String userDNString = "cn=test user,o=test";
  private DN policyDN;
  /**
   * Ensures that the Directory Server is running and creates a test backend
   * containing a single test user.
@@ -188,8 +157,6 @@
    policyDN = DN.valueOf(policyDNString);
  }
  /**
   * Returns test data for the simple/sasl tests.
   *
@@ -209,8 +176,6 @@
    // @formatter:on
  }
  /**
   * Test simple authentication where password validation succeeds.
   *
@@ -232,9 +197,7 @@
      // Create an empty test backend 'o=test'
      TestCaseUtils.initializeTestBackend(true);
      /*
       * The test user which who will be authenticated.
       */
      /* The test user which who will be authenticated. */
      TestCaseUtils.addEntries(
          /* @formatter:off */
          "dn: " + userDNString,
@@ -279,8 +242,6 @@
    }
  }
  /**
   * Test simple authentication where password validation succeeds.
   *
@@ -302,9 +263,7 @@
      // Create an empty test backend 'o=test'
      TestCaseUtils.initializeTestBackend(true);
      /*
       * The test user which who will be authenticated.
       */
      /* The test user which who will be authenticated. */
      TestCaseUtils.addEntries(
          /* @formatter:off */
          "dn: " + userDNString,
@@ -356,5 +315,4 @@
      assertTrue(policy.isPolicyFinalized());
    }
  }
}