2012-11-29 199 views
2

我正在嘗試從使用JAVA的Active Directory獲取用於身份驗證的TGT。無法從AD獲得TGT

這是我的代碼:

try 
{ 
    URL localURL = super.getClass().getResource("jaas_ntlm_configuration.txt"); 
    System.setProperty("java.security.auth.login.config", localURL.toString()); 

    LoginContext localLoginContext = new LoginContext("GetLoginNameKerberos", new SampleCallbackHandler()); 

    localLoginContext.login(); 

    Subject localSubject = localLoginContext.getSubject(); 

    ..... 
} 
catch (LoginException localLoginException) { 
    localLoginException.printStackTrace(); 
} 

此代碼的工作在一臺服務器上,但是,其他服務器上的失敗 「localLoginContext.login();」與此輸出:

>>>KinitOptions cache name is C:\Users\x\krb5cc_x 
LSA: Found Ticket 
LSA: Made NewWeakGlobalRef 
LSA: Found PrincipalName 
LSA: Made NewWeakGlobalRef 
LSA: Found DerValue 
LSA: Made NewWeakGlobalRef 
LSA: Found EncryptionKey 
LSA: Made NewWeakGlobalRef 
LSA: Found TicketFlags 
LSA: Made NewWeakGlobalRef 
LSA: Found KerberosTime 
LSA: Made NewWeakGlobalRef 
LSA: Found String 
LSA: Made NewWeakGlobalRef 
LSA: Found DerValue constructor 
LSA: Found Ticket constructor 
LSA: Found PrincipalName constructor 
LSA: Found EncryptionKey constructor 
LSA: Found TicketFlags constructor 
LSA: Found KerberosTime constructor 
LSA: Finished OnLoad processing 
>> Acquire default native Credentials 
LSA: Found KrbCreds constructor 
LSA: Got handle to Kerberos package 
LSA: Response size is 1556 
LSA: Principal domain is SUB.DOMAIN.COM 
LSA: Name type is 1 
LSA: Name count is 1 
LSA: Principal domain is SUB.DOMAIN.COM 
LSA: Name type is 2 
LSA: Name count is 2 
LSA: Session key all zero. Stop. 
>>> Found no TGT's in LSA 
javax.security.auth.login.LoginException: Unable to obtain Princpal Name for authentication 
    at com.sun.security.auth.module.Krb5LoginModule.promptForName(Unknown Source) 
    at com.sun.security.auth.module.Krb5LoginModule.attemptAuthentication(Unknown Source) 
    at com.sun.security.auth.module.Krb5LoginModule.login(Unknown Source) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at javax.security.auth.login.LoginContext.invoke(Unknown Source) 
    at javax.security.auth.login.LoginContext.access$000(Unknown Source) 
    at javax.security.auth.login.LoginContext$4.run(Unknown Source) 
    at javax.security.auth.login.LoginContext$4.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at javax.security.auth.login.LoginContext.invokePriv(Unknown Source) 
    at javax.security.auth.login.LoginContext.login(Unknown Source) 
    at my.test.MyTest.main(MyTest.java:123) 

你能幫我理解是什麼問題?

謝謝。

+0

回調處理程序可能有問題。它即將提示輸入用戶名時失敗。 –

回答

6

如果您不希望輸入用戶名(您希望單點登錄),那麼您的問題是一個已知問題:LSA API不會移交TGT的會話密鑰,因爲這被認爲是安全漏洞。錯誤信息清楚地表明,這正是發生的情況。

有一個Windows註冊表項AllowTGTSessionKey,您可以將其設置爲true以禁用此限制,但此設置是每個工作站而不是每個服務器,因此它是否不清楚它是如此工作的在一個地方而不在另一個地方。另一個原因可能是Windows版本,因爲這是在XP Service Pack 2中引入的,如果我沒有記錯的話。

在Java中實現單點登錄的正確方法是將TGT的處理委託給Windows SSPI,這是一種類似於GSS-API的高級API。有一個很好的圖書館可以幫助你,我可以親自推薦:WAFFLE。

+0

以下是更多信息:http://www.javaactivedirectory.com/?page_id=93 –