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);
}
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);
}
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;
}
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());
}
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());
}
Aggregations