SPNEGO授权:我的浏览器如何在没有额外配置的情况下成功,并且我的Java代码失败了?

时间:2016-09-06 14:52:42

标签: java authentication authorization kerberos spnego

我在Java中看到的用于SPNEGO授权的所有示例都涉及包括“login.conf”和“krb.conf”等配置文件,但Chrome在没有这些文件的情况下成功(在查询name / pwd之后)。我也可以用curl成功查询。

目前我的代码失败,出现“NEGOTIATE身份验证错误:提供的名称无效(机制级别:KrbException:找不到默认域名)”...

Lookup<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(skipPortAtKerberosDatabaseLookup))
.build();

CloseableHttpClient client = HttpClients.custom().setDefaultAuthSchemeRegistry(authSchemeRegistry).build();
HttpClientContext context = HttpClientContext.create();
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();

Credentials defaultCreds = new UsernamePasswordCredentials(username, password);
credentialsProvider.setCredentials(new AuthScope(null, -1, null), defaultCreds );
context.setCredentialsProvider(credentialsProvider);

HttpGet httpget = new HttpGet(url);
CloseableHttpResponse response = client.execute(httpget,context);
String responseString = IOUtils.toString(response.getEntity().getContent());

System.out.println(responseString);

我在这里做错了什么想法?

谢谢!

0 个答案:

没有答案