List of usage examples for javax.net.ssl SSLParameters getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.microsoft.tfs.core.config.httpclient.internal.DefaultSSLProtocolSocketFactory.java
private void configureSNI(final Socket socket, final String host) { if (System.getProperty("java.version").compareTo("1.8") < 0) { //$NON-NLS-1$ //$NON-NLS-2$ return;/*w ww . j a v a 2s . c om*/ } /* * Classes used to configure Server Name client-hello extension were * introduced in Java 8. So, we neither can use nor compile this code * using Java 6-7. Thus, let's use reflection. */ try { final SSLSocket sslSocket = (SSLSocket) socket; final SSLParameters params = sslSocket.getSSLParameters(); final Class<?> sniHostNameClass = Class.forName("javax.net.ssl.SNIHostName"); //$NON-NLS-1$ final Constructor<?> sniHostNameClassConstructor = sniHostNameClass.getConstructor(String.class); final Object serverName = sniHostNameClassConstructor.newInstance(host); final List<Object> serverNames = new ArrayList<Object>(1); serverNames.add(serverName); final Class<?> paramsClass = params.getClass(); final Method setServerNames = paramsClass.getMethod("setServerNames", List.class); //$NON-NLS-1$ setServerNames.invoke(params, serverNames); sslSocket.setSSLParameters(params); } catch (final Exception e) { log.error("Eror configuring SSL socket with SNI cipher extension:", e); //$NON-NLS-1$ } }
From source file:org.alfresco.repo.security.authentication.ldap.AlfrescoLdapSSLSocketFactory.java
private void addHostNameVerification(SSLSocket sslSocket) { if (useJava6CodeBase == null || useJava6CodeBase) { //Try to use SSLSocketImpl.trySetHostnameVerification method that is supported by java6 and lower try {/*from w w w . ja va 2 s . co m*/ Method m = sslSocket.getClass().getMethod("trySetHostnameVerification", String.class); m.invoke(sslSocket, "LDAP"); useJava6CodeBase = true; useJava7CodeBase = false; } catch (Throwable e) { useJava6CodeBase = false; } } if (useJava7CodeBase == null || useJava7CodeBase) { //Try to use sslParams.setEndpointIdentificationAlgorithm method that is supported by java 7 and higher try { SSLParameters sslParams = new SSLParameters(); Method m = sslParams.getClass().getMethod("setEndpointIdentificationAlgorithm", String.class); m.invoke(sslParams, "LDAPS"); sslSocket.setSSLParameters(sslParams); useJava6CodeBase = false; useJava7CodeBase = true; } catch (Throwable ee) { useJava7CodeBase = false; if (useJava6CodeBase == false && logger.isWarnEnabled()) { logger.warn("AlfrescoLdapSSLSocketFactory: Unable to turn on Hostname Verification"); } } } }