Grails应用程序未与过滤器一起运行

时间:2018-07-28 21:30:25

标签: grails spring-security

我正在尝试向应用程序添加过滤器。关于过滤器,有很多信息,包括官方的Spring Security插件:http://grails-plugins.github.io/grails-spring-security-core/2.0.x/guide/single.html#filters。我也找到了一个简单的示例:https://www.djamware.com/post/58a53b5180aca748640ce350/securing-rest-api-with-grails-3-and-spring-security-rest

我的第一个想法是:我的grails或安全性插件版本出了点问题……但是每次在任何版本上添加过滤器时,我都会出错!我尝试了Grails 2.4.3、2.5 *,3.3.6。与spring seciruty核心插件相同。

添加任何过滤器链,例如:

grails.plugin.springsecurity.filterChain.chainMap = [
  [pattern: '/api/**', filters:'JOINED_FILTERS,-anonymousAuthenticationFilter,-exceptionTranslationFilter,-authenticationProcessingFilter,-securityContextPersistenceFilter'],
  [pattern: '/**', filters:'JOINED_FILTERS,-restTokenValidationFilter,-restExceptionTranslationFilter']
]

Grails v3.3.6错误

java.lang.NoClassDefFoundError: org/springframework/boot/context/embedded/FilterRegistrationBean
        at grails.plugin.springsecurity.SpringSecurityCoreGrailsPlugin$_doWithSpring_closure12.doCall(SpringSecurityCoreGrailsPlugin.groovy:204)
        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:1427)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:264)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
        at groovy.lang.Closure.call(Closure.java:418)
        at groovy.lang.Closure.call(Closure.java:412)
        at grails.spring.BeanBuilder.invokeBeanDefiningClosure(BeanBuilder.java:759)
        at grails.spring.BeanBuilder.beans(BeanBuilder.java:588)
        at grails.spring.BeanBuilder.invokeMethod(BeanBuilder.java:531)
        at org.grails.plugins.DefaultGrailsPlugin.doWithRuntimeConfiguration(DefaultGrailsPlugin.java:559)
        at org.grails.plugins.AbstractGrailsPluginManager.doRuntimeConfiguration(AbstractGrailsPluginManager.java:167)
        at grails.boot.config.GrailsApplicationPostProcessor.postProcessBeanDefinitionRegistry(GrailsApplicationPostProcessor.groovy:171)
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:272)
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:122)
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:84)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:393)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:380)
        at grails.boot.GrailsApp$run.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:136)
        at mysecurerest.Application.main(Application.groovy:8)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.FilterRegistrationBean
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 34 common frames omitted

Grails 2.4.3错误

ERROR context.GrailsContextLoaderListener  - Error initializing the application: No signature of method: SpringSecurityCoreGrailsPlugin$_closure4_closure56.doCall() is applicable for argument types: (java.util.LinkedHashMap) values: [[pattern:/api/**, filters:JOINED_FILTERS,-anonymousAuthenticationFilter,-exceptionTranslationFilter,-authenticationProcessingFilter,-securityContextPersistenceFilter]]
Possible solutions: doCall(java.lang.Object, java.lang.Object), call(), call([Ljava.lang.Object;), call(java.lang.Object), call(java.lang.Object, java.lang.Object), findAll()
Message: No signature of method: SpringSecurityCoreGrailsPlugin$_closure4_closure56.doCall() is applicable for argument types: (java.util.LinkedHashMap) values: [[pattern:/api/**, filters:JOINED_FILTERS,-anonymousAuthenticationFilter,-exceptionTranslationFilter,-authenticationProcessingFilter,-securityContextPersistenceFilter]]
Possible solutions: doCall(java.lang.Object, java.lang.Object), call(), call([Ljava.lang.Object;), call(java.lang.Object), call(java.lang.Object, java.lang.Object), findAll()
    Line | Method
->>  631 | doCall    in SpringSecurityCoreGrailsPlugin$_closure4
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    266 | run       in java.util.concurrent.FutureTask
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . in java.lang.Thread

ERROR Exception sending context initialized event to listener
instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener
Message: Error executing bootstraps; nested exception is groovy.lang.MissingMethodException: No signature of method: SpringSecurityCoreGrailsPlugin$_closure4_closure56.doCall() is applicable for argument types: (java.util.LinkedHashMap) values: [[pattern:/api/**, filters:JOINED_FILTERS,-anonymousAuthenticationFilter,-exceptionTranslationFilter,-authenticationProcessingFilter,-securityContextPersistenceFilter]]
Possible solutions: doCall(java.lang.Object, java.lang.Object), call(), call([Ljava.lang.Object;), call(java.lang.Object), call(java.lang.Object, java.lang.Object), findAll()
    Line | Method
->>  266 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Caused by MissingMethodException: No signature of method: SpringSecurityCoreGrailsPlugin$_closure4_closure56.doCall() is applicable for argument types: (java.util.LinkedHashMap) values: [[pattern:/api/**, filters:JOINED_FILTERS,-anonymousAuthenticationFilter,-exceptionTranslationFilter,-authenticationProcessingFilter,-securityContextPersistenceFilter]]
Possible solutions: doCall(java.lang.Object, java.lang.Object), call(), call([Ljava.lang.Object;), call(java.lang.Object), call(java.lang.Object, java.lang.Object), findAll()
->>  631 | doCall    in SpringSecurityCoreGrailsPlugin$_closure4
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    266 | run       in java.util.concurrent.FutureTask
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . in java.lang.Thread

我在做什么错?还是错过了什么?

1 个答案:

答案 0 :(得分:0)

我不确定如何操作,但是在Grails 3问题解决后,我已经让Grails 2使用过滤器了!

所以我的解决方案是:

  1. 尝试使用不同的Java,Grails和spring-security-core版本(2和3)。
  2. @Koloritnij建议检查Grails 3.3.6 + org.grails.plugins:spring-security-core:3.2.3(在Java 1.8.0.181上运行)后,我能够正确运行带有过滤器的Grails 3项目。 / li>
  3. 回到我的Java 1.8.0.25 + Grails 2.4.3 + spring-security-core:2.0.0,它可以正常工作!