2012-08-16 142 views
0

我運行一個代碼,就像登錄:春季安全手動重定向(代碼,無需配置)

public String login(String username,String password){ 
    Authentication request = new UsernamePasswordAuthenticationToken(username,password); 
       Authentication result = authenticationManager.authenticate(request); 
       SecurityContextHolder.getContext().setAuthentication(result); 
return null; 
       } 

我不使用JSF和不知道如何成功登錄後的頁面重定向到請求的安全頁面。

我在使用它時正在獲取facesContext,但現在我沒有使用。

如何通過代碼重定向?

回答

1

只返回視圖檢查isAuthenticated()後,像這樣:

if (authenticationResponseToken.isAuthenticated()) { 
      //lookup authentication success url, or find redirect parameter from login bean 
      return "/secure/examples"; 
} 

參見: