如何绕过 Openshift 上 URLConnection 的 SSL 检查
How to bypass SSL check of URLConnection on Openshift
我找到了 3 种不同的方法,但只有其中一种能以非常丑陋的方式工作。
我正在使用 Spring MVC 在 openshift 上创建一个 REST 端点。
方法一:
HostnameVerifier bypassSSl = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(bypassSSl);
我把这个放到了@Bean
里面WebMvcConfigurerAdapter
,不行。
方法二:
new OpenShiftConnectionFactory()
.getConnection(id, username, password, host, new ISSLCertificateCallback() {
public boolean allowCertificate(X509Certificate[] chain) {
return true;
}
public boolean allowHostname(String hostname, SSLSession session) {
return true;
}
} )
没试过这个,不知道从哪里获得 OpenShift 库 jar 文件。
方法三
HostnameVerifier bypassSSl = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(bypassSSl);
在每个 HTTP 请求之前添加此代码段,它有效,但我认为这是一种非常糟糕的做法。
我应该如何将此绕过添加到我的 spring mvc webapp?是否有合适的事件处理程序,我可以在我的 webapp 启动时将其连接起来并 运行 恰好一次?
最终使用@mariuszprzydatek 的 class
gist link
我通过实现 ApplicationListener<ContextRefreshedEvent>
将其放入 spring 事件循环中,然后覆盖 onApplicationEvent(final ContextRefreshedEvent e)
我找到了 3 种不同的方法,但只有其中一种能以非常丑陋的方式工作。
我正在使用 Spring MVC 在 openshift 上创建一个 REST 端点。
方法一:
HostnameVerifier bypassSSl = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(bypassSSl);
我把这个放到了@Bean
里面WebMvcConfigurerAdapter
,不行。
方法二:
new OpenShiftConnectionFactory()
.getConnection(id, username, password, host, new ISSLCertificateCallback() {
public boolean allowCertificate(X509Certificate[] chain) {
return true;
}
public boolean allowHostname(String hostname, SSLSession session) {
return true;
}
} )
没试过这个,不知道从哪里获得 OpenShift 库 jar 文件。
方法三
HostnameVerifier bypassSSl = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(bypassSSl);
在每个 HTTP 请求之前添加此代码段,它有效,但我认为这是一种非常糟糕的做法。
我应该如何将此绕过添加到我的 spring mvc webapp?是否有合适的事件处理程序,我可以在我的 webapp 启动时将其连接起来并 运行 恰好一次?
最终使用@mariuszprzydatek 的 class gist link
我通过实现 ApplicationListener<ContextRefreshedEvent>
将其放入 spring 事件循环中,然后覆盖 onApplicationEvent(final ContextRefreshedEvent e)