use of com.unboundid.ldap.sdk.unboundidds.extensions.PasswordQualityRequirement in project ldapsdk by pingidentity.
the class PasswordPolicyStateJSON method getPasswordQualityRequirements.
/**
* Retrieves a list of the password quality requirements that are contained in
* the JSON object in which the indicated Boolean field is present and set to
* {@code true}.
*
* @param booleanFieldName The name of the field that is expected to be
* present with a Boolean value of true for each
* requirement to be included in the list that is
* returned.
*
* @return The appropriate list of password quality requirements, or an empty
* list if no requirements will be imposed.
*/
@NotNull()
private List<PasswordQualityRequirement> getPasswordQualityRequirements(@NotNull final String booleanFieldName) {
final List<JSONValue> requirementObjectLst = passwordPolicyStateObject.getFieldAsArray(PASSWORD_QUALITY_REQUIREMENTS.getFieldName());
if ((requirementObjectLst == null) || requirementObjectLst.isEmpty()) {
return Collections.emptyList();
}
final List<PasswordQualityRequirement> requirements = new ArrayList<>(requirementObjectLst.size());
for (final JSONValue requirementObjectValue : requirementObjectLst) {
if (!(requirementObjectValue instanceof JSONObject)) {
continue;
}
final JSONObject requirementObject = (JSONObject) requirementObjectValue;
final Boolean include = requirementObject.getFieldAsBoolean(booleanFieldName);
if ((include == null) || (!include.booleanValue())) {
continue;
}
final String description = requirementObject.getFieldAsString(REQUIREMENT_FIELD_DESCRIPTION);
if (description == null) {
continue;
}
final String clientSideValidationType = requirementObject.getFieldAsString(REQUIREMENT_FIELD_CLIENT_SIDE_VALIDATION_TYPE);
final Map<String, String> clientSideValidationProperties = new LinkedHashMap<>();
final List<JSONValue> propertyValues = requirementObject.getFieldAsArray(REQUIREMENT_FIELD_CLIENT_SIDE_VALIDATION_PROPERTIES);
if (propertyValues != null) {
for (final JSONValue propertyValue : propertyValues) {
if (!(propertyValue instanceof JSONObject)) {
continue;
}
final JSONObject propertyObject = (JSONObject) propertyValue;
final String name = propertyObject.getFieldAsString(REQUIREMENT_FIELD_CLIENT_SIDE_VALIDATION_PROPERTY_NAME);
final String value = propertyObject.getFieldAsString(REQUIREMENT_FIELD_CLIENT_SIDE_VALIDATION_PROPERTY_VALUE);
if ((name != null) && (value != null)) {
clientSideValidationProperties.put(name, value);
}
}
}
requirements.add(new PasswordQualityRequirement(description, clientSideValidationType, clientSideValidationProperties));
}
return requirements;
}
use of com.unboundid.ldap.sdk.unboundidds.extensions.PasswordQualityRequirement in project ldapsdk by pingidentity.
the class PasswordQualityRequirementValidationResult method decode.
/**
* Decodes the provided ASN.1 element as a password quality requirement
* validation result.
*
* @param element The ASN.1 element to be decoded as a password quality
* requirement validation result.
*
* @return The ASN.1 element containing the encoded password quality
* requirement validation result.
*
* @throws LDAPException If a problem is encountered while attempting to
* decode the provided ASN.1 element.
*/
@NotNull()
public static PasswordQualityRequirementValidationResult decode(@NotNull final ASN1Element element) throws LDAPException {
try {
final ASN1Element[] elements = ASN1Sequence.decodeAsSequence(element).elements();
final PasswordQualityRequirement passwordRequirement = PasswordQualityRequirement.decode(elements[0]);
final boolean requirementSatisfied = ASN1Boolean.decodeAsBoolean(elements[1]).booleanValue();
String additionalInfo = null;
for (int i = 2; i < elements.length; i++) {
switch(elements[i].getType()) {
case TYPE_ADDITIONAL_INFO:
additionalInfo = ASN1OctetString.decodeAsOctetString(elements[i]).stringValue();
break;
default:
throw new LDAPException(ResultCode.DECODING_ERROR, ERR_PW_REQ_VALIDATION_RESULT_INVALID_ELEMENT_TYPE.get(StaticUtils.toHex(elements[i].getType())));
}
}
return new PasswordQualityRequirementValidationResult(passwordRequirement, requirementSatisfied, additionalInfo);
} catch (final LDAPException le) {
Debug.debugException(le);
throw le;
} catch (final Exception e) {
Debug.debugException(e);
throw new LDAPException(ResultCode.DECODING_ERROR, ERR_PW_REQ_VALIDATION_RESULT_CANNOT_DECODE.get(StaticUtils.getExceptionMessage(e)), e);
}
}
use of com.unboundid.ldap.sdk.unboundidds.extensions.PasswordQualityRequirement in project ldapsdk by pingidentity.
the class PasswordQualityRequirementValidationResultTestCase method testRequirementNotSatisfied.
/**
* Tests the behavior for a result that indicates that the requirement was not
* satisfied.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testRequirementNotSatisfied() throws Exception {
PasswordQualityRequirementValidationResult r = new PasswordQualityRequirementValidationResult(new PasswordQualityRequirement("this will not be satisfied"), false, "Not good enough");
r = PasswordQualityRequirementValidationResult.decode(r.encode());
assertNotNull(r);
assertNotNull(r.getPasswordRequirement());
assertEquals(r.getPasswordRequirement().getDescription(), "this will not be satisfied");
assertFalse(r.requirementSatisfied());
assertNotNull(r.getAdditionalInfo());
assertEquals(r.getAdditionalInfo(), "Not good enough");
assertNotNull(r.toString());
}
use of com.unboundid.ldap.sdk.unboundidds.extensions.PasswordQualityRequirement in project ldapsdk by pingidentity.
the class PasswordValidationDetailsResponseControlTestCase method testValidationDetailsResultWithRequirements.
/**
* Tests the behavior for a control that provides information about the
* results of validation processing when there were requirements.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testValidationDetailsResultWithRequirements() throws Exception {
final List<PasswordQualityRequirementValidationResult> validationResults = Arrays.asList(new PasswordQualityRequirementValidationResult(new PasswordQualityRequirement("this was accepted"), true, null), new PasswordQualityRequirementValidationResult(new PasswordQualityRequirement("this was not accepted"), false, "Not good enough"));
PasswordValidationDetailsResponseControl c = new PasswordValidationDetailsResponseControl(PasswordValidationDetailsResponseType.VALIDATION_DETAILS, validationResults, true, true, 12345);
final Control genericControl = Control.decode(c.getOID(), c.isCritical(), c.getValue());
assertNotNull(genericControl);
assertTrue(genericControl instanceof PasswordValidationDetailsResponseControl);
c = (PasswordValidationDetailsResponseControl) genericControl;
assertNotNull(c.getOID());
assertEquals(c.getOID(), "1.3.6.1.4.1.30221.2.5.41");
assertFalse(c.isCritical());
assertNotNull(c.getValue());
assertNotNull(c.getResponseType());
assertEquals(c.getResponseType(), PasswordValidationDetailsResponseType.VALIDATION_DETAILS);
assertNotNull(c.getValidationResults());
assertFalse(c.getValidationResults().isEmpty());
assertEquals(c.getValidationResults().size(), 2);
assertTrue(c.missingCurrentPassword());
assertTrue(c.mustChangePassword());
assertNotNull(c.getSecondsUntilExpiration());
assertEquals(c.getSecondsUntilExpiration().intValue(), 12345);
assertNotNull(c.getControlName());
assertNotNull(c.toString());
}
use of com.unboundid.ldap.sdk.unboundidds.extensions.PasswordQualityRequirement in project ldapsdk by pingidentity.
the class PasswordPolicyStateJSONTestCase method testGetSelfChangePasswordQualityRequirements.
/**
* Tests the behavior for the properties related to password quality
* requirements for self password changes.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testGetSelfChangePasswordQualityRequirements() 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.getSelfChangePasswordQualityRequirements());
assertFalse(state.getSelfChangePasswordQualityRequirements().isEmpty());
assertEquals(state.getSelfChangePasswordQualityRequirements().size(), 2);
final PasswordQualityRequirement requirement0 = state.getSelfChangePasswordQualityRequirements().get(0);
assertEquals(requirement0.getDescription(), allRequirement.getDescription());
assertEquals(requirement0.getClientSideValidationType(), allRequirement.getClientSideValidationType());
assertEquals(requirement0.getClientSideValidationProperties(), allRequirement.getClientSideValidationProperties());
final PasswordQualityRequirement requirement1 = state.getSelfChangePasswordQualityRequirements().get(1);
assertEquals(requirement1.getDescription(), selfChangeRequirement.getDescription());
assertEquals(requirement1.getClientSideValidationType(), selfChangeRequirement.getClientSideValidationType());
assertEquals(requirement1.getClientSideValidationProperties(), selfChangeRequirement.getClientSideValidationProperties());
}
Aggregations