简体   繁体   English

Grails Spring安全身份验证提供程序和自定义过滤器

[英]Grails spring security authentication provider and custom filter

I'm new to the grails language and am using grails 2.5.6 with spring-security-core 2.0.0 plugin at work. 我是grails语言的新手,正在使用带有grails 2.5.6和spring-security-core 2.0.0插件的Grails。

I've defined my provider as this in the config.groovy file: 我已经在config.groovy文件中将提供程序定义为:

grails.plugin.springsecurity.providerNames = [
    'myCustomAuthenticationProvider',
    'anonymousAuthenticationProvider',
    'rememberMeAuthenticationProvider'
]

and my filter as: 和我的过滤器为:

grails.plugin.springsecurity.filterChain.filterNames = [
    'securityContextPersistenceFilter',
    'myCustomFilter',
    'exceptionTranslationFilter', 
    'anonymousAuthenticationFilter',
    'filterInvocationInterceptor'
]

My resources.groovy file: 我的resources.groovy文件:

myCustomAuthenticationProvider(MyCustomAuthenticationProvider)
myCustomFilter(myCustomFilter)

Both my filter and provider are java classes provided by a jar. 我的过滤器和提供程序都是jar提供的Java类。 The filter extends OncePerRequestFilter and has the AuthenticationManager and AuthenticationEntryPoint injected. 该过滤器扩展了OncePerRequestFilter ,并注入了AuthenticationManagerAuthenticationEntryPoint My provider implements AuthenticationProvider 我的提供者实现了AuthenticationProvider

The problem is when I put a debug point in my filter to see the AuthenticationManager and see the `AuthenticationProviders that are in it's list, I don't see my custom provider at all. 问题是,当我在过滤器中放置调试点以查看AuthenticationManager并查看列表中的“ AuthenticationProviders”时,根本看不到我的自定义提供程序。 I still see the default spring-security-core plugin providers. 我仍然看到默认的spring-security-core插件提供程序。

I also don't understand why my custom filter gets initiated even if I remove it from the list of filters. 即使我从过滤器列表中将其删除,我也不理解为什么启动自定义过滤器。 It seems like just defining it in the resources.groovy file is enough for it to get initiated. 似乎只需在resources.groovy文件中对其进行定义就足以启动它。

Just realized that the reason it gets initiated is because on startup it is being added to the spring container. 刚意识到它被启动的原因是因为在启动时将其添加到弹簧容器中。

Thanks 谢谢

Figured it out. 弄清楚了。 I ended up not defining the filterNames and in my resources.groovy file I have this: 我最终没有定义filterNames,在我的resources.groovy文件中我有以下内容:

authenticationProcessingFilter(MyCustomFilter) {
    ...args
}

And the issue with my provider on construction getting the providers doesn't matter. 我的提供者在构建获取提供者方面的问题并不重要。 Turns out spring security core doesn't change it until after that. 事实证明,Spring安全核心直到那之后才对其进行更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM