有没有办法使用 Apache oltu 通过 SSL 请求访问 token ? 如果我不使用 https(端口 8443)而只使用 http,它会很好用...
我的代码:
OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
OAuthClientRequest request = OAuthClientRequest.tokenLocation(MessageFormat.format("https://{0}:8443/applicationId/oauth/token", host)) //
.setGrantType(GrantType.PASSWORD) //
.setUsername("username") //
.setPassword("password") //
.setClientId("clientId") //
.buildBodyMessage();
OAuthAccessTokenResponse oAuthResponse = oAuthClient.accessToken(request);
我收到以下异常消息:
org.apache.oltu.oauth2.common.exception.OAuthSystemException: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No name matching localhost found
at org.apache.oltu.oauth2.client.URLConnectionClient.execute(URLConnectionClient.java:108)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:65)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:55)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:71)
我知道有这种方法可以通过覆盖 HttpsURLConnection 的 HostnameVerifier 来解决这个问题,但是有没有办法在 apache oltu 中实现这个?:
static {
//for localhost testing only
javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
new javax.net.ssl.HostnameVerifier(){
public boolean verify(String hostname,
javax.net.ssl.SSLSession sslSession) {
if (hostname.equals("localhost")) {
return true;
}
return false;
}
});
}
最佳答案
URLConnectionClient
使用 HttpsURLConnection
因此您的代码应该可以工作;你试过了吗?
关于java - Apache oltu oauth2 通过 SSL 询问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27707907/