2012-04-13 87 views
0

使用表单登录进行身份验证。我需要能够配置我们用于配置应用程序的其他方面的数据库表中的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"); 
}