Java SpringSecurity4,自定义提供程序和处理程序在身份验证之前不缓存url
我在SpringSecurity(v4.0.1)中配置了自定义身份验证提供程序、成功处理程序和失败处理程序。使用默认url时,在显示登录页面后,用户被重定向到先前请求的url。然而,在实现我自己的行为时,我失去了这种行为,所以我正在尝试恢复它 基本上,现在,我每次登录时都会被重定向到主页,即使我访问了登录页面试图获取另一个资源(在我的例子中是/web/users)。这就是我现在的配置: @配置bean(扩展Java SpringSecurity4,自定义提供程序和处理程序在身份验证之前不缓存url,java,spring,spring-security,Java,Spring,Spring Security,我在SpringSecurity(v4.0.1)中配置了自定义身份验证提供程序、成功处理程序和失败处理程序。使用默认url时,在显示登录页面后,用户被重定向到先前请求的url。然而,在实现我自己的行为时,我失去了这种行为,所以我正在尝试恢复它 基本上,现在,我每次登录时都会被重定向到主页,即使我访问了登录页面试图获取另一个资源(在我的例子中是/web/users)。这就是我现在的配置: @配置bean(扩展websecurityConfigureAdapter) 自定义Authenticatio
websecurityConfigureAdapter
)
自定义AuthenticationSuccessHandler
public class SystemAuthenticationSuccessHandler extends
SavedRequestAwareAuthenticationSuccessHandler {
private IUserService service;
public SystemAuthenticationSuccessHandler(IUserService service) {
this.service = service;
setDefaultTargetUrl("/web/home");
}
@Override
public void onAuthenticationSuccess(HttpServletRequest request,
HttpServletResponse response, Authentication authentication)
throws IOException, ServletException {
String username = request.getParameter("username");
User user = service.findByIdOrEmail(username, username);
if (user != null) {
service.saveLoginSuccess(user.getId());
}
//Call the parent method to manage the successful authentication
super.onAuthenticationSuccess(request, response, authentication);
}
基本上,我的问题是requestCache
总是为方法中的当前请求返回null
,这是因为该方法在重定向到登录页面之前与我的传入请求不匹配
具体来说,Spring使用的HttpSessionRequestCache
是一个丢弃所有传入请求的函数。我想让它使用,但不知道如何告诉春天
更新
在HttpSessionRequestCache#setRequestMatcher
中设置了断点,这就是Spring Security设置断点的具体点:
但是,我不知道如何为我的案例设置自定义请求缓存配置器!难道没有更简单的方法吗
更新2
我现在发现这个问题只发生在使用Firefox时,而不是Chrome或Internet Explorer时。这实际上是我当前的Firefox浏览器的问题。即使我删除了所有的导航和缓存数据,这种情况也会继续发生,但在其他浏览器如Chrome或IE上不会发生,即使使用其他FF浏览器也不行。如果您在success listener中唯一要做的事情就是记录一些比使用
ApplicationListener
更好的事情,然后侦听AuthenticationSuccessEvent
s并在那里进行记录。@M.Deinum即使我在配置中更改了默认成功url的成功处理程序,我的问题一直在发生,你也不需要。。。。
public class SystemAuthenticationSuccessHandler extends
SavedRequestAwareAuthenticationSuccessHandler {
private IUserService service;
public SystemAuthenticationSuccessHandler(IUserService service) {
this.service = service;
setDefaultTargetUrl("/web/home");
}
@Override
public void onAuthenticationSuccess(HttpServletRequest request,
HttpServletResponse response, Authentication authentication)
throws IOException, ServletException {
String username = request.getParameter("username");
User user = service.findByIdOrEmail(username, username);
if (user != null) {
service.saveLoginSuccess(user.getId());
}
//Call the parent method to manage the successful authentication
super.onAuthenticationSuccess(request, response, authentication);
}