Search in sources :

Example 6 with PasswordPolicyStateAccountUsabilityWarning

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

the class GetPasswordPolicyStateIssuesResponseControlTestCase method testGetLDAPExceptionPreDecodedControl.

/**
 * Tests the behavior of the get method for an LDAP exception that contains a
 * control that is already the correct type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGetLDAPExceptionPreDecodedControl() 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 = { c };
    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 7 with PasswordPolicyStateAccountUsabilityWarning

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

the class GetPasswordPolicyStateIssuesResponseControlTestCase method testGetBindResultPreDecodedControl.

/**
 * Tests the behavior of the get method for a bind result that contains a
 * control that is already the correct type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGetBindResultPreDecodedControl() 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 = { c };
    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)

Example 8 with PasswordPolicyStateAccountUsabilityWarning

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

the class PasswordPolicyStateJSONTestCase method createState.

/**
 * Creates a password policy state JSON object with the provided fields.
 *
 * @param  fields  The fields to include in the JSON object.
 *
 * @return  The password policy state JSON object that was created.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
private PasswordPolicyStateJSON createState(final Map<PasswordPolicyStateJSONField, ?> fields) throws Exception {
    final Map<String, JSONValue> jsonFields = new LinkedHashMap<>();
    for (final PasswordPolicyStateJSONField field : fields.keySet()) {
        final String name = field.getFieldName();
        final Object value = fields.get(field);
        if (value instanceof Boolean) {
            final Boolean b = (Boolean) value;
            jsonFields.put(name, new JSONBoolean(b));
        } else if (value instanceof Integer) {
            final Integer i = (Integer) value;
            jsonFields.put(name, new JSONNumber(i));
        } else if (value instanceof String) {
            final String s = (String) value;
            jsonFields.put(name, new JSONString(s));
        } else if (value instanceof Date) {
            final Date d = (Date) value;
            jsonFields.put(name, new JSONString(StaticUtils.encodeRFC3339Time(d)));
        } else if (value instanceof List) {
            final List<?> l = (List<?>) value;
            final List<JSONValue> arrayValues = new ArrayList<>();
            for (final Object o : l) {
                if (o instanceof Date) {
                    final Date d = (Date) o;
                    arrayValues.add(new JSONString(StaticUtils.encodeRFC3339Time(d)));
                } else if (o instanceof String) {
                    final String s = (String) o;
                    arrayValues.add(new JSONString(s));
                } else if (o instanceof PasswordPolicyStateAccountUsabilityError) {
                    final PasswordPolicyStateAccountUsabilityError e = (PasswordPolicyStateAccountUsabilityError) o;
                    if (e.getMessage() == null) {
                        arrayValues.add(new JSONObject(new JSONField("type-name", e.getName()), new JSONField("type-id", e.getIntValue())));
                    } else {
                        arrayValues.add(new JSONObject(new JSONField("type-name", e.getName()), new JSONField("type-id", e.getIntValue()), new JSONField("message", e.getMessage())));
                    }
                } else if (o instanceof PasswordPolicyStateAccountUsabilityWarning) {
                    final PasswordPolicyStateAccountUsabilityWarning w = (PasswordPolicyStateAccountUsabilityWarning) o;
                    if (w.getMessage() == null) {
                        arrayValues.add(new JSONObject(new JSONField("type-name", w.getName()), new JSONField("type-id", w.getIntValue())));
                    } else {
                        arrayValues.add(new JSONObject(new JSONField("type-name", w.getName()), new JSONField("type-id", w.getIntValue()), new JSONField("message", w.getMessage())));
                    }
                } else if (o instanceof PasswordPolicyStateAccountUsabilityNotice) {
                    final PasswordPolicyStateAccountUsabilityNotice n = (PasswordPolicyStateAccountUsabilityNotice) o;
                    if (n.getMessage() == null) {
                        arrayValues.add(new JSONObject(new JSONField("type-name", n.getName()), new JSONField("type-id", n.getIntValue())));
                    } else {
                        arrayValues.add(new JSONObject(new JSONField("type-name", n.getName()), new JSONField("type-id", n.getIntValue()), new JSONField("message", n.getMessage())));
                    }
                } else {
                    fail("Unexpected list element " + o + " of type " + o.getClass().getName());
                }
            }
            jsonFields.put(name, new JSONArray(arrayValues));
        } else if (value instanceof JSONValue) {
            jsonFields.put(name, (JSONValue) value);
        } else {
            fail("Unexpected field value " + value + " of type " + value.getClass().getName());
        }
    }
    final JSONObject o = new JSONObject(jsonFields);
    final Entry entry = new Entry("dn: uid=test.user,ou=People,dc=example,dc=com", "objectClass: top", "objectClass: person", "objectClass: organizationalPerson", "objectClass: inetOrgPerson", "uid: test.user", "givenName: Test", "sn: User", "cn: Test User");
    entry.addAttribute("ds-pwp-state-json", o.toSingleLineString());
    final PasswordPolicyStateJSON state = PasswordPolicyStateJSON.get(entry);
    assertNotNull(state);
    assertNotNull(state.getPasswordPolicyStateJSONObject());
    assertFalse(state.getPasswordPolicyStateJSONObject().getFields().isEmpty());
    assertEquals(state.getPasswordPolicyStateJSONObject().getFields().size(), jsonFields.size());
    assertNotNull(state.toString());
    assertFalse(state.toString().isEmpty());
    return state;
}
Also used : PasswordPolicyStateAccountUsabilityError(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityError) ArrayList(java.util.ArrayList) JSONArray(com.unboundid.util.json.JSONArray) PasswordPolicyStateJSONField(com.unboundid.ldap.sdk.unboundidds.PasswordPolicyStateJSONField) JSONField(com.unboundid.util.json.JSONField) JSONString(com.unboundid.util.json.JSONString) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) JSONValue(com.unboundid.util.json.JSONValue) Entry(com.unboundid.ldap.sdk.Entry) PasswordPolicyStateAccountUsabilityNotice(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityNotice) PasswordPolicyStateJSONField(com.unboundid.ldap.sdk.unboundidds.PasswordPolicyStateJSONField) JSONObject(com.unboundid.util.json.JSONObject) JSONBoolean(com.unboundid.util.json.JSONBoolean) PasswordPolicyStateAccountUsabilityWarning(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityWarning) JSONObject(com.unboundid.util.json.JSONObject) JSONNumber(com.unboundid.util.json.JSONNumber) ArrayList(java.util.ArrayList) List(java.util.List) JSONBoolean(com.unboundid.util.json.JSONBoolean) JSONString(com.unboundid.util.json.JSONString)

Example 9 with PasswordPolicyStateAccountUsabilityWarning

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

the class GetPasswordPolicyStateIssuesResponseControlTestCase method testAllTypes.

/**
 * Tests the behavior for a control with multiple notices, warnings, and
 * errors.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testAllTypes() throws Exception {
    final List<PasswordPolicyStateAccountUsabilityNotice> notices = Arrays.asList(new PasswordPolicyStateAccountUsabilityNotice(NOTICE_TYPE_OUTSTANDING_ONE_TIME_PASSWORD, NOTICE_NAME_OUTSTANDING_ONE_TIME_PASSWORD, "The user has an outstanding one-time password"), new PasswordPolicyStateAccountUsabilityNotice(NOTICE_TYPE_IN_MINIMUM_PASSWORD_AGE, NOTICE_NAME_IN_MINIMUM_PASSWORD_AGE, null));
    final List<PasswordPolicyStateAccountUsabilityWarning> warnings = Arrays.asList(new PasswordPolicyStateAccountUsabilityWarning(WARNING_TYPE_PASSWORD_EXPIRING, WARNING_NAME_PASSWORD_EXPIRING, "The password is about to expire"), new PasswordPolicyStateAccountUsabilityWarning(WARNING_TYPE_ACCOUNT_IDLE, WARNING_NAME_ACCOUNT_IDLE, null));
    final List<PasswordPolicyStateAccountUsabilityError> errors = Arrays.asList(new PasswordPolicyStateAccountUsabilityError(ERROR_TYPE_ACCOUNT_NOT_YET_ACTIVE, ERROR_NAME_ACCOUNT_NOT_YET_ACTIVE, "The account is not yet active"), new PasswordPolicyStateAccountUsabilityError(ERROR_TYPE_ACCOUNT_DISABLED, ERROR_NAME_ACCOUNT_DISABLED, null));
    final AuthenticationFailureReason authFailureReason = new AuthenticationFailureReason(FAILURE_TYPE_LOCKDOWN_MODE, FAILURE_NAME_LOCKDOWN_MODE, null);
    GetPasswordPolicyStateIssuesResponseControl c = new GetPasswordPolicyStateIssuesResponseControl(notices, warnings, errors, authFailureReason);
    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(), 2);
    assertNotNull(c.getWarnings());
    assertFalse(c.getWarnings().isEmpty());
    assertEquals(c.getWarnings().size(), 2);
    assertNotNull(c.getErrors());
    assertFalse(c.getErrors().isEmpty());
    assertEquals(c.getErrors().size(), 2);
    assertNotNull(c.getAuthenticationFailureReason());
    assertEquals(c.getAuthenticationFailureReason().getIntValue(), FAILURE_TYPE_LOCKDOWN_MODE);
    assertEquals(c.getAuthenticationFailureReason().getName(), FAILURE_NAME_LOCKDOWN_MODE);
    assertNull(c.getAuthenticationFailureReason().getMessage());
    assertNotNull(c.getControlName());
    assertNotNull(c.toString());
}
Also used : AuthenticationFailureReason(com.unboundid.ldap.sdk.unboundidds.controls.AuthenticationFailureReason) 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 10 with PasswordPolicyStateAccountUsabilityWarning

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

the class GetPasswordPolicyStateIssuesResponseControlTestCase method testSingleError.

/**
 * Tests the behavior for a control with only a single error and no notices
 * or warnings.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSingleError() throws Exception {
    final List<PasswordPolicyStateAccountUsabilityNotice> notices = Collections.emptyList();
    final List<PasswordPolicyStateAccountUsabilityWarning> warnings = Collections.emptyList();
    final List<PasswordPolicyStateAccountUsabilityError> errors = Collections.singletonList(new PasswordPolicyStateAccountUsabilityError(ERROR_TYPE_ACCOUNT_DISABLED, ERROR_NAME_ACCOUNT_DISABLED, "The account is disabled"));
    final AuthenticationFailureReason authFailureReason = new AuthenticationFailureReason(FAILURE_TYPE_ACCOUNT_NOT_USABLE, FAILURE_NAME_ACCOUNT_NOT_USABLE, "The account is not usable because it is disabled");
    GetPasswordPolicyStateIssuesResponseControl c = new GetPasswordPolicyStateIssuesResponseControl(notices, warnings, errors, authFailureReason);
    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());
    assertTrue(c.getNotices().isEmpty());
    assertNotNull(c.getWarnings());
    assertTrue(c.getWarnings().isEmpty());
    assertNotNull(c.getErrors());
    assertFalse(c.getErrors().isEmpty());
    assertEquals(c.getErrors().size(), 1);
    assertEquals(c.getErrors().get(0).getIntValue(), ERROR_TYPE_ACCOUNT_DISABLED);
    assertEquals(c.getErrors().get(0).getName(), ERROR_NAME_ACCOUNT_DISABLED);
    assertEquals(c.getErrors().get(0).getMessage(), "The account is disabled");
    assertNotNull(c.getAuthenticationFailureReason());
    assertEquals(c.getAuthenticationFailureReason().getIntValue(), FAILURE_TYPE_ACCOUNT_NOT_USABLE);
    assertEquals(c.getAuthenticationFailureReason().getName(), FAILURE_NAME_ACCOUNT_NOT_USABLE);
    assertEquals(c.getAuthenticationFailureReason().getMessage(), "The account is not usable because it is disabled");
    assertNotNull(c.getControlName());
    assertNotNull(c.toString());
}
Also used : AuthenticationFailureReason(com.unboundid.ldap.sdk.unboundidds.controls.AuthenticationFailureReason) 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)

Aggregations

PasswordPolicyStateAccountUsabilityWarning (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityWarning)16 PasswordPolicyStateAccountUsabilityError (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityError)15 PasswordPolicyStateAccountUsabilityNotice (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityNotice)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