首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于HttpClient的SPNEGO认证

基于HttpClient的SPNEGO认证
EN

Stack Overflow用户
提问于 2014-02-24 18:38:48
回答 1查看 3.7K关注 0票数 2

我正在尝试对运行IIS的Windows服务器进行身份验证,该服务器使用ApacheIIS4.3为( HttpClient )配置。我的代码看起来非常类似于我能够在线定位的示例代码,但是当我运行它时,我始终会得到一个HTTP 401返回。我对结果运行了Wireshark,没有看到SPNEGO令牌正在传递给服务器。

我可以通过web浏览器很好地访问受保护的资源,在本例中,我确实看到了SPNEGO令牌。不过,当我运行我的代码时,情况就不一样了。下面是所讨论的代码:

代码语言:javascript
复制
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文档中获取的。我还做了适当的注册表项更改,如文档中提到的。

你知道是什么导致了这件事吗?或者我该如何进行故障排除?有没有我错过的一步或一条线?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-24 20:30:33

问题解决了。这似乎是由IBM的JDK中的一个bug造成的。一旦我换了太阳,一切都正常。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21996162

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档