Commit 844954fc authored by Quxl's avatar Quxl

x

parent 6f15cce6
package com.egolm.sso; package com.egolm.sso;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.TimeZone; import java.util.TimeZone;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
...@@ -8,6 +10,8 @@ import org.springframework.context.ApplicationContext; ...@@ -8,6 +10,8 @@ import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import com.egolm.sso.util.MyTrustManager;
@EnableScheduling @EnableScheduling
@SpringBootApplication @SpringBootApplication
@EnableTransactionManagement @EnableTransactionManagement
...@@ -15,8 +19,9 @@ public class SapServiceApplication { ...@@ -15,8 +19,9 @@ public class SapServiceApplication {
private static ApplicationContext applicationContext; private static ApplicationContext applicationContext;
public static void main(String[] args) { public static void main(String[] args) throws KeyManagementException, NoSuchAlgorithmException {
TimeZone.setDefault(TimeZone.getTimeZone("GMT+8")); TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
MyTrustManager.trustAllHttpsCertificates();
applicationContext = SpringApplication.run(SapServiceApplication.class, args); applicationContext = SpringApplication.run(SapServiceApplication.class, args);
} }
......
...@@ -3,14 +3,9 @@ package com.egolm.sso.clients; ...@@ -3,14 +3,9 @@ package com.egolm.sso.clients;
import java.io.File; import java.io.File;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
import javax.security.auth.callback.Callback; import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler; import javax.security.auth.callback.CallbackHandler;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;
...@@ -39,21 +34,6 @@ public class SAPServiceFactory { ...@@ -39,21 +34,6 @@ public class SAPServiceFactory {
@Value("${schneider.password}") @Value("${schneider.password}")
private String password; private String password;
public SAPServiceFactory() throws KeyManagementException, NoSuchAlgorithmException {
javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1];
javax.net.ssl.TrustManager tm = new MyTrustManager();
trustAllCerts[0] = tm;
javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String urlHostName, SSLSession session) {
logger.warn("Warning: URL Host: " + urlHostName + " vs. " + session.getPeerHost());
return true;
}
});
}
public <T> T create(Class<T> requiredType, String WSDLPATH, QName serviceQName) { public <T> T create(Class<T> requiredType, String WSDLPATH, QName serviceQName) {
assert requiredType != null : "WebService requiredType cannot be null"; assert requiredType != null : "WebService requiredType cannot be null";
assert WSDLPATH != null : "WebService WSDLPATH cannot be null"; assert WSDLPATH != null : "WebService WSDLPATH cannot be null";
...@@ -106,27 +86,4 @@ public class SAPServiceFactory { ...@@ -106,27 +86,4 @@ public class SAPServiceFactory {
PasswordText, PasswordNone, PasswordDigest PasswordText, PasswordNone, PasswordDigest
} }
public static class MyTrustManager implements javax.net.ssl.TrustManager, javax.net.ssl.X509TrustManager {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public boolean isServerTrusted(java.security.cert.X509Certificate[] certs) {
return true;
}
public boolean isClientTrusted(java.security.cert.X509Certificate[] certs) {
return true;
}
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType)
throws java.security.cert.CertificateException {
return;
}
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType)
throws java.security.cert.CertificateException {
return;
}
}
} }
package com.egolm.sso.util;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class MyTrustManager implements javax.net.ssl.TrustManager, javax.net.ssl.X509TrustManager {
private final static Log logger = LogFactory.getLog(MyTrustManager.class);
public static void trustAllHttpsCertificates() throws NoSuchAlgorithmException, KeyManagementException {
javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1];
javax.net.ssl.TrustManager tm = new MyTrustManager();
trustAllCerts[0] = tm;
javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String urlHostName, SSLSession session) {
logger.warn("Warning: URL Host: " + urlHostName + " vs. " + session.getPeerHost());
return true;
}
});
}
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public boolean isServerTrusted(java.security.cert.X509Certificate[] certs) {
return true;
}
public boolean isClientTrusted(java.security.cert.X509Certificate[] certs) {
return true;
}
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) throws java.security.cert.CertificateException {
return;
}
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) throws java.security.cert.CertificateException {
return;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment