Search in sources :

Example 31 with ASN1Null

use of com.unboundid.asn1.ASN1Null in project ldapsdk by pingidentity.

the class DebugTestCase method testDebugASN1Write2DisabledAll.

/**
 * Tests the second {@code debugASN1Write} method with the debugger disabled
 * and a debug type set of all types.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testDebugASN1Write2DisabledAll() throws Exception {
    Debug.setEnabled(false);
    testLogHandler.resetMessageCount();
    assertFalse(Debug.debugEnabled(DebugType.ASN1));
    Debug.debugASN1Write(Level.FINEST, new ASN1Null());
    assertTrue(testLogHandler.getMessageCount() >= 0);
}
Also used : ASN1Null(com.unboundid.asn1.ASN1Null) Test(org.testng.annotations.Test)

Example 32 with ASN1Null

use of com.unboundid.asn1.ASN1Null in project ldapsdk by pingidentity.

the class DebugTestCase method testDebugASN1Write1EnabledIncludeASN1.

/**
 * Tests the first {@code debugASN1Write} method with the debugger enabled
 * and a debug type set that includes the ASN.1 type among others.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testDebugASN1Write1EnabledIncludeASN1() throws Exception {
    Debug.setEnabled(true, EnumSet.of(DebugType.ASN1, DebugType.OTHER));
    testLogHandler.resetMessageCount();
    assertTrue(Debug.debugEnabled(DebugType.ASN1));
    Debug.debugASN1Write(new ASN1Null());
    assertTrue(testLogHandler.getMessageCount() >= 1);
}
Also used : ASN1Null(com.unboundid.asn1.ASN1Null) Test(org.testng.annotations.Test)

Example 33 with ASN1Null

use of com.unboundid.asn1.ASN1Null in project ldapsdk by pingidentity.

the class DebugTestCase method testDebugASN1Read1EnabledIncludeASN1.

/**
 * Tests the first {@code debugASN1Read} method with the debugger enabled
 * and a debug type set that includes the ASN.1 type among others.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testDebugASN1Read1EnabledIncludeASN1() throws Exception {
    Debug.setEnabled(true, EnumSet.of(DebugType.ASN1, DebugType.OTHER));
    testLogHandler.resetMessageCount();
    assertTrue(Debug.debugEnabled(DebugType.ASN1));
    Debug.debugASN1Read(new ASN1Null());
    assertTrue(testLogHandler.getMessageCount() >= 1);
}
Also used : ASN1Null(com.unboundid.asn1.ASN1Null) Test(org.testng.annotations.Test)

Example 34 with ASN1Null

use of com.unboundid.asn1.ASN1Null in project ldapsdk by pingidentity.

the class DebugTestCase method testDebugASN1Read1EnabledWithoutASN1.

/**
 * Tests the first {@code debugASN1Read} method with the debugger enabled
 * and a debug type set that does not include the ASN.1 type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testDebugASN1Read1EnabledWithoutASN1() throws Exception {
    Debug.setEnabled(true, EnumSet.of(DebugType.OTHER));
    testLogHandler.resetMessageCount();
    assertFalse(Debug.debugEnabled(DebugType.ASN1));
    Debug.debugASN1Read(new ASN1Null());
    assertTrue(testLogHandler.getMessageCount() >= 0);
}
Also used : ASN1Null(com.unboundid.asn1.ASN1Null) Test(org.testng.annotations.Test)

Example 35 with ASN1Null

use of com.unboundid.asn1.ASN1Null in project ldapsdk by pingidentity.

the class GeneratePasswordExtendedRequest method encodeValue.

/**
 * Uses the provided information to generate an ASN.1 octet string that may be
 * used as the value of a generate password extended request.
 *
 * @param  passwordPolicySelectionType
 *              The password policy selection type to use.  It must not be
 *              {@code null}.
 * @param  passwordPolicyDN
 *              The password policy DN to use in conjunction with the
 *              {@link GeneratePasswordPolicySelectionType#PASSWORD_POLICY_DN}
 *              password policy selection type.  It must be non-{@code null}
 *              when used in conjunction with that policy selection type, and
 *              it must be {@code null} for all other selection types.
 * @param  targetEntryDN
 *              The target entry DN to use in conjunction with the
 *              {@link GeneratePasswordPolicySelectionType#TARGET_ENTRY_DN}
 *              password policy selection type.  It must be non-{@code null}
 *              when used in conjunction with that policy selection type, and
 *              it must be {@code null} for all other selection types.
 * @param  numberOfPasswords
 *              The number of passwords to generate.  The value must be
 *              greater than or equal to one.
 * @param  numberOfValidationAttempts
 *              The number of attempts that should be made to generate each
 *              password in an attempt to obtain a password that satisfies the
 *              associated set of password validators.  The value must be
 *              greater than or equal to zero.
 *
 * @return  An ASN.1 octet string that may be used as the value of a generate
 *          password extended request with the provided information, or
 *          {@code null} if the request uses all the default settings and no
 *          value is needed.
 */
@Nullable()
private static ASN1OctetString encodeValue(@NotNull final GeneratePasswordPolicySelectionType passwordPolicySelectionType, @Nullable final String passwordPolicyDN, @Nullable final String targetEntryDN, final int numberOfPasswords, final int numberOfValidationAttempts) {
    Validator.ensureNotNullWithMessage(passwordPolicySelectionType, "GeneratePasswordExtendedRequest.passwordPolicySelectionType must " + "not be null.");
    final List<ASN1Element> elements = new ArrayList<>(3);
    switch(passwordPolicySelectionType) {
        case DEFAULT_POLICY:
            Validator.ensureTrue((passwordPolicyDN == null), "GeneratePasswordExtendedRequest.passwordPolicyDN must be null " + "when using a password policy selection type of " + passwordPolicySelectionType + '.');
            Validator.ensureTrue((targetEntryDN == null), "GeneratePasswordExtendedRequest.targetEntryDN must be null " + "when using a password policy selection type of " + passwordPolicySelectionType + '.');
            if ((numberOfPasswords == DEFAULT_NUMBER_OF_PASSWORDS) && (numberOfValidationAttempts == DEFAULT_VALIDATION_ATTEMPTS)) {
                return null;
            }
            elements.add(new ASN1Null(passwordPolicySelectionType.getBERType()));
            break;
        case PASSWORD_POLICY_DN:
            Validator.ensureNotNullWithMessage(passwordPolicyDN, "GeneratePasswordExtendedRequest.passwordPolicyDN must not be " + "null when using a password policy selection type of " + passwordPolicySelectionType + '.');
            Validator.ensureTrue((targetEntryDN == null), "GeneratePasswordExtendedRequest.targetEntryDN must be null " + "when using a password policy selection type of " + passwordPolicySelectionType + '.');
            elements.add(new ASN1OctetString(passwordPolicySelectionType.getBERType(), passwordPolicyDN));
            break;
        case TARGET_ENTRY_DN:
            Validator.ensureTrue((passwordPolicyDN == null), "GeneratePasswordExtendedRequest.passwordPolicyDN must be null " + "when using a password policy selection type of " + passwordPolicySelectionType + '.');
            Validator.ensureNotNullWithMessage(targetEntryDN, "GeneratePasswordExtendedRequest.targetEntryDN must not be null " + "when using a password policy selection type of " + passwordPolicySelectionType + '.');
            elements.add(new ASN1OctetString(passwordPolicySelectionType.getBERType(), targetEntryDN));
            break;
    }
    if (numberOfPasswords != DEFAULT_NUMBER_OF_PASSWORDS) {
        Validator.ensureTrue((numberOfPasswords >= 1), "GeneratePasswordExtendedRequest.numberOfPasswords must be " + "greater than or equal to one.");
        elements.add(new ASN1Integer(TYPE_NUMBER_OF_PASSWORDS, numberOfPasswords));
    }
    if (numberOfValidationAttempts != DEFAULT_VALIDATION_ATTEMPTS) {
        Validator.ensureTrue((numberOfValidationAttempts >= 0), "GeneratePasswordExtendedRequest.validationAttempts must be " + "greater than or equal to zero.");
        elements.add(new ASN1Integer(TYPE_VALIDATION_ATTEMPTS, numberOfValidationAttempts));
    }
    return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) ASN1Integer(com.unboundid.asn1.ASN1Integer) ASN1Null(com.unboundid.asn1.ASN1Null) Nullable(com.unboundid.util.Nullable)

Aggregations

ASN1Null (com.unboundid.asn1.ASN1Null)69 Test (org.testng.annotations.Test)65 ASN1BitString (com.unboundid.asn1.ASN1BitString)36 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)33 DN (com.unboundid.ldap.sdk.DN)33 OID (com.unboundid.util.OID)32 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)28 ASN1ObjectIdentifier (com.unboundid.asn1.ASN1ObjectIdentifier)23 ASN1Integer (com.unboundid.asn1.ASN1Integer)21 ASN1Element (com.unboundid.asn1.ASN1Element)20 ASN1BigInteger (com.unboundid.asn1.ASN1BigInteger)15 ASN1GeneralizedTime (com.unboundid.asn1.ASN1GeneralizedTime)9 ASN1UTCTime (com.unboundid.asn1.ASN1UTCTime)6 ArrayList (java.util.ArrayList)6 ASN1Null (com.github.zhenwei.core.asn1.ASN1Null)5 Date (java.util.Date)5 ASN1ObjectIdentifier (com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)3 ASN1OctetString (com.github.zhenwei.core.asn1.ASN1OctetString)3 AlgorithmParameters (java.security.AlgorithmParameters)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3