Grails 3.2.4:未调用自定义身份验证过滤器
Posted
技术标签:
【中文标题】Grails 3.2.4:未调用自定义身份验证过滤器【英文标题】:Grails 3.2.4 : custom authentication filter not called 【发布时间】:2017-06-14 14:12:18 【问题描述】:从 grails 2.5 升级到 grails 3.x 时,不会触发用户名密码身份验证过滤器。
我正在使用 spring-security 核心插件 3.1.1
这就是自定义过滤器的样子
class CustomAuthenticationFilter extends UsernamePasswordAuthenticationFilter
@Override
protected String obtainUsername(HttpServletRequest request)
return (new CustomPrincipal(request.getParameter('company'), request.getParameter('username'))).toString()
@Override
protected String obtainPassword(HttpServletRequest request)
return request.getParameter('password')
application.groovy
grails.plugin.springsecurity.filterChain.filterNames = [
'securityContextPersistenceFilter',
'logoutFilter',
'customAuthenticationFilter',
'rememberMeAuthenticationFilter',
'anonymousAuthenticationFilter',
'exceptionTranslationFilter',
'filterInvocationInterceptor'
]
resources.grrovy
customAuthenticationFilter(CustomAuthenticationFilter)
authenticationManager = ref('authenticationManager')
sessionAuthenticationStrategy = ref('sessionAuthenticationStrategy')
authenticationFailureHandler = ref('internalAuthenticationFailureHandler')
【问题讨论】:
【参考方案1】:filterNames map要定义如下:
**grails.plugin.springsecurity.filterChain.filterNames**= [
**pattern**:'/**',
**filters**:'securityContextPersistenceFilter',
'logoutFilter',
'customAuthenticationFilter',
'rememberMeAuthenticationFilter',
'anonymousAuthenticationFilter',
'exceptionTranslationFilter',
'filterInvocationInterceptor'
]
【讨论】:
以上是关于Grails 3.2.4:未调用自定义身份验证过滤器的主要内容,如果未能解决你的问题,请参考以下文章
Grails:Spring Security Core 自定义身份验证 getUserByUserName 返回 null 对象