回答

2

Java的春天是不是確切地瞭解應該從getDetails SecurityContext中

我們不能說這樣的 期待,因爲我覺得Spring開發者給了這個選擇安全提供程序實現。

如果您有自定義實現,您的安全提供程序必須使用AbstractAuthenticationToken之一。作爲AbstractAuthenticationToken的一部分,您可以設置細節。 AbstractAuthenticationToken.setDetails(details);

例如,我使用CAS(中央認證服務)。 CAS使用UsernamePasswordAuthenticationToken並設置有DefaultServiceAuthenticationDetails

,下設詳情如下細節:

詳情:org.springframework.secu[email protected]950d14e5:RemoteIpAddress:xxx.xx.xx.xxx ; SESSIONID:A0A0A0A0BB1B1B1B1ServiceUrl:https://local.example.com/test_application/j_spring_cas_security_check

+1

這裏是證明,檢查線#109 http://grepcode.com/file/repo1.maven.org/maven2/org.springframework.security/spring-security-cas-client/3.0.6.RELEASE/組織/ springframework的/安全/ CAS /網絡/ CasAuthenticationFilter。java – ranafeb14

+0

如果我正確理解了你的評論和代碼,這就是Spring **能夠**改變\初始化**細節**的價值的證明,這與其他人已經回答的相反。 – Portable

+0

@Portable,這些值由管理器/過濾器更改,其實現已爲您所知。取決於這個實現,你會期待一個特定的'細節'。 – Andrew

4

期待null,除非你把東西在那裏。

它僅取決於所選的實現和您的操作。你提供這些信息,而不是Spring。 Spring剛剛創建了一個字段,用於保存與身份驗證實例相關的其他數據,並允許您設置所需的所有內容。

編輯:
還有就是Authentication的一個子 - 它定義了getDetails()既不其known implementing classes覆蓋的該方法中,AbstractAuthenticationToken。這意味着setDetails是從外部改變這些細節的一種方式。因此,所有工作都將轉移到一種填充認證的機制(例如AuthenticationManager),通常由您控制。

+0

你怎麼知道的?你能提供一個可靠來源的鏈接嗎? – Portable

0

就是這樣,我們使用細節對象


public class CustomAuthentication implements Authentication { 
    private Object details;

@Override 
public Object getDetails(){ 
    return details; 
} 

/** Sets the details */ 
public void setDetails(Object details){ 
    this.details = details;`enter code here` 
}} 

你可以看到,春節只是支持getDetails()函數,我們可以設置任何東西到這個對象,並且getDetails()將精確返回那些數據。

+0

你怎麼知道的? – Portable

+0

所以,我認爲春季編輯/更新您的數據? – BIZ

+0

在我之前更新或填寫數據。在javadoc中編寫代碼非常簡單:"如果這確實是真的,那麼Spring庫將不會使用該字段"。 – Portable

相關問題