Search in sources :

Example 6 with PasswordPolicyStateExtendedResult

use of com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateExtendedResult 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)

Example 7 with PasswordPolicyStateExtendedResult

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

the class ManageAccountProcessor method handleResult.

/**
 * Performs the appropriate processing for a result that failed with an
 * {@code LDAPException}.
 *
 * @param  request  The request that was processed.
 * @param  le       The exception caught during processing.
 */
private void handleResult(@NotNull final PasswordPolicyStateExtendedRequest request, @NotNull final LDAPException le) {
    try {
        final PasswordPolicyStateExtendedResult result = new PasswordPolicyStateExtendedResult(new ExtendedResult(le));
        handleResult(request, result);
        return;
    } catch (final Exception e) {
        Debug.debugException(e);
    }
    handleResult(createResultEntry(request, le.toLDAPResult()), true);
}
Also used : PasswordPolicyStateExtendedResult(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateExtendedResult) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult) PasswordPolicyStateExtendedResult(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateExtendedResult) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Aggregations

PasswordPolicyStateExtendedResult (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateExtendedResult)7 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)4 InMemoryDirectoryServerConfig (com.unboundid.ldap.listener.InMemoryDirectoryServerConfig)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Test (org.testng.annotations.Test)4 LDAPException (com.unboundid.ldap.sdk.LDAPException)3 PasswordPolicyStateOperation (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateOperation)3 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)2 ExtendedResult (com.unboundid.ldap.sdk.ExtendedResult)2 PasswordPolicyStateAccountUsabilityError (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityError)2 PasswordPolicyStateAccountUsabilityNotice (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityNotice)2 PasswordPolicyStateAccountUsabilityWarning (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityWarning)2 Entry (com.unboundid.ldap.sdk.Entry)1 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)1 NotNull (com.unboundid.util.NotNull)1 Argument (com.unboundid.util.args.Argument)1 ArgumentParser (com.unboundid.util.args.ArgumentParser)1 BooleanValueArgument (com.unboundid.util.args.BooleanValueArgument)1 StringArgument (com.unboundid.util.args.StringArgument)1 SubCommand (com.unboundid.util.args.SubCommand)1