Search in sources :

Example 1 with DIGESTMD5BindRequestProperties

use of com.unboundid.ldap.sdk.DIGESTMD5BindRequestProperties in project ldapsdk by pingidentity.

the class SASLUtils method createDIGESTMD5BindRequest.

/**
 * Creates a SASL DIGEST-MD5 bind request using the provided password and set
 * of options.
 *
 * @param  password           The password to use for the bind request.
 * @param  promptForPassword  Indicates whether to interactively prompt for
 *                            the password if one is needed but none was
 *                            provided.
 * @param  tool               The command-line tool whose input and output
 *                            streams should be used when prompting for the
 *                            bind password.  It may be {@code null} only if
 *                            {@code promptForPassword} is {@code false}.
 * @param  options            The set of SASL options for the bind request.
 * @param  controls           The set of controls to include in the request.
 *
 * @return  The SASL DIGEST-MD5 bind request that was created.
 *
 * @throws  LDAPException  If a problem is encountered while trying to create
 *                         the SASL bind request.
 */
@NotNull()
private static DIGESTMD5BindRequest createDIGESTMD5BindRequest(@Nullable() final byte[] password, final boolean promptForPassword, @Nullable final CommandLineTool tool, @NotNull final Map<String, String> options, @Nullable final Control[] controls) throws LDAPException {
    final byte[] pw;
    if (password == null) {
        if (promptForPassword) {
            tool.getOriginalOut().print(INFO_LDAP_TOOL_ENTER_BIND_PASSWORD.get());
            pw = PasswordReader.readPassword();
            tool.getOriginalOut().println();
        } else {
            throw new LDAPException(ResultCode.PARAM_ERROR, ERR_SASL_OPTION_MECH_REQUIRES_PASSWORD.get(DIGESTMD5BindRequest.DIGESTMD5_MECHANISM_NAME));
        }
    } else {
        pw = password;
    }
    // The authID option is required.
    final String authID = options.remove(StaticUtils.toLowerCase(SASL_OPTION_AUTH_ID));
    if (authID == null) {
        throw new LDAPException(ResultCode.PARAM_ERROR, ERR_SASL_MISSING_REQUIRED_OPTION.get(SASL_OPTION_AUTH_ID, DIGESTMD5BindRequest.DIGESTMD5_MECHANISM_NAME));
    }
    final DIGESTMD5BindRequestProperties properties = new DIGESTMD5BindRequestProperties(authID, pw);
    // The authzID option is optional.
    properties.setAuthorizationID(options.remove(StaticUtils.toLowerCase(SASL_OPTION_AUTHZ_ID)));
    // The realm option is optional.
    properties.setRealm(options.remove(StaticUtils.toLowerCase(SASL_OPTION_REALM)));
    // The QoP option is optional, and may contain multiple values that need to
    // be parsed.
    final String qopString = options.remove(StaticUtils.toLowerCase(SASL_OPTION_QOP));
    if (qopString != null) {
        properties.setAllowedQoP(SASLQualityOfProtection.decodeQoPList(qopString));
    }
    // Ensure no unsupported options were provided.
    ensureNoUnsupportedOptions(options, DIGESTMD5BindRequest.DIGESTMD5_MECHANISM_NAME);
    return new DIGESTMD5BindRequest(properties, controls);
}
Also used : DIGESTMD5BindRequestProperties(com.unboundid.ldap.sdk.DIGESTMD5BindRequestProperties) LDAPException(com.unboundid.ldap.sdk.LDAPException) DIGESTMD5BindRequest(com.unboundid.ldap.sdk.DIGESTMD5BindRequest)

Aggregations

DIGESTMD5BindRequest (com.unboundid.ldap.sdk.DIGESTMD5BindRequest)1 DIGESTMD5BindRequestProperties (com.unboundid.ldap.sdk.DIGESTMD5BindRequestProperties)1 LDAPException (com.unboundid.ldap.sdk.LDAPException)1