是否有一种使用Apache通过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)我知道有一种方法可以通过覆盖HostnameVerifier的HttpsURLConnection来解决这个问题,但是在apache中有实现这种方法的方法吗?:
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;
}
});
}发布于 2014-12-30 21:00:32
URLConnectionClient使用HttpsURLConnection,所以您的代码应该可以工作;您试过了吗?
https://stackoverflow.com/questions/27707907
复制相似问题