List of usage examples for org.apache.hadoop.security.ssl SSLFactory getHostnameVerifier
public HostnameVerifier getHostnameVerifier()
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 ww .ja 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.registry.retrieve.AMWebClient.java
License:Apache License
private static URLConnectionClientHandler getUrlConnectionClientHandler() { return new URLConnectionClientHandler(new HttpURLConnectionFactory() { @Override//from w w w . ja v a2 s.co m public HttpURLConnection getHttpURLConnection(URL url) throws IOException { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); if (connection.getResponseCode() == HttpURLConnection.HTTP_MOVED_TEMP) { // is a redirect - are we changing schemes? String redirectLocation = connection.getHeaderField(HttpHeaders.LOCATION); String originalScheme = url.getProtocol(); String redirectScheme = URI.create(redirectLocation).getScheme(); if (!originalScheme.equals(redirectScheme)) { // need to fake it out by doing redirect ourselves log.info("Protocol change during redirect. Redirecting {} to URL {}", url, redirectLocation); URL redirectURL = new URL(redirectLocation); connection = (HttpURLConnection) redirectURL.openConnection(); } } if (connection instanceof HttpsURLConnection) { log.debug("Attempting to configure HTTPS connection using client " + "configuration"); final SSLFactory factory; final SSLSocketFactory sf; final HostnameVerifier hv; try { HttpsURLConnection c = (HttpsURLConnection) connection; factory = new SSLFactory(SSLFactory.Mode.CLIENT, new Configuration()); factory.init(); sf = factory.createSSLSocketFactory(); hv = factory.getHostnameVerifier(); c.setSSLSocketFactory(sf); c.setHostnameVerifier(hv); } catch (Exception e) { log.info("Unable to configure HTTPS connection from " + "configuration. Using JDK properties."); } } return connection; } }); }
From source file:org.apache.slider.core.registry.retrieve.RegistryRetriever.java
License:Apache License
private static URLConnectionClientHandler getUrlConnectionClientHandler() { return new URLConnectionClientHandler(new HttpURLConnectionFactory() { @Override//ww w . ja va2 s.c o m public HttpURLConnection getHttpURLConnection(URL url) throws IOException { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); if (connection.getResponseCode() == HttpURLConnection.HTTP_MOVED_TEMP) { // is a redirect - are we changing schemes? String redirectLocation = connection.getHeaderField(HttpHeaders.LOCATION); String originalScheme = url.getProtocol(); String redirectScheme = URI.create(redirectLocation).getScheme(); if (!originalScheme.equals(redirectScheme)) { // need to fake it out by doing redirect ourselves log.info("Protocol change during redirect. Redirecting {} to URL {}", url, redirectLocation); URL redirectURL = new URL(redirectLocation); connection = (HttpURLConnection) redirectURL.openConnection(); } } if (connection instanceof HttpsURLConnection) { log.debug("Attempting to configure HTTPS connection using client " + "configuration"); final SSLFactory factory; final SSLSocketFactory sf; final HostnameVerifier hv; try { HttpsURLConnection c = (HttpsURLConnection) connection; factory = new SSLFactory(SSLFactory.Mode.CLIENT, new Configuration()); factory.init(); sf = factory.createSSLSocketFactory(); hv = factory.getHostnameVerifier(); c.setSSLSocketFactory(sf); c.setHostnameVerifier(hv); } catch (Exception e) { log.info("Unable to configure HTTPS connection from " + "configuration. Leveraging JDK properties."); } } return connection; } }); }
From source file:org.apache.slider.core.restclient.SliderURLConnectionFactory.java
License:Apache License
/** * Create a new ConnectionConfigurator for SSL connections *//* w ww . ja va2 s . co 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.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 {/* w ww .j av a2 s . c om*/ 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; } }; }