Search in sources :

Example 31 with JSONField

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());
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) PasswordPolicyStateJSONField(com.unboundid.ldap.sdk.unboundidds.PasswordPolicyStateJSONField) JSONField(com.unboundid.util.json.JSONField) Date(java.util.Date) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Example 32 with JSONField

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());
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) PasswordPolicyStateJSONField(com.unboundid.ldap.sdk.unboundidds.PasswordPolicyStateJSONField) JSONField(com.unboundid.util.json.JSONField) Test(org.testng.annotations.Test)

Example 33 with JSONField

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());
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) PasswordPolicyStateJSONField(com.unboundid.ldap.sdk.unboundidds.PasswordPolicyStateJSONField) JSONField(com.unboundid.util.json.JSONField) Test(org.testng.annotations.Test)

Example 34 with JSONField

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());
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) PasswordPolicyStateJSONField(com.unboundid.ldap.sdk.unboundidds.PasswordPolicyStateJSONField) JSONField(com.unboundid.util.json.JSONField) JSONNumber(com.unboundid.util.json.JSONNumber) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Example 35 with JSONField

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());
}
Also used : PasswordQualityRequirement(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordQualityRequirement) JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) PasswordPolicyStateJSONField(com.unboundid.ldap.sdk.unboundidds.PasswordPolicyStateJSONField) JSONField(com.unboundid.util.json.JSONField) Test(org.testng.annotations.Test)

Aggregations

JSONField (com.unboundid.util.json.JSONField)97 JSONObject (com.unboundid.util.json.JSONObject)97 Test (org.testng.annotations.Test)91 JSONArray (com.unboundid.util.json.JSONArray)68 JSONString (com.unboundid.util.json.JSONString)66 JSONNumber (com.unboundid.util.json.JSONNumber)20 PasswordPolicyStateJSONField (com.unboundid.ldap.sdk.unboundidds.PasswordPolicyStateJSONField)11 LDAPSDKUsageException (com.unboundid.util.LDAPSDKUsageException)8 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)7 Date (java.util.Date)7 Entry (com.unboundid.ldap.sdk.Entry)5 JSONException (com.unboundid.util.json.JSONException)5 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)4 JSONBoolean (com.unboundid.util.json.JSONBoolean)4 JSONValue (com.unboundid.util.json.JSONValue)4 CompareRequest (com.unboundid.ldap.sdk.CompareRequest)3 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)3 PasswordQualityRequirement (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordQualityRequirement)3 LogField (com.unboundid.ldap.sdk.unboundidds.logs.v2.LogField)3 ArrayList (java.util.ArrayList)3