2010-02-23 74 views
0

我可以從我的課的retrieveUser方法延伸org.springframework.security.providers.dao.AbstractUserDetailsAuthenticationProvider訪問HTTP會話使用Spring Security登錄進程

如果是這樣,如何內部訪問HTTP Session對象?下面是retrieveUser方法的簽名:

public UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication); 

我想放置在會議上,一些用戶信息,用戶登錄後.....

回答

1

如何使用一個會話作用域的bean無論你需要存儲和填充它的ApplicationListener?您可以定義監聽器(假設你使用Java配置):

@Bean 
public ApplicationListener<AbstractAuthenticationEvent> authenticationListener() { 
    return new MyAuthenticationListener(); 
} 
0

嗯,我的解決辦法是添加數據到UserDetails對象由retrieveUser對象返回。然後我可以使用Spring Security從應用程序中的任何位置檢索數據。