Example usage for org.apache.thrift.transport TSaslClientTransport TSaslClientTransport

List of usage examples for org.apache.thrift.transport TSaslClientTransport TSaslClientTransport

Introduction

In this page you can find the example usage for org.apache.thrift.transport TSaslClientTransport TSaslClientTransport.

Prototype

public TSaslClientTransport(String mechanism, String authorizationId, String protocol, String serverName,
        Map<String, String> props, CallbackHandler cbh, TTransport transport) throws SaslException 

Source Link

Document

Creates a SaslClient using the given SASL-specific parameters.

Usage

From source file:alluxio.security.authentication.PlainSaslTransportProvider.java

License:Apache License

/**
 * Gets a PLAIN mechanism transport for client side.
 *
 * @param username User Name of PlainClient
 * @param password Password of PlainClient
 * @param serverAddress Address of the server
 * @return Wrapped transport with PLAIN mechanism
 *//*from w  w w.  j  a v a  2  s . c om*/
public TTransport getClientTransport(String username, String password, InetSocketAddress serverAddress)
        throws UnauthenticatedException {
    TTransport wrappedTransport = TransportProviderUtils.createThriftSocket(serverAddress, mSocketTimeoutMs);
    try {
        return new TSaslClientTransport(PlainSaslServerProvider.MECHANISM, null, null, null,
                new HashMap<String, String>(), new PlainSaslClientCallbackHandler(username, password),
                wrappedTransport);
    } catch (SaslException e) {
        throw new UnauthenticatedException(e.getMessage(), e);
    }
}

From source file:alluxio.security.authentication.PlainSaslUtils.java

License:Apache License

/**
 * Gets a PLAIN mechanism transport for client side.
 *
 * @param username User Name of PlainClient
 * @param password Password of PlainClient
 * @param wrappedTransport The original Transport
 * @return Wrapped transport with PLAIN mechanism
 * @throws SaslException if an AuthenticationProvider is not found
 *///w  w w.  ja v  a2s  .  co m
public static TTransport getPlainClientTransport(String username, String password, TTransport wrappedTransport)
        throws SaslException {
    return new TSaslClientTransport(PlainSaslServerProvider.MECHANISM, null, null, null,
            new HashMap<String, String>(), new PlainClientCallbackHandler(username, password),
            wrappedTransport);
}

From source file:backtype.storm.security.auth.digest.DigestSaslTransportPlugin.java

License:Apache License

@Override
public TTransport connect(TTransport transport, String serverHost) throws TTransportException, IOException {
    ClientCallbackHandler client_callback_handler = new ClientCallbackHandler(login_conf);
    TSaslClientTransport wrapper_transport = new TSaslClientTransport(DIGEST, null, AuthUtils.SERVICE,
            serverHost, null, client_callback_handler, transport);

    wrapper_transport.open();//from  w  ww  . jav a 2  s . com
    LOG.debug("SASL DIGEST-MD5 client transport has been established");

    return wrapper_transport;
}

From source file:backtype.storm.security.auth.kerberos.KerberosSaslTransportPlugin.java

License:Apache License

public TTransport connect(TTransport transport, String serverHost) throws TTransportException, IOException {
    //create an authentication callback handler
    ClientCallbackHandler client_callback_handler = new ClientCallbackHandler(login_conf);

    //login our user
    Login login = null;//from   w  w w  .j a  v  a  2s.co m
    try {
        //specify a configuration object to be used
        Configuration.setConfiguration(login_conf);
        //now login
        login = new Login(AuthUtils.LOGIN_CONTEXT_CLIENT, client_callback_handler);
    } catch (LoginException ex) {
        LOG.error("Server failed to login in principal:" + ex, ex);
        throw new RuntimeException(ex);
    }

    final Subject subject = login.getSubject();
    if (subject.getPrivateCredentials(KerberosTicket.class).isEmpty()) { //error
        throw new RuntimeException("Fail to verify user principal with section \""
                + AuthUtils.LOGIN_CONTEXT_CLIENT + "\" in login configuration file " + login_conf);
    }

    final String principal = getPrincipal(subject);
    String serviceName = AuthUtils.get(login_conf, AuthUtils.LOGIN_CONTEXT_CLIENT, "serviceName");
    if (serviceName == null) {
        serviceName = AuthUtils.SERVICE;
    }
    Map<String, String> props = new TreeMap<String, String>();
    props.put(Sasl.QOP, "auth");
    props.put(Sasl.SERVER_AUTH, "false");

    LOG.debug("SASL GSSAPI client transport is being established");
    final TTransport sasalTransport = new TSaslClientTransport(KERBEROS, principal, serviceName, serverHost,
            props, null, transport);

    //open Sasl transport with the login credential
    try {
        Subject.doAs(subject, new PrivilegedExceptionAction<Void>() {
            public Void run() {
                try {
                    LOG.debug("do as:" + principal);
                    sasalTransport.open();
                } catch (Exception e) {
                    LOG.error(
                            "Client failed to open SaslClientTransport to interact with a server during session initiation: "
                                    + e,
                            e);
                }
                return null;
            }
        });
    } catch (PrivilegedActionException e) {
        throw new RuntimeException(e);
    }

    return sasalTransport;
}

From source file:com.cloudera.llama.am.LlamaAdminClient.java

License:Apache License

static TTransport createTransport(boolean secure, String host, int port) throws Exception {
    TTransport transport = new TSocket(host, port);
    if (secure) {
        Map<String, String> saslProperties = new HashMap<String, String>();
        saslProperties.put(Sasl.QOP, "auth-conf,auth-int,auth");
        transport = new TSaslClientTransport("GSSAPI", null, "llama", host, saslProperties, null, transport);
    }//from ww w.  jav a2 s  .c om
    transport.open();
    return transport;
}

From source file:com.cloudera.llama.am.LlamaClient.java

License:Apache License

static LlamaAMService.Client createClient(boolean secure, String host, int port) throws Exception {
    TTransport transport = new TSocket(host, port);
    if (secure) {
        Map<String, String> saslProperties = new HashMap<String, String>();
        saslProperties.put(Sasl.QOP, "auth-conf,auth-int,auth");
        transport = new TSaslClientTransport("GSSAPI", null, "llama", host, saslProperties, null, transport);
    }/*from  w w w  . j ava  2  s.co  m*/
    transport.open();
    TProtocol protocol = new TBinaryProtocol(transport);
    return new LlamaAMService.Client(protocol);
}

From source file:com.cloudera.llama.am.TestSecureLlamaAMThriftServer.java

License:Apache License

protected com.cloudera.llama.thrift.LlamaAMService.Client createClient(LlamaAMServer server, String qop)
        throws Exception {
    TTransport transport = new TSocket(server.getAddressHost(), server.getAddressPort());
    Map<String, String> saslProperties = new HashMap<String, String>();
    saslProperties.put(Sasl.QOP, qop);
    transport = new TSaslClientTransport("GSSAPI", null, "llama", server.getAddressHost(), saslProperties, null,
            transport);/*from  w  ww.j a va2  s  .  co m*/
    transport.open();
    TProtocol protocol = new TBinaryProtocol(transport);
    return new com.cloudera.llama.thrift.LlamaAMService.Client(protocol);
}

From source file:com.cloudera.llama.am.TestSecureLlamaAMThriftServer.java

License:Apache License

@Override
protected com.cloudera.llama.thrift.LlamaAMAdminService.Client createAdminClient(LlamaAMServer server)
        throws Exception {
    TTransport transport = new TSocket(server.getAdminAddressHost(), server.getAdminAddressPort());
    Map<String, String> saslProperties = new HashMap<String, String>();
    saslProperties.put(Sasl.QOP, "auth-conf,auth-int,auth");
    transport = new TSaslClientTransport("GSSAPI", null, "llama", server.getAddressHost(), saslProperties, null,
            transport);/*from   w w w .j a  v a2  s .co  m*/
    transport.open();
    TProtocol protocol = new TBinaryProtocol(transport);
    return new com.cloudera.llama.thrift.LlamaAMAdminService.Client(protocol);
}

From source file:com.cloudera.llama.nm.TestSecureLlamaNMAuxiliaryService.java

License:Apache License

@Override
protected LlamaNMService.Client createClient() throws Exception {
    TTransport transport = new TSocket(MyLlamaNMAuxiliaryService.host, MyLlamaNMAuxiliaryService.port);
    Map<String, String> saslProperties = new HashMap<String, String>();
    saslProperties.put(Sasl.QOP, "auth-conf,auth-int,auth");
    transport = new TSaslClientTransport("GSSAPI", null, "llama", MyLlamaNMAuxiliaryService.host,
            saslProperties, null, transport);
    transport.open();//from w  ww. ja  v  a 2  s . c o m
    TProtocol protocol = new TBinaryProtocol(transport);
    return new LlamaNMService.Client(protocol);
}

From source file:com.cloudera.llama.server.ThriftEndPoint.java

License:Apache License

public static TTransport createClientTransport(ServerConfiguration conf, String host, int port)
        throws Exception {
    int timeout = conf.getTransportTimeOut();

    TTransport tTransport = new TSocket(host, port, timeout);
    if (Security.isSecure(conf)) {
        String serviceName = conf.getNotificationPrincipalName();
        Map<String, String> saslProperties = new HashMap<String, String>();
        saslProperties.put(Sasl.QOP, "auth-conf,auth-int,auth");
        tTransport = new TSaslClientTransport("GSSAPI", null, serviceName, host, saslProperties, null,
                tTransport);/*from   ww  w.  jav a 2 s  .  c o m*/
    }
    return tTransport;
}