我正在尝试对运行IIS的Windows服务器进行身份验证,该服务器使用ApacheIIS4.3为( HttpClient )配置。我的代码看起来非常类似于我能够在线定位的示例代码,但是当我运行它时,我始终会得到一个HTTP 401返回。我对结果运行了Wireshark,没有看到SPNEGO令牌正在传递给服务器。
我可以通过web浏览器很好地访问受保护的资源,在本例中,我确实看到了SPNEGO令牌。不过,当我运行我的代码时,情况就不一样了。下面是所讨论的代码:
public static void main(String[] args) {
System.setProperty("java.security.krb5.conf",
"c:\\develop\\XYZ\\KerberosTest\\conf\\krb5.conf");
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
System.setProperty("java.security.auth.login.config",
"c:\\develop\\XYZ\\KerberosTest\\conf\\login.conf");
Credentials jaasCredentials = new Credentials() {
public String getPassword() {
return null;
}
public Principal getUserPrincipal() {
return null;
}
};
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(null, -1, null),
jaasCredentials);
Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder
.<AuthSchemeProvider> create().register(AuthSchemes.SPNEGO,
new SPNegoSchemeFactory()).build();
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultAuthSchemeRegistry(authSchemeRegistry)
.setDefaultCredentialsProvider(credsProvider).build();
try {
HttpGet httpget = new HttpGet(ENDPOINT);
RequestLine requestLine = httpget.getRequestLine();
CloseableHttpResponse response = httpclient.execute(httpget);
try {
StatusLine status = response.getStatusLine();
HttpEntity entity = response.getEntity();
if (entity != null) {
}
EntityUtils.consume(entity);
} finally {
response.close();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}我相信我已经正确配置了我的krb5.conf文件,并且我的login.conf文件是直接从Apache文档中获取的。我还做了适当的注册表项更改,如文档中提到的。
你知道是什么导致了这件事吗?或者我该如何进行故障排除?有没有我错过的一步或一条线?
发布于 2014-02-24 20:30:33
问题解决了。这似乎是由IBM的JDK中的一个bug造成的。一旦我换了太阳,一切都正常。
https://stackoverflow.com/questions/21996162
复制相似问题