Example usage for javax.security.sasl Sasl createSaslClient

List of usage examples for javax.security.sasl Sasl createSaslClient

Introduction

In this page you can find the example usage for javax.security.sasl Sasl createSaslClient.

Prototype

public static SaslClient createSaslClient(String[] mechanisms, String authorizationId, String protocol,
        String serverName, Map<String, ?> props, CallbackHandler cbh) throws SaslException 

Source Link

Document

Creates a SaslClient using the parameters supplied.

Usage

From source file:org.apache.hadoop.io.crypto.bee.key.sasl.KeySaslClient.java

public KeySaslClient(KeyToken keyToken) throws SaslException {
    logger.debug("assign key token");
    this.keyToken = keyToken;
    Map<String, String> propsClient = new TreeMap<String, String>();
    propsClient.put(Sasl.QOP, "auth-conf");
    saslCli = Sasl.createSaslClient(new String[] { "DIGEST-MD5" }, this.keyToken.getUser(),
            SaslUtil.KEY_SERVICE, SaslUtil.KEY_REALM, propsClient, new ClientCallbackHandler(this.keyToken));

    saslAuthStatus = SaslUtil.SaslAuthStatus.AUTH_PROCESSING;
}

From source file:org.apache.hadoop.security.SaslRpcClient.java

/**
 * Create a SaslRpcClient for an authentication method
 * /*w  ww  .  ja v a2s .  c  om*/
 * @param method
 *          the requested authentication method
 * @param token
 *          token to use if needed by the authentication method
 */
public SaslRpcClient(AuthMethod method, Token<? extends TokenIdentifier> token, String serverPrincipal)
        throws IOException {
    switch (method) {
    case DIGEST:
        if (LOG.isDebugEnabled())
            LOG.debug("Creating SASL " + AuthMethod.DIGEST.getMechanismName()
                    + " client to authenticate to service at " + token.getService());
        saslClient = Sasl.createSaslClient(new String[] { AuthMethod.DIGEST.getMechanismName() }, null, null,
                SaslRpcServer.SASL_DEFAULT_REALM, SaslRpcServer.SASL_PROPS,
                new SaslClientCallbackHandler(token));
        break;
    case KERBEROS:
        if (LOG.isDebugEnabled()) {
            LOG.debug("Creating SASL " + AuthMethod.KERBEROS.getMechanismName()
                    + " client. Server's Kerberos principal name is " + serverPrincipal);
        }
        if (serverPrincipal == null || serverPrincipal.length() == 0) {
            throw new IOException("Failed to specify server's Kerberos principal name");
        }
        String names[] = SaslRpcServer.splitKerberosName(serverPrincipal);
        if (names.length != 3) {
            throw new IOException(
                    "Kerberos principal name does NOT have the expected hostname part: " + serverPrincipal);
        }
        saslClient = Sasl.createSaslClient(new String[] { AuthMethod.KERBEROS.getMechanismName() }, null,
                names[0], names[1], SaslRpcServer.SASL_PROPS, null);
        break;
    default:
        throw new IOException("Unknown authentication method " + method);
    }
    if (saslClient == null)
        throw new IOException("Unable to find SASL client implementation");
}

From source file:org.wildfly.security.sasl.entity.EntityTest.java

@Test
public void testServerAuthIndirect_Client() throws Exception {
    Map<String, Object> props = new HashMap<String, Object>();

    // No properties are set, an appropriate EntitySaslClient should be returned
    SaslClient client = Sasl.createSaslClient(
            new String[] { SaslMechanismInformation.Names.IEC_ISO_9798_U_RSA_SHA1_ENC }, "TestUser",
            "TestProtocol", "TestServer", props, null);
    assertEquals(EntitySaslClient.class, client.getClass());
    assertEquals(SaslMechanismInformation.Names.IEC_ISO_9798_U_RSA_SHA1_ENC, client.getMechanismName());

    // If we set SERVER_AUTH to true even though only unilateral mechanisms are specified, no client should be returned
    props.put(Sasl.SERVER_AUTH, Boolean.toString(true));
    client = Sasl.createSaslClient(
            new String[] { SaslMechanismInformation.Names.IEC_ISO_9798_U_RSA_SHA1_ENC,
                    SaslMechanismInformation.Names.IEC_ISO_9798_U_DSA_SHA1,
                    SaslMechanismInformation.Names.IEC_ISO_9798_U_ECDSA_SHA1 },
            "TestUser", "TestProtocol", "TestServer", props, null);
    assertNull(client);//from  w  ww  . j av  a 2s  .  c  o m

    // If we set SERVER_AUTH to true, an appropriate EntitySaslClient should be returned
    props.put(Sasl.SERVER_AUTH, Boolean.toString(true));
    client = Sasl.createSaslClient(
            new String[] { SaslMechanismInformation.Names.IEC_ISO_9798_U_RSA_SHA1_ENC,
                    SaslMechanismInformation.Names.IEC_ISO_9798_U_DSA_SHA1,
                    SaslMechanismInformation.Names.IEC_ISO_9798_U_ECDSA_SHA1,
                    SaslMechanismInformation.Names.IEC_ISO_9798_M_RSA_SHA1_ENC,
                    SaslMechanismInformation.Names.IEC_ISO_9798_M_DSA_SHA1,
                    SaslMechanismInformation.Names.IEC_ISO_9798_M_ECDSA_SHA1 },
            "TestUser", "TestProtocol", "TestServer", props, null);
    assertEquals(EntitySaslClient.class, client.getClass());
    assertEquals(SaslMechanismInformation.Names.IEC_ISO_9798_M_RSA_SHA1_ENC, client.getMechanismName());
}