Search in sources :

Example 1 with URLConnectionClientHandler

use of com.sun.jersey.client.urlconnection.URLConnectionClientHandler in project hadoop by apache.

the class TestTimelineReaderWebServicesHBaseStorage method createClient.

private static Client createClient() {
    ClientConfig cfg = new DefaultClientConfig();
    cfg.getClasses().add(YarnJacksonJaxbJsonProvider.class);
    return new Client(new URLConnectionClientHandler(new DummyURLConnectionFactory()), cfg);
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) URLConnectionClientHandler(com.sun.jersey.client.urlconnection.URLConnectionClientHandler) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) Client(com.sun.jersey.api.client.Client)

Example 2 with URLConnectionClientHandler

use of com.sun.jersey.client.urlconnection.URLConnectionClientHandler in project hadoop by apache.

the class TestTimelineReaderWebServices method createClient.

private static Client createClient() {
    ClientConfig cfg = new DefaultClientConfig();
    cfg.getClasses().add(YarnJacksonJaxbJsonProvider.class);
    return new Client(new URLConnectionClientHandler(new DummyURLConnectionFactory()), cfg);
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) URLConnectionClientHandler(com.sun.jersey.client.urlconnection.URLConnectionClientHandler) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) Client(com.sun.jersey.api.client.Client)

Example 3 with URLConnectionClientHandler

use of com.sun.jersey.client.urlconnection.URLConnectionClientHandler in project incubator-atlas by apache.

the class AtlasBaseClient method getClient.

@VisibleForTesting
protected Client getClient(Configuration configuration, UserGroupInformation ugi, String doAsUser) {
    DefaultClientConfig config = new DefaultClientConfig();
    // Enable POJO mapping feature
    config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
    int readTimeout = configuration.getInt("atlas.client.readTimeoutMSecs", 60000);
    int connectTimeout = configuration.getInt("atlas.client.connectTimeoutMSecs", 60000);
    if (configuration.getBoolean(TLS_ENABLED, false)) {
        // configuration object, persist it, then subsequently pass in an empty configuration to SSLFactory
        try {
            SecureClientUtils.persistSSLClientConfiguration(configuration);
        } catch (Exception e) {
            LOG.info("Error processing client configuration.", e);
        }
    }
    final URLConnectionClientHandler handler;
    if ((!AuthenticationUtil.isKerberosAuthenticationEnabled()) && basicAuthUser != null && basicAuthPassword != null) {
        if (configuration.getBoolean(TLS_ENABLED, false)) {
            handler = SecureClientUtils.getUrlConnectionClientHandler();
        } else {
            handler = new URLConnectionClientHandler();
        }
    } else {
        handler = SecureClientUtils.getClientConnectionHandler(config, configuration, doAsUser, ugi);
    }
    Client client = new Client(handler, config);
    client.setReadTimeout(readTimeout);
    client.setConnectTimeout(connectTimeout);
    return client;
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) URLConnectionClientHandler(com.sun.jersey.client.urlconnection.URLConnectionClientHandler) Client(com.sun.jersey.api.client.Client) ConnectException(java.net.ConnectException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with URLConnectionClientHandler

use of com.sun.jersey.client.urlconnection.URLConnectionClientHandler in project hadoop by apache.

the class TimelineConnector method serviceInit.

@Override
protected void serviceInit(Configuration conf) throws Exception {
    super.serviceInit(conf);
    ClientConfig cc = new DefaultClientConfig();
    cc.getClasses().add(YarnJacksonJaxbJsonProvider.class);
    sslFactory = getSSLFactory(conf);
    connConfigurator = getConnConfigurator(sslFactory);
    if (UserGroupInformation.isSecurityEnabled()) {
        authenticator = new KerberosDelegationTokenAuthenticator();
    } else {
        authenticator = new PseudoDelegationTokenAuthenticator();
    }
    authenticator.setConnectionConfigurator(connConfigurator);
    connectionRetry = new TimelineClientConnectionRetry(conf);
    client = new Client(new URLConnectionClientHandler(new TimelineURLConnectionFactory(authUgi, authenticator, connConfigurator, token, doAsUser)), cc);
    if (requireConnectionRetry) {
        TimelineJerseyRetryFilter retryFilter = new TimelineJerseyRetryFilter(connectionRetry);
        client.addFilter(retryFilter);
    }
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) PseudoDelegationTokenAuthenticator(org.apache.hadoop.security.token.delegation.web.PseudoDelegationTokenAuthenticator) URLConnectionClientHandler(com.sun.jersey.client.urlconnection.URLConnectionClientHandler) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) Client(com.sun.jersey.api.client.Client) KerberosDelegationTokenAuthenticator(org.apache.hadoop.security.token.delegation.web.KerberosDelegationTokenAuthenticator)

Example 5 with URLConnectionClientHandler

use of com.sun.jersey.client.urlconnection.URLConnectionClientHandler in project incubator-atlas by apache.

the class SecureClientUtils method getClientConnectionHandler.

public static URLConnectionClientHandler getClientConnectionHandler(DefaultClientConfig config, org.apache.commons.configuration.Configuration clientConfig, String doAsUser, final UserGroupInformation ugi) {
    config.getProperties().put(URLConnectionClientHandler.PROPERTY_HTTP_URL_CONNECTION_SET_METHOD_WORKAROUND, true);
    Configuration conf = new Configuration();
    conf.addResource(conf.get(SSLFactory.SSL_CLIENT_CONF_KEY, SecurityProperties.SSL_CLIENT_PROPERTIES));
    UserGroupInformation.setConfiguration(conf);
    final ConnectionConfigurator connConfigurator = newConnConfigurator(conf);
    Authenticator authenticator = new KerberosDelegationTokenAuthenticator();
    authenticator.setConnectionConfigurator(connConfigurator);
    final DelegationTokenAuthenticator finalAuthenticator = (DelegationTokenAuthenticator) authenticator;
    final DelegationTokenAuthenticatedURL.Token token = new DelegationTokenAuthenticatedURL.Token();
    HttpURLConnectionFactory httpURLConnectionFactory = null;
    try {
        UserGroupInformation ugiToUse = ugi != null ? ugi : UserGroupInformation.getCurrentUser();
        final UserGroupInformation actualUgi = (ugiToUse.getAuthenticationMethod() == UserGroupInformation.AuthenticationMethod.PROXY) ? ugiToUse.getRealUser() : ugiToUse;
        LOG.info("Real User: {}, is from ticket cache? {}", actualUgi, actualUgi.isLoginTicketBased());
        if (StringUtils.isEmpty(doAsUser)) {
            doAsUser = actualUgi.getShortUserName();
        }
        LOG.info("doAsUser: {}", doAsUser);
        final String finalDoAsUser = doAsUser;
        httpURLConnectionFactory = new HttpURLConnectionFactory() {

            @Override
            public HttpURLConnection getHttpURLConnection(final URL url) throws IOException {
                try {
                    return actualUgi.doAs(new PrivilegedExceptionAction<HttpURLConnection>() {

                        @Override
                        public HttpURLConnection run() throws Exception {
                            try {
                                return new DelegationTokenAuthenticatedURL(finalAuthenticator, connConfigurator).openConnection(url, token, finalDoAsUser);
                            } catch (Exception e) {
                                throw new IOException(e);
                            }
                        }
                    });
                } catch (Exception e) {
                    if (e instanceof IOException) {
                        throw (IOException) e;
                    } else {
                        throw new IOException(e);
                    }
                }
            }
        };
    } catch (IOException e) {
        LOG.warn("Error obtaining user", e);
    }
    return new URLConnectionClientHandler(httpURLConnectionFactory);
}
Also used : ConnectionConfigurator(org.apache.hadoop.security.authentication.client.ConnectionConfigurator) Configuration(org.apache.hadoop.conf.Configuration) DelegationTokenAuthenticatedURL(org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticatedURL) KerberosDelegationTokenAuthenticator(org.apache.hadoop.security.token.delegation.web.KerberosDelegationTokenAuthenticator) DelegationTokenAuthenticator(org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticator) IOException(java.io.IOException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) URL(java.net.URL) DelegationTokenAuthenticatedURL(org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticatedURL) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) AtlasException(org.apache.atlas.AtlasException) HttpURLConnectionFactory(com.sun.jersey.client.urlconnection.HttpURLConnectionFactory) HttpURLConnection(java.net.HttpURLConnection) URLConnectionClientHandler(com.sun.jersey.client.urlconnection.URLConnectionClientHandler) KerberosDelegationTokenAuthenticator(org.apache.hadoop.security.token.delegation.web.KerberosDelegationTokenAuthenticator) Authenticator(org.apache.hadoop.security.authentication.client.Authenticator) DelegationTokenAuthenticator(org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticator) KerberosDelegationTokenAuthenticator(org.apache.hadoop.security.token.delegation.web.KerberosDelegationTokenAuthenticator) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Aggregations

URLConnectionClientHandler (com.sun.jersey.client.urlconnection.URLConnectionClientHandler)5 Client (com.sun.jersey.api.client.Client)4 DefaultClientConfig (com.sun.jersey.api.client.config.DefaultClientConfig)4 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)3 IOException (java.io.IOException)2 KerberosDelegationTokenAuthenticator (org.apache.hadoop.security.token.delegation.web.KerberosDelegationTokenAuthenticator)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)1 HttpURLConnectionFactory (com.sun.jersey.client.urlconnection.HttpURLConnectionFactory)1 ConnectException (java.net.ConnectException)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 GeneralSecurityException (java.security.GeneralSecurityException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 AtlasException (org.apache.atlas.AtlasException)1 Configuration (org.apache.hadoop.conf.Configuration)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 Authenticator (org.apache.hadoop.security.authentication.client.Authenticator)1 ConnectionConfigurator (org.apache.hadoop.security.authentication.client.ConnectionConfigurator)1 DelegationTokenAuthenticatedURL (org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticatedURL)1