gpt4 book ai didi

grails - 无法覆盖 AuthenticationSuccessHandler 的 onAuthenticationSuccess 方法

转载 作者:行者123 更新时间:2023-12-02 15:43:17 25 4
gpt4 key购买 nike

在其他一些帖子之后,我尝试覆盖 spring-security 处理程序的身份验证成功方法,但它从未被调用。我的代码如下所示:
src/groovy/mypackage/MyAuthenticationSuccessHandler.groovy :

package mypackage

import org.springframework.security.core.Authentication
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler

import javax.servlet.ServletException
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

public class MyAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {
public MyAuthenticationSuccessHandler() {
println("constructed!")
}
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
println("override called")
super.onAuthenticationSuccess(request, response, authentication);
}
}

资源.groovy:
authenticationSuccessHandler(MyAuthenticationSuccessHandler) {
def conf = SpringSecurityUtils.securityConfig
requestCache = ref('requestCache')
defaultTargetUrl = conf.successHandler.defaultTargetUrl
alwaysUseDefaultTargetUrl = conf.successHandler.alwaysUseDefault
targetUrlParameter = conf.successHandler.targetUrlParameter
useReferer = conf.successHandler.useReferer
redirectStrategy = ref('redirectStrategy')
}

没有错误,构造函数肯定被调用和 MyAuthenticationSuccessHandler被注入(inject)测试 Controller ,但 onAuthenticationSuccess永远不会被调用。我在父类(super class)版本中放置了一个断点,并且有效。我也尝试用 java 重写我的自定义类,但这没有用。

我究竟做错了什么?

最佳答案

原来另一个登录过滤器已经处于事件状态,它阻止了正常方法的工作。有问题的过滤器是 org.mitre.openid.connect.client.OIDCAuthenticationFilter解决方法是通过那个注入(inject)您的成功处理程序,例如:

    authenticationSuccessHandler(apipulse.MyAuthenticationSuccessHandler) {
clientRegistrationTemplate = ref(clientRegistrationTemplate)
}

...

openIdConnectAuthenticationFilter(OIDCAuthenticationFilter) {
...
authenticationSuccessHandler = ref('authenticationSuccessHandler')
}

只是浪费了一天的时间看这个 - 非常感谢, Spring 。

关于grails - 无法覆盖 AuthenticationSuccessHandler 的 onAuthenticationSuccess 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54291700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com