Java Spring安全表单登录属性的动态配置
使用表单登录进行身份验证。我需要能够从数据库表中配置失败url和成功url,以便配置应用程序的其他方面 此验证用户身份的应用程序链接到此服务器或其他服务器上的其他应用程序,我需要在用户注销时返回该服务器或转到该服务器Java Spring安全表单登录属性的动态配置,java,spring,spring-mvc,spring-security,Java,Spring,Spring Mvc,Spring Security,使用表单登录进行身份验证。我需要能够从数据库表中配置失败url和成功url,以便配置应用程序的其他方面 此验证用户身份的应用程序链接到此服务器或其他服务器上的其他应用程序,我需要在用户注销时返回该服务器或转到该服务器 <form-login authentication-success-handler-ref="authenticationSuccessHandler" always-use-default-target="true"
<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"/>
如何动态更改这些属性?我认为您无法动态配置它们-最好指向读取数据库属性的控制器方法,然后重定向到相应的页面
@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");
}
听起来您有逻辑处理来确定用户实际到达的位置。如果我是你,我会连接你的属性,让另一个控制器根据你的规则和重定向处理请求
<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
}
}