Apache HttpClient 4.3을 사용하여 SPNEGO (Windows 통합 인증) 용으로 구성된 IIS를 실행중인 Windows 서버에 인증을 시도하고 있습니다. 내 코드는 온라인에서 찾을 수 있었던 샘플 코드의 코드와 매우 비슷하게 보이지만 실행하면 일관되게 HTTP 401이 반환됩니다. 결과에서 Wireshark를 실행했는데 SPNEGO 토큰이 서버로 전달되는 것을 보지 못했습니다.SPNEGO HttpClient를 통한 인증
보호 된 리소스를 웹 브라우저를 통해 정상적으로 공격 할 수 있습니다.이 경우 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 파일은 아파치 HttpClient를 문서에서 직접 가져온 것입니다. 또한 문서에서 언급 한 것처럼 적절한 레지스트리 키를 변경했습니다.
어떤 문제가 발생했는지 또는 문제 해결 방법을 알 수 있습니까? 내가 누락 된 단계가 있습니까?
ibm jdk에는 sun jdk와 다른 jaas 매개 변수가 있습니다. 올바른 것을 사용하고 있습니까? IBM JDK는 도청되지 않았으므로 HTTP Client를 사용할 수 있습니다. –