2015-09-20 49 views
-1

我正在使用自定義UsernamePasswordAuthenticationFilter(它在登錄頁面之前調用)。我正在考慮此過濾器中已登錄用戶的會話ID。如果auth_token存在相應的會話ID,我想繞過登錄頁面。如何繞過spring security中的登錄表單頁面?

我該怎麼做?

+0

github中有許多spring安全項目可以工作。其中一個人可以幫助回答你的問題嗎?我不在計算機上提供更多細節。 –

回答

0

一旦您檢查了auth_token,您只需使用經過身份驗證的身份驗證安全上下文。類似的東西(在你的自定義過濾器):

... // first check the existence of the auth_token and extract some information from it like user name and roles 
String login = ... 
String role = ... 
PreAuthenticatedAuthenticationToken preAuthenticatedAuthenticationToken 
        = new PreAuthenticatedAuthenticationToken(login, auth_token, Collections.singleton(new SimpleGrantedAuthority(role))); 
SecurityContextHolder.getContext().setAuthentication(preAuthenticatedAuthenticationToken); 
//At this point : the security context contains an authenticated Authentication and other security filters won't have any impact anymore 

我不說這是您所需要的最佳方法,但它會隨着或多或少的標準彈簧安全配置工作。

相關問題