gpt4 book ai didi

java - Grails中拦截Spring Security获取一些请求参数

转载 作者:行者123 更新时间:2023-11-30 11:43:58 25 4
gpt4 key购买 nike

我想为用户提供在登录时选择应用程序语言的可能性。但是由于我们使用的是 spring security,我真的不确定如何从请求参数中获取选定的语言参数?

有没有什么方法可以在不修改流程本身的情况下拦截 spring security 身份验证流程(因为我已经找到了一些自定义身份验证的示例,但目前不需要)?

或者在进一步重定向之前检索请求参数的最佳做法是什么?谢谢。

最佳答案

您可以在 resources.groovy 中设置您自己的(而不是默认的)身份验证成功处理程序:

authenticationSuccessHandler(MyAuthenticationSuccessHandler) {
}

其中 MyAuthenticationSuccessHandler 是实现 AuthenticationSuccessHandler 的类,或者更好地扩展默认使用的 AjaxAwareAuthenticationSuccessHandler,例如:

authenticationSuccessHandler(AjaxAwareAuthenticationSuccessHandler) {
requestCache = ref('requestCache')
defaultTargetUrl = conf.successHandler.defaultTargetUrl // '/'
alwaysUseDefaultTargetUrl = conf.successHandler.alwaysUseDefault // false
targetUrlParameter = conf.successHandler.targetUrlParameter // 'spring-security-redirect'
ajaxSuccessUrl = conf.successHandler.ajaxSuccessUrl // '/login/ajaxSuccess'
useReferer = conf.successHandler.useReferer // false
redirectStrategy = ref('redirectStrategy')
}

此类可以访问以下位置的实际请求:

void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException;

关于java - Grails中拦截Spring Security获取一些请求参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10982372/

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