grails / grails-spring-security-core

Grails Spring Security Core Plugin
Apache License 2.0
261 stars 223 forks source link

Metadata.current.getGrailsVersion() returns null #1033

Closed gsartori closed 3 weeks ago

gsartori commented 1 month ago

Expected Behavior

It should just work

Actual Behaviour

Configuring Spring Security Core ...
15:12:09.626 ERROR [main] o.s.boot.SpringApplication               : Application run failed
java.lang.NullPointerException: Cannot invoke method startsWith() on null object
    at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:113)
    at org.codehaus.groovy.vmplugin.v8.IndyGuardsFiltersAndSignatures.invokeGroovyObjectInvoker(IndyGuardsFiltersAndSignatures.java:151)
    at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
    at grails.plugin.springsecurity.SpringSecurityCoreGrailsPlugin$_doWithSpring_closure12$_closure49.doCall(SpringSecurityCoreGrailsPlugin.groovy:229)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:343)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:328)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:279)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1007)
    at groovy.lang.Closure.call(Closure.java:433)
    at grails.spring.BeanBuilder.invokeBeanDefiningMethod(BeanBuilder.java:708)
    at grails.spring.BeanBuilder.invokeMethod(BeanBuilder.java:565)
    at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:651)
    at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:628)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeOnDelegationObjects(ClosureMetaClass.java:405)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:328)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1007)
    at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
    at grails.plugin.springsecurity.SpringSecurityCoreGrailsPlugin$_doWithSpring_closure12.doCall(SpringSecurityCoreGrailsPlugin.groovy:220)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:343)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:328)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:279)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1007)
    at groovy.lang.Closure.call(Closure.java:433)
    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:545)
    at org.grails.plugins.AbstractGrailsPluginManager.doRuntimeConfiguration(AbstractGrailsPluginManager.java:152)
    at grails.boot.config.GrailsApplicationPostProcessor.postProcessBeanDefinitionRegistry(GrailsApplicationPostProcessor.groovy:155)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:349)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:148)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:789)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:607)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:335)
    at grails.boot.GrailsApp.run(GrailsApp.groovy:87)
    at grails.boot.GrailsApp.run(GrailsApp.groovy:392)
    at grails.boot.GrailsApp.run(GrailsApp.groovy:379)
    at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
    at dueuno.elements.test.Application.main(Application.groovy:31)

Steps To Reproduce

  1. Download the project: https://github.com/dueuno-projects/dueuno-elements/tree/feature/grails-7
  2. ./gradlew :app-test:bootRun

Environment Information

No response

Example Application

https://github.com/dueuno-projects/dueuno-elements/tree/feature/grails-7

Version

7.0.0

codeconsole commented 3 weeks ago

That is due to where the plugin is putting the filter chain.

https://github.com/grails/grails-spring-security-core/blob/5b20efd9368424aec7d1582f74757a8ec0ceb21d/plugin/src/main/groovy/grails/plugin/springsecurity/SpringSecurityCoreGrailsPlugin.groovy#L220-L235

"has to be after grailsWebRequestFilter"

codeconsole commented 3 weeks ago

Fixed with https://github.com/grails/grails-spring-security-core/commit/c7e7725cf7d7a6e60412a4b9ea447eefda6e4ec7