Search in sources :

Example 16 with PasswordPolicyStateAccountUsabilityWarning

use of com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityWarning in project ldapsdk by pingidentity.

the class ManageAccountProcessor method createResultEntry.

/**
 * Creates an entry that encapsulates the content of the provided result.
 *
 * @param  request  The request that was processed.
 * @param  result   The result of the processing.
 *
 * @return  The entry that was created.
 */
@NotNull()
private Entry createResultEntry(@NotNull final PasswordPolicyStateExtendedRequest request, @NotNull final LDAPResult result) {
    final Entry e = new Entry(request.getUserDN());
    e.addAttribute("base-command-line", commandLine + " --targetDN " + StaticUtils.cleanExampleCommandLineArgument(e.getDN()));
    e.addAttribute("result-code", String.valueOf(result.getResultCode().intValue()));
    final String resultCodeName = result.getResultCode().getName();
    if (resultCodeName != null) {
        e.addAttribute("result-code-name", resultCodeName);
    }
    final String diagnosticMessage = result.getDiagnosticMessage();
    if (diagnosticMessage != null) {
        e.addAttribute("diagnostic-message", diagnosticMessage);
    }
    final String matchedDN = result.getMatchedDN();
    if (matchedDN != null) {
        e.addAttribute("matched-dn", matchedDN);
    }
    final String[] referralURLs = result.getReferralURLs();
    if ((referralURLs != null) && (referralURLs.length > 0)) {
        e.addAttribute("referral-url", referralURLs);
    }
    if (!(result instanceof PasswordPolicyStateExtendedResult)) {
        return e;
    }
    final PasswordPolicyStateExtendedResult r = (PasswordPolicyStateExtendedResult) result;
    for (final PasswordPolicyStateOperation o : r.getOperations()) {
        final String[] values = o.getStringValues();
        if (values.length == 0) {
            if (suppressEmptyResultOperations) {
                continue;
            }
        }
        final String attrName;
        final ManageAccountSubCommandType subcommandType = ManageAccountSubCommandType.forOperationType(o.getOperationType());
        if (subcommandType == null) {
            if (o.getOperationType() == 39) {
                // This is a deprecated response that the client doesn't support, but
                // older servers may return it.
                attrName = "get-password-history";
            } else {
                // This result may come from a newer version of the server that has
                // additional password policy state operation types.
                attrName = "unrecognized-operation-type-" + o.getOperationType();
            }
        } else {
            attrName = subcommandType.getPrimaryName();
        }
        if (values.length == 0) {
            e.addAttribute(attrName, "");
        } else if (subcommandType == null) {
            e.addAttribute(attrName, values);
        } else {
            // those specially.  Otherwise, just go with the string representations.
            switch(subcommandType) {
                case GET_ACCOUNT_USABILITY_NOTICES:
                    final String[] notices = new String[values.length];
                    for (int i = 0; i < values.length; i++) {
                        try {
                            notices[i] = new PasswordPolicyStateAccountUsabilityNotice(values[i]).getMessage();
                        } catch (final Exception ex) {
                            Debug.debugException(ex);
                            notices[i] = values[i];
                        }
                    }
                    e.addAttribute(attrName, notices);
                    break;
                case GET_ACCOUNT_USABILITY_WARNINGS:
                    final String[] warnings = new String[values.length];
                    for (int i = 0; i < values.length; i++) {
                        try {
                            warnings[i] = new PasswordPolicyStateAccountUsabilityWarning(values[i]).getMessage();
                        } catch (final Exception ex) {
                            Debug.debugException(ex);
                            warnings[i] = values[i];
                        }
                    }
                    e.addAttribute(attrName, warnings);
                    break;
                case GET_ACCOUNT_USABILITY_ERRORS:
                    final String[] errors = new String[values.length];
                    for (int i = 0; i < values.length; i++) {
                        try {
                            errors[i] = new PasswordPolicyStateAccountUsabilityError(values[i]).getMessage();
                        } catch (final Exception ex) {
                            Debug.debugException(ex);
                            errors[i] = values[i];
                        }
                    }
                    e.addAttribute(attrName, errors);
                    break;
                default:
                    e.addAttribute(attrName, values);
                    break;
            }
        }
    }
    return e;
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) PasswordPolicyStateAccountUsabilityNotice(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityNotice) PasswordPolicyStateAccountUsabilityError(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityError) PasswordPolicyStateOperation(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateOperation) PasswordPolicyStateAccountUsabilityWarning(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityWarning) PasswordPolicyStateExtendedResult(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateExtendedResult) LDAPException(com.unboundid.ldap.sdk.LDAPException) NotNull(com.unboundid.util.NotNull)

Aggregations

PasswordPolicyStateAccountUsabilityWarning (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityWarning)16 PasswordPolicyStateAccountUsabilityError (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityError)15 PasswordPolicyStateAccountUsabilityNotice (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityNotice)15 Test (org.testng.annotations.Test)10 Control (com.unboundid.ldap.sdk.Control)5 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)4 LDAPException (com.unboundid.ldap.sdk.LDAPException)4 AuthenticationFailureReason (com.unboundid.ldap.sdk.unboundidds.controls.AuthenticationFailureReason)4 ArrayList (java.util.ArrayList)4 NotNull (com.unboundid.util.NotNull)3 BindResult (com.unboundid.ldap.sdk.BindResult)2 Entry (com.unboundid.ldap.sdk.Entry)2 PasswordPolicyStateExtendedResult (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateExtendedResult)2 PasswordPolicyStateOperation (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateOperation)2 JSONObject (com.unboundid.util.json.JSONObject)2 JSONString (com.unboundid.util.json.JSONString)2 JSONValue (com.unboundid.util.json.JSONValue)2 LinkedHashMap (java.util.LinkedHashMap)2 ASN1Element (com.unboundid.asn1.ASN1Element)1 ASN1Integer (com.unboundid.asn1.ASN1Integer)1