2016-12-04 96 views
0

我在使用Grails 3中的Spring Security Rest plugin,但我遇到了篩選鏈問題。Grails Spring Security Rest:restTokenValidationFilter不起作用

我想要完成的是安全上下文已初始化,但匿名訪問仍應可能。

我filterchain是

anonymousAuthenticationFilter, restTokenValidationFilter,restExceptionTranslationFilter 

但在應用程序啓動時出現錯誤

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ' restTokenValidationFilter' is defined 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:698) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1175) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) 
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1060) 
    at grails.plugin.springsecurity.SpringSecurityUtils$_buildFilterChains_closure6.doCall(SpringSecurityUtils.groovy:794) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1426) 
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) 
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) 
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294) 
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021) 
    at groovy.lang.Closure.call(Closure.java:426) 
    at groovy.lang.Closure.call(Closure.java:442) 
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.collect(DefaultGroovyMethods.java:3124) 
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.collect(DefaultGroovyMethods.java:3095) 
    at grails.plugin.springsecurity.SpringSecurityUtils.buildFilterChains(SpringSecurityUtils.groovy:794) 
    at grails.plugin.springsecurity.SpringSecurityUtils$buildFilterChains$3.call(Unknown Source) 
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149) 
    at grails.plugin.springsecurity.SpringSecurityCoreGrailsPlugin.doWithApplicationContext(SpringSecurityCoreGrailsPlugin.groovy:682) 
    at org.grails.plugins.DefaultGrailsPlugin.doWithApplicationContext(DefaultGrailsPlugin.java:524) 
    at org.grails.plugins.AbstractGrailsPluginManager.doPostProcessing(AbstractGrailsPluginManager.java:229) 
    at grails.boot.config.GrailsApplicationPostProcessor.onApplicationEvent(GrailsApplicationPostProcessor.groovy:231) 
    at grails.boot.config.GrailsApplicationPostProcessor.onApplicationEvent(GrailsApplicationPostProcessor.groovy) 
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:163) 
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:136) 
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:381) 
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:335) 
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:855) 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:140) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) 
    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) 
    at grails.boot.GrailsApp.run(GrailsApp.groovy:55) 
    at grails.boot.GrailsApp.run(GrailsApp.groovy:365) 
    at grails.boot.GrailsApp.run(GrailsApp.groovy:354) 
    at grails.boot.GrailsApp$run.call(Unknown Source) 
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) 
    at com.me.Application.main(Application.groovy:8) 

我檢查和插件包含RestTokenValidationFilter類,所以我不明白,爲什麼bean是未找到。

爲了達到這個目的,我嘗試將該類添加到resource.groovy文件中,但它仍然無效。

是我的過濾鏈中的問題還是我缺少其他東西?

回答

0

實測溶液1分鐘發佈後:/

正確的過濾器鏈(from the docs)爲:

anonymousAuthenticationFilter,restTokenValidationFilter,restExceptionTranslationFilter,filterInvocationInterceptor