Search in sources :

Example 1 with GSSAPIBindRequestProperties

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

the class SASLUtils method createGSSAPIBindRequest.

/**
 * Creates a SASL GSSAPI 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 GSSAPI bind request that was created.
 *
 * @throws  LDAPException  If a problem is encountered while trying to create
 *                         the SASL bind request.
 */
@NotNull()
private static GSSAPIBindRequest createGSSAPIBindRequest(@Nullable final byte[] password, final boolean promptForPassword, @Nullable final CommandLineTool tool, @NotNull final Map<String, String> options, @Nullable final Control[] controls) throws LDAPException {
    // 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, GSSAPIBindRequest.GSSAPI_MECHANISM_NAME));
    }
    final GSSAPIBindRequestProperties gssapiProperties = new GSSAPIBindRequestProperties(authID, password);
    // The authzID option is optional.
    gssapiProperties.setAuthorizationID(options.remove(StaticUtils.toLowerCase(SASL_OPTION_AUTHZ_ID)));
    // The configFile option is optional.
    gssapiProperties.setConfigFilePath(options.remove(StaticUtils.toLowerCase(SASL_OPTION_CONFIG_FILE)));
    // The debug option is optional.
    gssapiProperties.setEnableGSSAPIDebugging(getBooleanValue(options, SASL_OPTION_DEBUG, false));
    // The kdcAddress option is optional.
    gssapiProperties.setKDCAddress(options.remove(StaticUtils.toLowerCase(SASL_OPTION_KDC_ADDRESS)));
    // The protocol option is optional.
    final String protocol = options.remove(StaticUtils.toLowerCase(SASL_OPTION_PROTOCOL));
    if (protocol != null) {
        gssapiProperties.setServicePrincipalProtocol(protocol);
    }
    // The realm option is optional.
    gssapiProperties.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) {
        gssapiProperties.setAllowedQoP(SASLQualityOfProtection.decodeQoPList(qopString));
    }
    // The renewTGT option is optional.
    gssapiProperties.setRenewTGT(getBooleanValue(options, SASL_OPTION_RENEW_TGT, false));
    // The requireCache option is optional.
    gssapiProperties.setRequireCachedCredentials(getBooleanValue(options, SASL_OPTION_REQUIRE_CACHE, false));
    // The ticketCache option is optional.
    gssapiProperties.setTicketCachePath(options.remove(StaticUtils.toLowerCase(SASL_OPTION_TICKET_CACHE_PATH)));
    // The useTicketCache option is optional.
    gssapiProperties.setUseTicketCache(getBooleanValue(options, SASL_OPTION_USE_TICKET_CACHE, true));
    // Ensure no unsupported options were provided.
    ensureNoUnsupportedOptions(options, GSSAPIBindRequest.GSSAPI_MECHANISM_NAME);
    // requireTicketCache=true.
    if (password == null) {
        if (!(gssapiProperties.useTicketCache() && gssapiProperties.requireCachedCredentials())) {
            if (promptForPassword) {
                tool.getOriginalOut().print(INFO_LDAP_TOOL_ENTER_BIND_PASSWORD.get());
                gssapiProperties.setPassword(PasswordReader.readPassword());
                tool.getOriginalOut().println();
            } else {
                throw new LDAPException(ResultCode.PARAM_ERROR, ERR_SASL_OPTION_GSSAPI_PASSWORD_REQUIRED.get());
            }
        }
    }
    return new GSSAPIBindRequest(gssapiProperties, controls);
}
Also used : GSSAPIBindRequest(com.unboundid.ldap.sdk.GSSAPIBindRequest) GSSAPIBindRequestProperties(com.unboundid.ldap.sdk.GSSAPIBindRequestProperties) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Aggregations

GSSAPIBindRequest (com.unboundid.ldap.sdk.GSSAPIBindRequest)1 GSSAPIBindRequestProperties (com.unboundid.ldap.sdk.GSSAPIBindRequestProperties)1 LDAPException (com.unboundid.ldap.sdk.LDAPException)1