use of com.unboundid.util.json.JSONField 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.JSONField 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.JSONField 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());
}
use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class PasswordPolicyStateJSONTestCase method testSASLAuthentication.
/**
* Tests the behavior for the properties related to SASL authentication.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSASLAuthentication() throws Exception {
List<String> availableSASLMechanisms = Arrays.asList("PLAIN", "UNBOUNDID-TOTP");
PasswordPolicyStateJSON state = createState(StaticUtils.mapOf(AVAILABLE_SASL_MECHANISMS, availableSASLMechanisms, HAS_TOTP_SHARED_SECRET, true, HAS_REGISTERED_YUBIKEY_OTP_DEVICE, false));
assertNotNull(state.getAvailableSASLMechanisms());
assertFalse(state.getAvailableSASLMechanisms().isEmpty());
assertEquals(state.getAvailableSASLMechanisms(), availableSASLMechanisms);
assertNotNull(state.getAvailableOTPDeliveryMechanisms());
assertTrue(state.getAvailableOTPDeliveryMechanisms().isEmpty());
assertNotNull(state.getHasTOTPSharedSecret());
assertTrue(state.getHasTOTPSharedSecret().booleanValue());
assertNotNull(state.getHasRegisteredYubiKeyOTPDevice());
assertFalse(state.getHasRegisteredYubiKeyOTPDevice());
availableSASLMechanisms = Arrays.asList("PLAIN", "UNBOUNDID-DELIVERED-OTP");
final List<String> availableOTPDeliveryMechanisms = Arrays.asList("SMS", "E-Mail");
state = createState(StaticUtils.mapOf(AVAILABLE_SASL_MECHANISMS, availableSASLMechanisms, AVAILABLE_OTP_DELIVERY_MECHANISMS, availableOTPDeliveryMechanisms, HAS_TOTP_SHARED_SECRET, false, HAS_REGISTERED_YUBIKEY_OTP_DEVICE, false));
assertNotNull(state.getAvailableSASLMechanisms());
assertFalse(state.getAvailableSASLMechanisms().isEmpty());
assertEquals(state.getAvailableSASLMechanisms(), availableSASLMechanisms);
assertNotNull(state.getAvailableOTPDeliveryMechanisms());
assertFalse(state.getAvailableOTPDeliveryMechanisms().isEmpty());
assertEquals(state.getAvailableOTPDeliveryMechanisms(), availableOTPDeliveryMechanisms);
assertNotNull(state.getHasTOTPSharedSecret());
assertFalse(state.getHasTOTPSharedSecret().booleanValue());
assertNotNull(state.getHasRegisteredYubiKeyOTPDevice());
assertFalse(state.getHasRegisteredYubiKeyOTPDevice());
availableSASLMechanisms = Arrays.asList("PLAIN", "UNBOUNDID-YUBIKEY-OTP");
state = createState(StaticUtils.mapOf(AVAILABLE_SASL_MECHANISMS, availableSASLMechanisms, HAS_TOTP_SHARED_SECRET, false, HAS_REGISTERED_YUBIKEY_OTP_DEVICE, true));
assertNotNull(state.getAvailableSASLMechanisms());
assertFalse(state.getAvailableSASLMechanisms().isEmpty());
assertEquals(state.getAvailableSASLMechanisms(), availableSASLMechanisms);
assertNotNull(state.getAvailableOTPDeliveryMechanisms());
assertTrue(state.getAvailableOTPDeliveryMechanisms().isEmpty());
assertNotNull(state.getHasTOTPSharedSecret());
assertFalse(state.getHasTOTPSharedSecret().booleanValue());
assertNotNull(state.getHasRegisteredYubiKeyOTPDevice());
assertTrue(state.getHasRegisteredYubiKeyOTPDevice());
final JSONObject o = new JSONObject(new JSONField(AVAILABLE_SASL_MECHANISMS.getFieldName(), new JSONArray(new JSONNumber(1234))), new JSONField(AVAILABLE_OTP_DELIVERY_MECHANISMS.getFieldName(), new JSONArray(new JSONNumber(5678))));
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.getAvailableSASLMechanisms());
assertTrue(state.getAvailableSASLMechanisms().isEmpty());
assertNotNull(state.getAvailableOTPDeliveryMechanisms());
assertTrue(state.getAvailableOTPDeliveryMechanisms().isEmpty());
assertNull(state.getHasTOTPSharedSecret());
assertNull(state.getHasRegisteredYubiKeyOTPDevice());
}
use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class PasswordPolicyStateJSONTestCase method testGetPasswordQualityRequirementsPropertyMissingName.
/**
* Tests the behavior when trying to retrieve password quality requirements
* when the properties array has an object without a name.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testGetPasswordQualityRequirementsPropertyMissingName() throws Exception {
final PasswordPolicyStateJSON state = createState(StaticUtils.mapOf(PASSWORD_QUALITY_REQUIREMENTS, new JSONArray(new JSONObject(new JSONField("description", "description"), new JSONField("client-side-validation-type", "type"), new JSONField("client-side-validation-properties", new JSONArray(new JSONObject(new JSONField("value", "foo")))), new JSONField("applies-to-add", true)))));
assertNotNull(state.getAddPasswordQualityRequirements());
assertFalse(state.getAddPasswordQualityRequirements().isEmpty());
assertEquals(state.getAddPasswordQualityRequirements().size(), 1);
final PasswordQualityRequirement r = state.getAddPasswordQualityRequirements().get(0);
assertEquals(r.getDescription(), "description");
assertEquals(r.getClientSideValidationType(), "type");
assertNotNull(r.getClientSideValidationProperties());
assertTrue(r.getClientSideValidationProperties().isEmpty());
}
Aggregations