Java 身份验证成功处理程序ref与登录处理url不兼容?
spring-security.xml:Java 身份验证成功处理程序ref与登录处理url不兼容?,java,spring,spring-security,Java,Spring,Spring Security,spring-security.xml: <form-login login-page="/admin/login" login-processing-url="/admin/postlogin" authentication-failure-url="/admin/login?error=true" default-target-url="/admin/dashboard" username-
<form-login
login-page="/admin/login"
login-processing-url="/admin/postlogin"
authentication-failure-url="/admin/login?error=true"
default-target-url="/admin/dashboard"
username-parameter="username"
password-parameter="password"
authentication-success-handler-ref="customAuthenticationSuccessHandler"/>
没有
authentication success handler ref
它工作正常,我被重定向到仪表板,但是有了authentication success handler ref
我在链接/admin/postlogin
上看到一个空白页面。我需要在我的会话中使用这些属性,就像这样,它应该只调用一次。有什么想法吗?您需要从自定义处理程序的onAuthenticationSuccess()方法重定向到正确的URL
private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
@Override
public void onAuthenticationSuccess(HttpServletRequest request,
HttpServletResponse response, Authentication authentication) throws IOException {
//Your custom stuff
handle(request, response, authentication);
}
protected void handle(HttpServletRequest request,
HttpServletResponse response, Authentication authentication) throws IOException {
String targetUrl = "";//Place your target url detection logic here.
redirectStrategy.sendRedirect(request, response, targetUrl);
}
我不能做任何重定向,因为实现了AuthenticationSuccessHandler它只支持void函数我要求做重定向,而不是返回。在您实现自己的成功处理程序时,您有责任确定下一个url(如果成功的话)。将添加一些eamples。
private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
@Override
public void onAuthenticationSuccess(HttpServletRequest request,
HttpServletResponse response, Authentication authentication) throws IOException {
//Your custom stuff
handle(request, response, authentication);
}
protected void handle(HttpServletRequest request,
HttpServletResponse response, Authentication authentication) throws IOException {
String targetUrl = "";//Place your target url detection logic here.
redirectStrategy.sendRedirect(request, response, targetUrl);
}