有没有办法使用 Apache oltu 通过 SSL 请求访问令牌?如果我不使用 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;
}
});
}