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());
}
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());
}
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());
}
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());
}
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();
}
Aggregations