Search in sources :

Example 81 with JSONField

use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.

the class RecentLoginHistoryTestCase method testDecodeMalformedSuccessObject.

/**
 * Tests the behavior when trying to decode a JSON object with a malformed
 * set of successful attempts when the malformed attempt is an object.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeMalformedSuccessObject() throws Exception {
    final JSONObject o = new JSONObject(new JSONField("successful-attempts", new JSONArray(new JSONObject(new JSONField("malformed", true)))));
    new RecentLoginHistory(o);
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) JSONField(com.unboundid.util.json.JSONField) Test(org.testng.annotations.Test)

Example 82 with JSONField

use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.

the class RecentLoginHistoryTestCase method testDecodeMalformedFailureNotObject.

/**
 * Tests the behavior when trying to decode a JSON object with a malformed
 * set of failed attempts when the malformed attempt is not an object.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeMalformedFailureNotObject() throws Exception {
    final JSONObject o = new JSONObject(new JSONField("failed-attempts", new JSONArray(new JSONString("malformed"))));
    new RecentLoginHistory(o);
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) JSONField(com.unboundid.util.json.JSONField) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Example 83 with JSONField

use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.

the class PasswordPolicyStateJSONTestCase method testGraceLogins.

/**
 * Tests the behavior for the properties related to grace logins.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGraceLogins() throws Exception {
    PasswordPolicyStateJSON state = createState(StaticUtils.mapOf(MAXIMUM_GRACE_LOGIN_COUNT, 5, USED_GRACE_LOGIN_COUNT, 0, REMAINING_GRACE_LOGIN_COUNT, 5, GRACE_LOGIN_USE_TIMES, Collections.emptyList()));
    assertNotNull(state.getMaximumGraceLoginCount());
    assertEquals(state.getMaximumGraceLoginCount().intValue(), 5);
    assertNotNull(state.getUsedGraceLoginCount());
    assertEquals(state.getUsedGraceLoginCount().intValue(), 0);
    assertNotNull(state.getRemainingGraceLoginCount());
    assertEquals(state.getRemainingGraceLoginCount().intValue(), 5);
    assertNotNull(state.getGraceLoginUseTimes());
    assertTrue(state.getGraceLoginUseTimes().isEmpty());
    final Date currentDate = new Date();
    final Date threeMinutesAgo = new Date(currentDate.getTime() - 3_000L);
    final Date twoMinutesAgo = new Date(currentDate.getTime() - 2_000L);
    final Date oneMinuteAgo = new Date(currentDate.getTime() - 1_000L);
    final List<Date> graceLoginUseTimes = Arrays.asList(threeMinutesAgo, twoMinutesAgo, oneMinuteAgo);
    state = createState(StaticUtils.mapOf(MAXIMUM_GRACE_LOGIN_COUNT, 5, USED_GRACE_LOGIN_COUNT, 3, REMAINING_GRACE_LOGIN_COUNT, 2, GRACE_LOGIN_USE_TIMES, graceLoginUseTimes));
    assertNotNull(state.getMaximumGraceLoginCount());
    assertEquals(state.getMaximumGraceLoginCount().intValue(), 5);
    assertNotNull(state.getUsedGraceLoginCount());
    assertEquals(state.getUsedGraceLoginCount().intValue(), 3);
    assertNotNull(state.getRemainingGraceLoginCount());
    assertEquals(state.getRemainingGraceLoginCount().intValue(), 2);
    assertNotNull(state.getGraceLoginUseTimes());
    assertFalse(state.getGraceLoginUseTimes().isEmpty());
    assertEquals(state.getGraceLoginUseTimes(), graceLoginUseTimes);
    final JSONObject o = new JSONObject(new JSONField(GRACE_LOGIN_USE_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.getGraceLoginUseTimes());
    assertTrue(state.getGraceLoginUseTimes().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 84 with JSONField

use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.

the class PasswordPolicyStateJSONTestCase method testGetPasswordQualityRequirementsPropertyMissingValue.

/**
 * Tests the behavior when trying to retrieve password quality requirements
 * when the properties array has an object without a value.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGetPasswordQualityRequirementsPropertyMissingValue() 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("name", "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)

Example 85 with JSONField

use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.

the class PasswordPolicyStateJSONTestCase method testMalformedRecentLoginHistory.

/**
 * Tests the behavior when trying to retrieve a malformed recent login
 * history.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testMalformedRecentLoginHistory() throws Exception {
    final PasswordPolicyStateJSON state = createState(StaticUtils.mapOf(RECENT_LOGIN_HISTORY, new JSONObject(new JSONField("successful-attempts", new JSONArray(new JSONObject(new JSONField("malformed", true))))), MAXIMUM_RECENT_LOGIN_HISTORY_SUCCESSFUL_AUTHENTICATION_COUNT, 50, MAXIMUM_RECENT_LOGIN_HISTORY_SUCCESSFUL_AUTHENTICATION_DURATION_SECONDS, (int) TimeUnit.DAYS.toSeconds(30L), MAXIMUM_RECENT_LOGIN_HISTORY_FAILED_AUTHENTICATION_COUNT, 20, MAXIMUM_RECENT_LOGIN_HISTORY_FAILED_AUTHENTICATION_DURATION_SECONDS, (int) TimeUnit.DAYS.toSeconds(10L)));
    state.getRecentLoginHistory();
}
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)

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