Search in sources :

Example 36 with JSONArray

use of com.unboundid.util.json.JSONArray 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 37 with JSONArray

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

the class PasswordPolicyStateJSONTestCase method testGetAdministrativeResetPasswordQualityRequirements.

/**
 * Tests the behavior for the properties related to password quality
 * requirements for administrative password resets.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGetAdministrativeResetPasswordQualityRequirements() 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.getAdministrativeResetPasswordQualityRequirements());
    assertFalse(state.getAdministrativeResetPasswordQualityRequirements().isEmpty());
    assertEquals(state.getAdministrativeResetPasswordQualityRequirements().size(), 2);
    final PasswordQualityRequirement requirement0 = state.getAdministrativeResetPasswordQualityRequirements().get(0);
    assertEquals(requirement0.getDescription(), allRequirement.getDescription());
    assertEquals(requirement0.getClientSideValidationType(), allRequirement.getClientSideValidationType());
    assertEquals(requirement0.getClientSideValidationProperties(), allRequirement.getClientSideValidationProperties());
    final PasswordQualityRequirement requirement1 = state.getAdministrativeResetPasswordQualityRequirements().get(1);
    assertEquals(requirement1.getDescription(), adminResetRequirement.getDescription());
    assertEquals(requirement1.getClientSideValidationType(), adminResetRequirement.getClientSideValidationType());
    assertEquals(requirement1.getClientSideValidationProperties(), adminResetRequirement.getClientSideValidationProperties());
}
Also used : PasswordQualityRequirement(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordQualityRequirement) JSONArray(com.unboundid.util.json.JSONArray) Test(org.testng.annotations.Test)

Example 38 with JSONArray

use of com.unboundid.util.json.JSONArray 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)

Example 39 with JSONArray

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

the class PasswordPolicyStateJSONTestCase method testGetPasswordQualityRequirementsArrayValueNotObject.

/**
 * Tests the behavior when trying to retrieve password quality requirements
 * when the array contains a non-object element.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGetPasswordQualityRequirementsArrayValueNotObject() throws Exception {
    final PasswordPolicyStateJSON state = createState(StaticUtils.mapOf(PASSWORD_QUALITY_REQUIREMENTS, new JSONArray(new JSONString("foo"))));
    assertNotNull(state.getAddPasswordQualityRequirements());
    assertTrue(state.getAddPasswordQualityRequirements().isEmpty());
}
Also used : JSONArray(com.unboundid.util.json.JSONArray) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Example 40 with JSONArray

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

the class LDAPCompareJSONOutputHandler method formatResult.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
String formatResult(@NotNull final CompareRequest request, @NotNull final LDAPResult result) {
    final Map<String, JSONValue> fields = new LinkedHashMap<>();
    fields.put(FIELD_NAME_DN, new JSONString(request.getDN()));
    fields.put(FIELD_NAME_ATTRIBUTE, new JSONString(request.getAttributeName()));
    fields.put(FIELD_NAME_ASSERTION_VALUE, new JSONString(request.getAssertionValue()));
    fields.put(FIELD_NAME_RESULT_CODE_VALUE, new JSONNumber(result.getResultCode().intValue()));
    fields.put(FIELD_NAME_RESULT_CODE_NAME, new JSONString(result.getResultCode().getName()));
    if (result.getDiagnosticMessage() != null) {
        fields.put(FIELD_NAME_DIAGNOSTIC_MESSAGE, new JSONString(result.getDiagnosticMessage()));
    }
    if (result.getMatchedDN() != null) {
        fields.put(FIELD_NAME_MATCHED_DN, new JSONString(result.getMatchedDN()));
    }
    if (result.getReferralURLs().length > 0) {
        final JSONValue[] referralURLValues = new JSONValue[result.getReferralURLs().length];
        for (int i = 0; i < referralURLValues.length; i++) {
            referralURLValues[i] = new JSONString(result.getReferralURLs()[i]);
        }
        fields.put(FIELD_NAME_REFERRAL_URLS, new JSONArray(referralURLValues));
    }
    return new JSONObject(fields).toSingleLineString();
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) JSONNumber(com.unboundid.util.json.JSONNumber) JSONString(com.unboundid.util.json.JSONString) JSONString(com.unboundid.util.json.JSONString) LinkedHashMap(java.util.LinkedHashMap) NotNull(com.unboundid.util.NotNull)

Aggregations

JSONArray (com.unboundid.util.json.JSONArray)98 JSONObject (com.unboundid.util.json.JSONObject)89 JSONString (com.unboundid.util.json.JSONString)77 Test (org.testng.annotations.Test)72 JSONField (com.unboundid.util.json.JSONField)68 JSONValue (com.unboundid.util.json.JSONValue)27 JSONNumber (com.unboundid.util.json.JSONNumber)22 NotNull (com.unboundid.util.NotNull)20 ArrayList (java.util.ArrayList)19 LinkedHashMap (java.util.LinkedHashMap)18 PasswordPolicyStateJSONField (com.unboundid.ldap.sdk.unboundidds.PasswordPolicyStateJSONField)11 PasswordQualityRequirement (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordQualityRequirement)7 Entry (com.unboundid.ldap.sdk.Entry)6 Map (java.util.Map)6 LDAPSDKUsageException (com.unboundid.util.LDAPSDKUsageException)5 JSONBoolean (com.unboundid.util.json.JSONBoolean)5 JSONException (com.unboundid.util.json.JSONException)5 Date (java.util.Date)4 List (java.util.List)4 LogField (com.unboundid.ldap.sdk.unboundidds.logs.v2.LogField)3