2012-04-13 10 views
0

認証にform-loginを使用します。私はアプリケーションの他の側面を設定するために持っているデータベーステーブルからfailure-urlとsuccess-urlを設定できる必要があります。Spring Securityのフォームログイン属性の動的設定

このユーザーを認証するアプリケーションは、このサーバーまたは別のサーバー上にある可能性がある別のアプリケーションからリンクされています。ユーザーがログアウトしたときにそこにフェイルバックするか、そこに移動する必要があります。

<form-login authentication-success-handler-ref="authenticationSuccessHandler" 
        always-use-default-target="true" 
        authentication-failure-url="**/failureurl.aspx**" 
        default-target-url="/home/configuration"/> 
<logout logout-success-url="**/successurl.aspx**" invalidate-session="true"/> 

これらの属性を変更するにはどうすればよいですか?

答えて

1

実際にユーザーが実際にどこに着陸するかを決定するロジック処理のようです。私があなたの場合は、あなたのルールとそこからのリダイレクトに基づいて要求を処理する別のコントローラによって傍受されるように属性を配線します。

<form-login authentication-success-handler-ref="authenticationSuccessHandler" 
       always-use-default-target="true" 
       authentication-failure-url="/redirect/failure" 
       default-target-url="/home/configuration"/> 

そして:

@Controller 
@RequestMapping("/redirect/failure") 
public class Redirector 
{ 
    public String doFailureRedirection(HttpServletRequest request, Model model) 
    { 
      //check where user is supposed to go and return 
    } 
} 
1

動的に構成することはできないと思います。データベースプロパティを読み取って適切なページにリダイレクトするコントローラメソッドを指している方がよいでしょう。

@RequestMapping(value = {"", "/", "/index"}, method = RequestMethod.GET) 
public ModelAndView redirectToHomepage(HttpServletRequest request) { 
    // If not logged in, then go to the landing page. 
    if (request.getUserPrincipal() == null) { 
     return new ModelAndView("redirect:/"); 
    } 

    if (request.isUserInRole("ROLE_ADMIN")) { 
     return new ModelAndView("redirect:/admin"); 
    } 
    return new ModelAndView("redirect:/dashboard"); 
}