List of usage examples for org.apache.hadoop.security.authentication.client ConnectionConfigurator ConnectionConfigurator
ConnectionConfigurator
From source file:org.apache.atlas.security.SecureClientUtils.java
License:Apache License
private static ConnectionConfigurator newSslConnConfigurator(final int timeout, Configuration conf) throws IOException, GeneralSecurityException { final SSLFactory factory; final SSLSocketFactory sf; final HostnameVerifier hv; factory = new SSLFactory(SSLFactory.Mode.CLIENT, conf); factory.init();/*from w w w . j a v a 2 s .c o m*/ sf = factory.createSSLSocketFactory(); hv = factory.getHostnameVerifier(); return new ConnectionConfigurator() { @Override public HttpURLConnection configure(HttpURLConnection conn) throws IOException { if (conn instanceof HttpsURLConnection) { HttpsURLConnection c = (HttpsURLConnection) conn; c.setSSLSocketFactory(sf); c.setHostnameVerifier(hv); } setTimeouts(conn, timeout); return conn; } }; }
From source file:org.apache.slider.core.restclient.SliderURLConnectionFactory.java
License:Apache License
/** * Create a new ConnectionConfigurator for SSL connections */// w ww . j ava 2 s. c o m private static ConnectionConfigurator newSslConnConfigurator(final int timeout, Configuration conf) throws IOException, GeneralSecurityException { final SSLFactory factory; final SSLSocketFactory sf; final HostnameVerifier hv; factory = new SSLFactory(SSLFactory.Mode.CLIENT, conf); factory.init(); sf = factory.createSSLSocketFactory(); hv = factory.getHostnameVerifier(); return new ConnectionConfigurator() { @Override public HttpURLConnection configure(HttpURLConnection conn) throws IOException { if (conn instanceof HttpsURLConnection) { HttpsURLConnection c = (HttpsURLConnection) conn; c.setSSLSocketFactory(sf); c.setHostnameVerifier(hv); } SliderURLConnectionFactory.setupConnection(conn, timeout); return conn; } }; }
From source file:org.apache.sqoop.client.request.ResourceRequest.java
License:Apache License
public Token<?>[] addDelegationTokens(String strURL, String renewer, Credentials credentials) throws IOException { Token<?>[] tokens = null;//from www . j a v a 2 s . co m Text dtService = getDelegationTokenService(strURL); Token<?> token = credentials.getToken(dtService); if (token == null) { URL url = new URL(strURL); DelegationTokenAuthenticatedURL authUrl = new DelegationTokenAuthenticatedURL( new ConnectionConfigurator() { @Override public HttpURLConnection configure(HttpURLConnection conn) throws IOException { return conn; } }); try { token = authUrl.getDelegationToken(url, authToken, renewer); if (token != null) { credentials.addToken(token.getService(), token); tokens = new Token<?>[] { token }; } else { throw new IOException("Got NULL as delegation token"); } } catch (AuthenticationException ex) { throw new IOException(ex); } } return tokens; }
From source file:org.apache.tez.dag.api.client.TimelineReaderFactory.java
License:Apache License
private static ConnectionConfigurator getNewConnectionConf(final Configuration conf, final boolean useHttps, final int connTimeout) { ConnectionConfigurator connectionConf = null; if (useHttps) { try {/*from ww w. j ava 2s . c om*/ connectionConf = getNewSSLConnectionConf(conf, connTimeout); } catch (IOException e) { if (LOG.isDebugEnabled()) { LOG.debug("Cannot load customized ssl related configuration." + " Falling back to system-generic settings.", e); } } } if (connectionConf == null) { connectionConf = new ConnectionConfigurator() { @Override public HttpURLConnection configure(HttpURLConnection httpURLConnection) throws IOException { setTimeouts(httpURLConnection, connTimeout); return httpURLConnection; } }; } return connectionConf; }
From source file:org.apache.tez.dag.api.client.TimelineReaderFactory.java
License:Apache License
private static ConnectionConfigurator getNewSSLConnectionConf(final Configuration conf, final int connTimeout) throws IOException { final SSLFactory sslFactory; final SSLSocketFactory sslSocketFactory; final HostnameVerifier hostnameVerifier; sslFactory = new SSLFactory(CLIENT, conf); try {/*from w w w .j a va 2s.c o m*/ sslFactory.init(); sslSocketFactory = sslFactory.createSSLSocketFactory(); } catch (GeneralSecurityException e) { sslFactory.destroy(); throw new IOException("Failed to initialize ssl factory"); } hostnameVerifier = sslFactory.getHostnameVerifier(); return new ConnectionConfigurator() { @Override public HttpURLConnection configure(HttpURLConnection httpURLConnection) throws IOException { if (!(httpURLConnection instanceof HttpsURLConnection)) { throw new IOException("Expected https connection"); } HttpsURLConnection httpsURLConnection = (HttpsURLConnection) httpURLConnection; httpsURLConnection.setSSLSocketFactory(sslSocketFactory); httpsURLConnection.setHostnameVerifier(hostnameVerifier); setTimeouts(httpsURLConnection, connTimeout); return httpsURLConnection; } }; }