All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jlot.client.config.rest.SSLContextInitalizer Maven / Gradle / Ivy

There is a newer version: 1.2
Show newest version
package org.jlot.client.config.rest;

import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import org.springframework.stereotype.Component;

@Component
public class SSLContextInitalizer
{
	public SSLContextInitalizer ()
	{
		initalize();
	}

	public void initalize ( )
	{
		try
		{
			SSLContext ctx = SSLContext.getInstance("TLS");
			X509TrustManager tm = new X509TrustManager()
			{

				@Override
				public void checkClientTrusted ( X509Certificate[] xcs, String string ) throws CertificateException
				{}

				@Override
				public void checkServerTrusted ( X509Certificate[] xcs, String string ) throws CertificateException
				{}

				@Override
				public X509Certificate[] getAcceptedIssuers ( )
				{
					return null;
				}
			};
			ctx.init(null, new TrustManager[] { tm }, null);
			SSLContext.setDefault(ctx);
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy