【问题标题】:Why RememberMeAuthenticationFilter does not redirect to requested url?为什么 RememberMeAuthenticationFilter 不重定向到请求的 url?
【发布时间】:2020-08-08 12:23:24
【问题描述】:

我是 Spring Security 的新手,很抱歉我的英语不好。
我有一个 rememberme cookie,当请求到达过滤器时,RememberMeAuthenticationFilter - 它进行身份验证,中断下一个处理并立即返回用户只有 200 个状态,默认 URL,类似于

{"redirectTo":"/","success":true,"username":"userName","roles":[listOfRoles]}

在这里

public RememberMeAuthenticationFilter(AuthenticationManager authenticationManager,
        RememberMeServices rememberMeServices) {

   public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    ...
    if (successHandler != null) {   // <<<<<<<<<<<<<<<<<In here the request breaks.
                            successHandler.onAuthenticationSuccess(request, response,
                                    rememberMeAuth);

                            return;
                        }
    ...
    chain.doFilter(request, response);
    }
}

请告诉我下一步该怎么做:请求失败,在使用 rememberme cookie 成功认证后将过滤器扔到 chain.doFilter(request, response); 毕竟过滤器转到用户要求的控制器方法。

【问题讨论】:

    标签: spring authentication spring-security


    【解决方案1】:

    如果有人感兴趣,我会找到解决方案。解决方案不是将 authenticationSuccessHandler 注入到 RememberMeAuthenticationFilter。我重新定义了 bean RememberMeAuthenticationFilter(默认情况下在 grails 中定义)并且没有注入 authenticationSuccessHandler。这就是为什么这段代码不处理并转到chain.doFilter的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-15
      • 2015-05-20
      • 1970-01-01
      • 1970-01-01
      • 2021-08-15
      • 2015-03-02
      • 1970-01-01
      相关资源
      最近更新 更多