Search in sources :

Example 1 with PasswordPolicyStateAccountUsabilityNotice

use of com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityNotice in project ldapsdk by pingidentity.

the class ResultUtils method addGetPasswordPolicyStateIssuesResponseControl.

/**
 * Adds a multi-line string representation of the provided control, which is
 * expected to be a get password policy state issues response control, to the
 * given list.
 *
 * @param  lines     The list to which the lines should be added.
 * @param  c         The control to be formatted.
 * @param  prefix    The prefix to use for each line.
 * @param  maxWidth  The maximum length of each line in characters, including
 *                   the comment prefix and indent.
 */
private static void addGetPasswordPolicyStateIssuesResponseControl(@NotNull final List<String> lines, @NotNull final Control c, @NotNull final String prefix, final int maxWidth) {
    final GetPasswordPolicyStateIssuesResponseControl decoded;
    try {
        decoded = new GetPasswordPolicyStateIssuesResponseControl(c.getOID(), c.isCritical(), c.getValue());
    } catch (final Exception e) {
        Debug.debugException(e);
        addGenericResponseControl(lines, c, prefix, maxWidth);
        return;
    }
    wrap(lines, INFO_RESULT_UTILS_GET_PW_STATE_ISSUES_HEADER.get(), prefix, maxWidth);
    final String indentPrefix = prefix + "     ";
    wrap(lines, INFO_RESULT_UTILS_RESPONSE_CONTROL_OID.get(c.getOID()), indentPrefix, maxWidth);
    final String doubleIndentPrefix = indentPrefix + "     ";
    final AuthenticationFailureReason authFailureReason = decoded.getAuthenticationFailureReason();
    if (authFailureReason != null) {
        wrap(lines, INFO_RESULT_UTILS_GET_PW_STATE_ISSUES_FAILURE_REASON_HEADER.get(), indentPrefix, maxWidth);
        wrap(lines, INFO_RESULT_UTILS_GET_PW_STATE_ISSUES_FAILURE_TYPE.get(authFailureReason.getName()), doubleIndentPrefix, maxWidth);
        final String message = authFailureReason.getMessage();
        if (message != null) {
            wrap(lines, INFO_RESULT_UTILS_GET_PW_STATE_ISSUES_FAILURE_MESSAGE.get(message), doubleIndentPrefix, maxWidth);
        }
    }
    final List<PasswordPolicyStateAccountUsabilityError> errors = decoded.getErrors();
    if (errors != null) {
        for (final PasswordPolicyStateAccountUsabilityError e : errors) {
            wrap(lines, INFO_RESULT_UTILS_GET_PW_STATE_ISSUES_ERROR_HEADER.get(), indentPrefix, maxWidth);
            wrap(lines, INFO_RESULT_UTILS_GET_PW_STATE_ISSUES_ERROR_NAME.get(e.getName()), doubleIndentPrefix, maxWidth);
            final String message = e.getMessage();
            if (message != null) {
                wrap(lines, INFO_RESULT_UTILS_GET_PW_STATE_ISSUES_ERROR_MESSAGE.get(message), doubleIndentPrefix, maxWidth);
            }
        }
    }
    final List<PasswordPolicyStateAccountUsabilityWarning> warnings = decoded.getWarnings();
    if (warnings != null) {
        for (final PasswordPolicyStateAccountUsabilityWarning w : warnings) {
            wrap(lines, INFO_RESULT_UTILS_GET_PW_STATE_ISSUES_WARNING_HEADER.get(), indentPrefix, maxWidth);
            wrap(lines, INFO_RESULT_UTILS_GET_PW_STATE_ISSUES_WARNING_NAME.get(w.getName()), doubleIndentPrefix, maxWidth);
            final String message = w.getMessage();
            if (message != null) {
                wrap(lines, INFO_RESULT_UTILS_GET_PW_STATE_ISSUES_WARNING_MESSAGE.get(message), doubleIndentPrefix, maxWidth);
            }
        }
    }
    final List<PasswordPolicyStateAccountUsabilityNotice> notices = decoded.getNotices();
    if (notices != null) {
        for (final PasswordPolicyStateAccountUsabilityNotice n : notices) {
            wrap(lines, INFO_RESULT_UTILS_GET_PW_STATE_ISSUES_NOTICE_HEADER.get(), indentPrefix, maxWidth);
            wrap(lines, INFO_RESULT_UTILS_GET_PW_STATE_ISSUES_NOTICE_NAME.get(n.getName()), doubleIndentPrefix, maxWidth);
            final String message = n.getMessage();
            if (message != null) {
                wrap(lines, INFO_RESULT_UTILS_GET_PW_STATE_ISSUES_NOTICE_MESSAGE.get(message), doubleIndentPrefix, maxWidth);
            }
        }
    }
}
Also used : AuthenticationFailureReason(com.unboundid.ldap.sdk.unboundidds.controls.AuthenticationFailureReason) PasswordPolicyStateAccountUsabilityError(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityError) PasswordPolicyStateAccountUsabilityNotice(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityNotice) PasswordPolicyStateAccountUsabilityWarning(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityWarning) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) GetPasswordPolicyStateIssuesResponseControl(com.unboundid.ldap.sdk.unboundidds.controls.GetPasswordPolicyStateIssuesResponseControl) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Example 2 with PasswordPolicyStateAccountUsabilityNotice

use of com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityNotice in project ldapsdk by pingidentity.

the class PasswordPolicyStateJSONTestCase method testAccountUsabilityIsNotUsable.

/**
 * Tests the behavior for the properties related to account usability when the
 * account is not and there are multiple usability errors, warnings, and
 * notices.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testAccountUsabilityIsNotUsable() throws Exception {
    final List<PasswordPolicyStateAccountUsabilityError> errors = Arrays.asList(new PasswordPolicyStateAccountUsabilityError(PasswordPolicyStateAccountUsabilityError.ERROR_TYPE_ACCOUNT_DISABLED, PasswordPolicyStateAccountUsabilityError.ERROR_NAME_ACCOUNT_DISABLED, null), new PasswordPolicyStateAccountUsabilityError(PasswordPolicyStateAccountUsabilityError.ERROR_TYPE_ACCOUNT_EXPIRED, PasswordPolicyStateAccountUsabilityError.ERROR_NAME_ACCOUNT_EXPIRED, "The account expired a while ago."));
    final List<PasswordPolicyStateAccountUsabilityWarning> warnings = Arrays.asList(new PasswordPolicyStateAccountUsabilityWarning(PasswordPolicyStateAccountUsabilityWarning.WARNING_TYPE_ACCOUNT_IDLE, PasswordPolicyStateAccountUsabilityWarning.WARNING_NAME_ACCOUNT_IDLE, null), new PasswordPolicyStateAccountUsabilityWarning(PasswordPolicyStateAccountUsabilityWarning.WARNING_TYPE_OUTSTANDING_BIND_FAILURES, PasswordPolicyStateAccountUsabilityWarning.WARNING_NAME_OUTSTANDING_BIND_FAILURES, "The account has outstanding bind failures."));
    final List<PasswordPolicyStateAccountUsabilityNotice> notices = Arrays.asList(new PasswordPolicyStateAccountUsabilityNotice(PasswordPolicyStateAccountUsabilityNotice.NOTICE_TYPE_NO_STATIC_PASSWORD, PasswordPolicyStateAccountUsabilityNotice.NOTICE_NAME_NO_STATIC_PASSWORD, null), new PasswordPolicyStateAccountUsabilityNotice(PasswordPolicyStateAccountUsabilityNotice.NOTICE_TYPE_IN_MINIMUM_PASSWORD_AGE, PasswordPolicyStateAccountUsabilityNotice.NOTICE_NAME_IN_MINIMUM_PASSWORD_AGE, "You can't change your password again for a while."));
    final PasswordPolicyStateJSON state = createState(StaticUtils.mapOf(ACCOUNT_IS_USABLE, false, ACCOUNT_USABILITY_ERRORS, errors, ACCOUNT_USABILITY_WARNINGS, warnings, ACCOUNT_USABILITY_NOTICES, notices));
    assertNotNull(state.getAccountIsUsable());
    assertEquals(state.getAccountIsUsable(), Boolean.FALSE);
    assertNotNull(state.getAccountUsabilityErrors());
    assertFalse(state.getAccountUsabilityErrors().isEmpty());
    assertEquals(state.getAccountUsabilityErrors().size(), 2);
    final PasswordPolicyStateAccountUsabilityError e1 = state.getAccountUsabilityErrors().get(0);
    assertEquals(e1.getIntValue(), PasswordPolicyStateAccountUsabilityError.ERROR_TYPE_ACCOUNT_DISABLED);
    assertEquals(e1.getName(), PasswordPolicyStateAccountUsabilityError.ERROR_NAME_ACCOUNT_DISABLED);
    assertNull(e1.getMessage());
    final PasswordPolicyStateAccountUsabilityError e2 = state.getAccountUsabilityErrors().get(1);
    assertEquals(e2.getIntValue(), PasswordPolicyStateAccountUsabilityError.ERROR_TYPE_ACCOUNT_EXPIRED);
    assertEquals(e2.getName(), PasswordPolicyStateAccountUsabilityError.ERROR_NAME_ACCOUNT_EXPIRED);
    assertNotNull(e2.getMessage());
    assertEquals(e2.getMessage(), "The account expired a while ago.");
    assertNotNull(state.getAccountUsabilityWarnings());
    assertFalse(state.getAccountUsabilityWarnings().isEmpty());
    assertEquals(state.getAccountUsabilityWarnings().size(), 2);
    final PasswordPolicyStateAccountUsabilityWarning w1 = state.getAccountUsabilityWarnings().get(0);
    assertEquals(w1.getIntValue(), PasswordPolicyStateAccountUsabilityWarning.WARNING_TYPE_ACCOUNT_IDLE);
    assertEquals(w1.getName(), PasswordPolicyStateAccountUsabilityWarning.WARNING_NAME_ACCOUNT_IDLE);
    assertNull(w1.getMessage());
    final PasswordPolicyStateAccountUsabilityWarning w2 = state.getAccountUsabilityWarnings().get(1);
    assertEquals(w2.getIntValue(), PasswordPolicyStateAccountUsabilityWarning.WARNING_TYPE_OUTSTANDING_BIND_FAILURES);
    assertEquals(w2.getName(), PasswordPolicyStateAccountUsabilityWarning.WARNING_NAME_OUTSTANDING_BIND_FAILURES);
    assertNotNull(w2.getMessage());
    assertEquals(w2.getMessage(), "The account has outstanding bind failures.");
    assertNotNull(state.getAccountUsabilityNotices());
    assertFalse(state.getAccountUsabilityNotices().isEmpty());
    assertEquals(state.getAccountUsabilityNotices().size(), 2);
    final PasswordPolicyStateAccountUsabilityNotice n1 = state.getAccountUsabilityNotices().get(0);
    assertEquals(n1.getIntValue(), PasswordPolicyStateAccountUsabilityNotice.NOTICE_TYPE_NO_STATIC_PASSWORD);
    assertEquals(n1.getName(), PasswordPolicyStateAccountUsabilityNotice.NOTICE_NAME_NO_STATIC_PASSWORD);
    assertNull(n1.getMessage());
    final PasswordPolicyStateAccountUsabilityNotice n2 = state.getAccountUsabilityNotices().get(1);
    assertEquals(n2.getIntValue(), PasswordPolicyStateAccountUsabilityNotice.NOTICE_TYPE_IN_MINIMUM_PASSWORD_AGE);
    assertEquals(n2.getName(), PasswordPolicyStateAccountUsabilityNotice.NOTICE_NAME_IN_MINIMUM_PASSWORD_AGE);
    assertNotNull(n2.getMessage());
    assertEquals(n2.getMessage(), "You can't change your password again for a while.");
}
Also used : PasswordPolicyStateAccountUsabilityError(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityError) PasswordPolicyStateAccountUsabilityNotice(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityNotice) PasswordPolicyStateAccountUsabilityWarning(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityWarning) Test(org.testng.annotations.Test)

Example 3 with PasswordPolicyStateAccountUsabilityNotice

use of com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityNotice in project ldapsdk by pingidentity.

the class GetPasswordPolicyStateIssuesResponseControlTestCase method testGetLDAPExceptionValidGenericControl.

/**
 * Tests the behavior of the get method for an LDAP exception that contains a
 * generic control that can be decoded as a get password policy state issues
 * response control.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGetLDAPExceptionValidGenericControl() throws Exception {
    final List<PasswordPolicyStateAccountUsabilityNotice> notices = Collections.singletonList(new PasswordPolicyStateAccountUsabilityNotice(NOTICE_TYPE_OUTSTANDING_RETIRED_PASSWORD, NOTICE_NAME_OUTSTANDING_RETIRED_PASSWORD, "The user has a retired password"));
    final List<PasswordPolicyStateAccountUsabilityWarning> warnings = Collections.emptyList();
    final List<PasswordPolicyStateAccountUsabilityError> errors = Collections.emptyList();
    final GetPasswordPolicyStateIssuesResponseControl c = new GetPasswordPolicyStateIssuesResponseControl(notices, warnings, errors);
    final Control[] controls = { new Control(c.getOID(), c.isCritical(), c.getValue()) };
    final LDAPException ldapException = new LDAPException(ResultCode.INVALID_CREDENTIALS, null, null, null, controls, null);
    assertNotNull(GetPasswordPolicyStateIssuesResponseControl.get(ldapException));
    assertEquals(GetPasswordPolicyStateIssuesResponseControl.get(ldapException), c);
}
Also used : Control(com.unboundid.ldap.sdk.Control) PasswordPolicyStateAccountUsabilityNotice(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityNotice) PasswordPolicyStateAccountUsabilityError(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityError) LDAPException(com.unboundid.ldap.sdk.LDAPException) PasswordPolicyStateAccountUsabilityWarning(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityWarning) Test(org.testng.annotations.Test)

Example 4 with PasswordPolicyStateAccountUsabilityNotice

use of com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityNotice in project ldapsdk by pingidentity.

the class GetPasswordPolicyStateIssuesResponseControlTestCase method testSingleNotice.

/**
 * Tests the behavior for a control with only a single notice and no warnings
 * or errors.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSingleNotice() throws Exception {
    final List<PasswordPolicyStateAccountUsabilityNotice> notices = Collections.singletonList(new PasswordPolicyStateAccountUsabilityNotice(NOTICE_TYPE_OUTSTANDING_RETIRED_PASSWORD, NOTICE_NAME_OUTSTANDING_RETIRED_PASSWORD, "The user has a retired password"));
    final List<PasswordPolicyStateAccountUsabilityWarning> warnings = Collections.emptyList();
    final List<PasswordPolicyStateAccountUsabilityError> errors = Collections.emptyList();
    GetPasswordPolicyStateIssuesResponseControl c = new GetPasswordPolicyStateIssuesResponseControl(notices, warnings, errors);
    c = new GetPasswordPolicyStateIssuesResponseControl().decodeControl(c.getOID(), c.isCritical(), c.getValue());
    assertNotNull(c.getOID());
    assertEquals(c.getOID(), "1.3.6.1.4.1.30221.2.5.47");
    assertFalse(c.isCritical());
    assertNotNull(c.getValue());
    assertNotNull(c.getNotices());
    assertFalse(c.getNotices().isEmpty());
    assertEquals(c.getNotices().size(), 1);
    assertEquals(c.getNotices().get(0).getIntValue(), NOTICE_TYPE_OUTSTANDING_RETIRED_PASSWORD);
    assertEquals(c.getNotices().get(0).getName(), NOTICE_NAME_OUTSTANDING_RETIRED_PASSWORD);
    assertEquals(c.getNotices().get(0).getMessage(), "The user has a retired password");
    assertNotNull(c.getWarnings());
    assertTrue(c.getWarnings().isEmpty());
    assertNotNull(c.getErrors());
    assertTrue(c.getErrors().isEmpty());
    assertNull(c.getAuthenticationFailureReason());
    assertNotNull(c.getControlName());
    assertNotNull(c.toString());
}
Also used : PasswordPolicyStateAccountUsabilityNotice(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityNotice) PasswordPolicyStateAccountUsabilityError(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityError) PasswordPolicyStateAccountUsabilityWarning(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityWarning) Test(org.testng.annotations.Test)

Example 5 with PasswordPolicyStateAccountUsabilityNotice

use of com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityNotice in project ldapsdk by pingidentity.

the class GetPasswordPolicyStateIssuesResponseControlTestCase method testGetBindResultValidGenericControl.

/**
 * Tests the behavior of the get method for a bind result that contains a
 * generic control that can be decoded as a get password policy state issues
 * response control.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGetBindResultValidGenericControl() throws Exception {
    final List<PasswordPolicyStateAccountUsabilityNotice> notices = Collections.singletonList(new PasswordPolicyStateAccountUsabilityNotice(NOTICE_TYPE_OUTSTANDING_RETIRED_PASSWORD, NOTICE_NAME_OUTSTANDING_RETIRED_PASSWORD, "The user has a retired password"));
    final List<PasswordPolicyStateAccountUsabilityWarning> warnings = Collections.emptyList();
    final List<PasswordPolicyStateAccountUsabilityError> errors = Collections.emptyList();
    final GetPasswordPolicyStateIssuesResponseControl c = new GetPasswordPolicyStateIssuesResponseControl(notices, warnings, errors);
    final Control[] controls = { new Control(c.getOID(), c.isCritical(), c.getValue()) };
    final BindResult bindResult = new BindResult(1, ResultCode.SUCCESS, null, null, null, controls);
    assertNotNull(GetPasswordPolicyStateIssuesResponseControl.get(bindResult));
    assertEquals(GetPasswordPolicyStateIssuesResponseControl.get(bindResult), c);
}
Also used : Control(com.unboundid.ldap.sdk.Control) PasswordPolicyStateAccountUsabilityNotice(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityNotice) PasswordPolicyStateAccountUsabilityError(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityError) PasswordPolicyStateAccountUsabilityWarning(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityWarning) BindResult(com.unboundid.ldap.sdk.BindResult) Test(org.testng.annotations.Test)

Aggregations

PasswordPolicyStateAccountUsabilityNotice (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityNotice)16 PasswordPolicyStateAccountUsabilityError (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityError)15 PasswordPolicyStateAccountUsabilityWarning (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityWarning)15 Test (org.testng.annotations.Test)10 Control (com.unboundid.ldap.sdk.Control)5 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)4 LDAPException (com.unboundid.ldap.sdk.LDAPException)4 AuthenticationFailureReason (com.unboundid.ldap.sdk.unboundidds.controls.AuthenticationFailureReason)4 ArrayList (java.util.ArrayList)4 NotNull (com.unboundid.util.NotNull)3 BindResult (com.unboundid.ldap.sdk.BindResult)2 Entry (com.unboundid.ldap.sdk.Entry)2 PasswordPolicyStateExtendedResult (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateExtendedResult)2 PasswordPolicyStateOperation (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateOperation)2 JSONObject (com.unboundid.util.json.JSONObject)2 JSONString (com.unboundid.util.json.JSONString)2 JSONValue (com.unboundid.util.json.JSONValue)2 LinkedHashMap (java.util.LinkedHashMap)2 ASN1Element (com.unboundid.asn1.ASN1Element)1 ASN1Integer (com.unboundid.asn1.ASN1Integer)1