use of com.unboundid.util.json.JSONArray in project ldapsdk by pingidentity.
the class ScrambleAttributeTransformation method scrambleObjectsInArray.
/**
* Creates a new JSON array that will have all the same elements as the
* provided array except that any values in the array that are JSON objects
* (including objects contained in nested arrays) will have any appropriate
* scrambling performed.
*
* @param a The JSON array for which to scramble any values.
*
* @return The array with any appropriate scrambling performed.
*/
@NotNull()
private JSONArray scrambleObjectsInArray(@NotNull final JSONArray a) {
final List<JSONValue> originalValues = a.getValues();
final ArrayList<JSONValue> scrambledValues = new ArrayList<>(originalValues.size());
for (final JSONValue arrayValue : originalValues) {
if (arrayValue instanceof JSONArray) {
scrambledValues.add(scrambleObjectsInArray((JSONArray) arrayValue));
} else if (arrayValue instanceof JSONObject) {
scrambledValues.add(scrambleJSONValue(arrayValue, false));
} else {
scrambledValues.add(arrayValue);
}
}
return new JSONArray(scrambledValues);
}
use of com.unboundid.util.json.JSONArray in project ldapsdk by pingidentity.
the class PasswordPolicyStateJSONTestCase method testFailureLockout.
/**
* Tests the behavior for the properties related to failure lockout.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testFailureLockout() throws Exception {
final Date currentDate = new Date();
final Date tenSecondsAgo = new Date(currentDate.getTime() - 10_000L);
final Date fiveSecondsAgo = new Date(currentDate.getTime() - 5_000);
List<Date> failureTimes = Arrays.asList(tenSecondsAgo, fiveSecondsAgo);
final int tenMinutesInSeconds = (int) TimeUnit.MINUTES.toSeconds(10L);
PasswordPolicyStateJSON state = createState(StaticUtils.mapOf(ACCOUNT_IS_FAILURE_LOCKED, false, FAILURE_LOCKOUT_COUNT, 5, CURRENT_AUTHENTICATION_FAILURE_COUNT, 2, REMAINING_AUTHENTICATION_FAILURE_COUNT, 3, AUTHENTICATION_FAILURE_TIMES, failureTimes, FAILURE_LOCKOUT_DURATION_SECONDS, tenMinutesInSeconds));
assertNotNull(state.getAccountIsFailureLocked());
assertEquals(state.getAccountIsFailureLocked().booleanValue(), false);
assertNotNull(state.getFailureLockoutCount());
assertEquals(state.getFailureLockoutCount().intValue(), 5);
assertNotNull(state.getCurrentAuthenticationFailureCount());
assertEquals(state.getCurrentAuthenticationFailureCount().intValue(), 2);
assertNotNull(state.getRemainingAuthenticationFailureCount());
assertEquals(state.getRemainingAuthenticationFailureCount().intValue(), 3);
assertNotNull(state.getAuthenticationFailureTimes());
assertEquals(state.getAuthenticationFailureTimes(), failureTimes);
assertNull(state.getFailureLockoutTime());
assertNotNull(state.getFailureLockoutDurationSeconds());
assertEquals(state.getFailureLockoutDurationSeconds().intValue(), tenMinutesInSeconds);
assertNull(state.getFailureLockoutExpirationTime());
assertNull(state.getSecondsRemainingInFailureLockout());
final Date twentyFiveSecondsAgo = new Date(currentDate.getTime() - 25_000L);
final Date twentySecondsAgo = new Date(currentDate.getTime() - 20_000L);
final Date fifteenSecondsAgo = new Date(currentDate.getTime() - 15_000L);
final int tenMinutesMinusFiveSecondsInSeconds = tenMinutesInSeconds - 5;
final Date tenMinutesFromNowMinusFiveSeconds = new Date(currentDate.getTime() + (tenMinutesMinusFiveSecondsInSeconds * 1000L));
failureTimes = Arrays.asList(twentyFiveSecondsAgo, twentySecondsAgo, fifteenSecondsAgo, tenSecondsAgo, fiveSecondsAgo);
state = createState(StaticUtils.mapOf(ACCOUNT_IS_FAILURE_LOCKED, true, FAILURE_LOCKOUT_COUNT, 5, CURRENT_AUTHENTICATION_FAILURE_COUNT, 5, REMAINING_AUTHENTICATION_FAILURE_COUNT, 0, AUTHENTICATION_FAILURE_TIMES, failureTimes, FAILURE_LOCKOUT_TIME, fiveSecondsAgo, FAILURE_LOCKOUT_DURATION_SECONDS, tenMinutesInSeconds, FAILURE_LOCKOUT_EXPIRATION_TIME, tenMinutesFromNowMinusFiveSeconds, SECONDS_REMAINING_IN_FAILURE_LOCKOUT, tenMinutesMinusFiveSecondsInSeconds));
assertNotNull(state.getAccountIsFailureLocked());
assertEquals(state.getAccountIsFailureLocked().booleanValue(), true);
assertNotNull(state.getFailureLockoutCount());
assertEquals(state.getFailureLockoutCount().intValue(), 5);
assertNotNull(state.getCurrentAuthenticationFailureCount());
assertEquals(state.getCurrentAuthenticationFailureCount().intValue(), 5);
assertNotNull(state.getRemainingAuthenticationFailureCount());
assertEquals(state.getRemainingAuthenticationFailureCount().intValue(), 0);
assertNotNull(state.getAuthenticationFailureTimes());
assertEquals(state.getAuthenticationFailureTimes(), failureTimes);
assertNotNull(state.getFailureLockoutTime());
assertEquals(state.getFailureLockoutTime(), fiveSecondsAgo);
assertNotNull(state.getFailureLockoutDurationSeconds());
assertEquals(state.getFailureLockoutDurationSeconds().intValue(), tenMinutesInSeconds);
assertNotNull(state.getFailureLockoutExpirationTime());
assertEquals(state.getFailureLockoutExpirationTime(), tenMinutesFromNowMinusFiveSeconds);
assertNotNull(state.getSecondsRemainingInFailureLockout());
assertEquals(state.getSecondsRemainingInFailureLockout().intValue(), tenMinutesMinusFiveSecondsInSeconds);
final JSONObject o = new JSONObject(new JSONField(AUTHENTICATION_FAILURE_TIMES.getFieldName(), new JSONArray(new JSONString("malformed-timestamp"))));
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());
state = PasswordPolicyStateJSON.get(entry);
assertNotNull(state);
assertNotNull(state.getAuthenticationFailureTimes());
assertTrue(state.getAuthenticationFailureTimes().isEmpty());
}
use of com.unboundid.util.json.JSONArray in project ldapsdk by pingidentity.
the class PasswordPolicyStateJSONTestCase method testGetPasswordQualityRequirementsObjectMissingDescription.
/**
* Tests the behavior when trying to retrieve password quality requirements
* when the array contains an object that is missing the required description
* field.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testGetPasswordQualityRequirementsObjectMissingDescription() throws Exception {
final PasswordPolicyStateJSON state = createState(StaticUtils.mapOf(PASSWORD_QUALITY_REQUIREMENTS, new JSONArray(new JSONObject(new JSONField("client-side-validation-type", "type"), new JSONField("applies-to-add", true)))));
assertNotNull(state.getAddPasswordQualityRequirements());
assertTrue(state.getAddPasswordQualityRequirements().isEmpty());
}
use of com.unboundid.util.json.JSONArray in project ldapsdk by pingidentity.
the class PasswordPolicyStateJSONTestCase method testGetSelfChangePasswordQualityRequirements.
/**
* Tests the behavior for the properties related to password quality
* requirements for self password changes.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testGetSelfChangePasswordQualityRequirements() throws Exception {
final PasswordQualityRequirement allRequirement = new PasswordQualityRequirement("all-requirement-description", "all-requirement-type", Collections.<String, String>emptyMap());
final PasswordQualityRequirement noneRequirement = new PasswordQualityRequirement("none-requirement-description", "none-requirement-type", Collections.<String, String>emptyMap());
final PasswordQualityRequirement addRequirement = new PasswordQualityRequirement("add-requirement-description", "add-requirement-type", Collections.singletonMap("property-1", "value-1"));
final PasswordQualityRequirement selfChangeRequirement = new PasswordQualityRequirement("self-change-requirement-description", "self-change-requirement-type", StaticUtils.mapOf("property-1", "value-1", "property-2", "value-2"));
final PasswordQualityRequirement adminResetRequirement = new PasswordQualityRequirement("admin-reset-requirement-description", "admin-reset-requirement-type", StaticUtils.mapOf("property-1", "value-1", "property-2", "value-2", "property-3", "value-3"));
final PasswordQualityRequirement bindRequirement = new PasswordQualityRequirement("bind-requirement-description", null, null);
final JSONArray requirementsArray = new JSONArray(encodeRequirement(allRequirement, true, true, true, true), encodeRequirement(noneRequirement, false, false, false, false), encodeRequirement(addRequirement, true, false, false, false), encodeRequirement(selfChangeRequirement, false, true, false, false), encodeRequirement(adminResetRequirement, false, false, true, false), encodeRequirement(bindRequirement, false, false, false, true));
final PasswordPolicyStateJSON state = createState(StaticUtils.mapOf(PASSWORD_QUALITY_REQUIREMENTS, requirementsArray));
assertNotNull(state.getSelfChangePasswordQualityRequirements());
assertFalse(state.getSelfChangePasswordQualityRequirements().isEmpty());
assertEquals(state.getSelfChangePasswordQualityRequirements().size(), 2);
final PasswordQualityRequirement requirement0 = state.getSelfChangePasswordQualityRequirements().get(0);
assertEquals(requirement0.getDescription(), allRequirement.getDescription());
assertEquals(requirement0.getClientSideValidationType(), allRequirement.getClientSideValidationType());
assertEquals(requirement0.getClientSideValidationProperties(), allRequirement.getClientSideValidationProperties());
final PasswordQualityRequirement requirement1 = state.getSelfChangePasswordQualityRequirements().get(1);
assertEquals(requirement1.getDescription(), selfChangeRequirement.getDescription());
assertEquals(requirement1.getClientSideValidationType(), selfChangeRequirement.getClientSideValidationType());
assertEquals(requirement1.getClientSideValidationProperties(), selfChangeRequirement.getClientSideValidationProperties());
}
use of com.unboundid.util.json.JSONArray in project ldapsdk by pingidentity.
the class PasswordPolicyStateJSONTestCase method testEmptyAccountUsabilityObjects.
/**
* Tests the behavior for the properties related to account usability when the
* errors, warnings, and notices are all empty objects.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testEmptyAccountUsabilityObjects() throws Exception {
final JSONObject o = new JSONObject(new JSONField(ACCOUNT_USABILITY_ERRORS.getFieldName(), new JSONArray(JSONObject.EMPTY_OBJECT)), new JSONField(ACCOUNT_USABILITY_WARNINGS.getFieldName(), new JSONArray(JSONObject.EMPTY_OBJECT)), new JSONField(ACCOUNT_USABILITY_NOTICES.getFieldName(), new JSONArray(JSONObject.EMPTY_OBJECT)));
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.getAccountUsabilityErrors());
assertTrue(state.getAccountUsabilityErrors().isEmpty());
assertNotNull(state.getAccountUsabilityWarnings());
assertTrue(state.getAccountUsabilityWarnings().isEmpty());
assertNotNull(state.getAccountUsabilityNotices());
assertTrue(state.getAccountUsabilityNotices().isEmpty());
}
Aggregations