0
我有一個Linux \的Java6客戶端,將認證通過Kerberos sharepoint2010,然後使用Apache的百科全書發送HTTP REST Web服務的HttpClient 4.2設置用戶名編程,而不是迅速,與HttpClient的 Kerberos的
如果我從命令運行行"kinit [email protected]"
之前連接我的客戶端運行平穩。
我的問題是,如果我不運行kinit,我會提示輸入用戶名。
如何在不提示用戶名的情況下以編程方式進行身份驗證,而無需運行命令行程序?
(我創建和密鑰表和login.conf中定義它,以便照顧密碼提示,但不是用戶PROMT的)
public static void main(String[] args) throws Exception {
System.setProperty("java.security.auth.login.config", "login.conf");
System.setProperty("java.security.krb5.conf", "krb5.conf");
System.setProperty("sun.security.krb5.debug", "true");
System.setProperty("javax.security.auth.useSubjectCredsOnly","false");
DefaultHttpClient httpclient = new DefaultHttpClient();
try {
httpclient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory());
Credentials use_jaas_creds = new Credentials() {
public String getPassword() {
return null;
}
public Principal getUserPrincipal() {
return null;
}
};
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(null, -1, null),
use_jaas_creds);
HttpUriRequest request = new HttpGet("http://kerberoshost/");
HttpResponse response = httpclient.execute(request);
HttpEntity entity = response.getEntity();
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
System.out.println("----------------------------------------");
if (entity != null) {
System.out.println(EntityUtils.toString(entity));
}
System.out.println("----------------------------------------");
// This ensures the connection gets released back to the manager
EntityUtils.consume(entity);
} finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}
}
請發表您的login.config文件指的是您創建的密鑰表。 –
我回答了這裏非常類似的東西: http://stackoverflow.com/questions/21629132/httpclient-set-credentials-for-kerberos-authentication/23679954#23679954 – eljeko