jeffwils / grails-spring-security-saml

Grails Spring Security SAML2.0 Plugin for Grails 3
8 stars 24 forks source link

Setting saml.active to false results in bean creation issues when running integration tests #49

Closed irstevenson closed 1 year ago

irstevenson commented 6 years ago

As per matrix discussion @ https://matrix.to/#/!FUjEjFPHmocIJkjrBw:istevenson.net/$1528950176106derpu:istevenson.net :

I've attempted to disable the SAML plugin when running my integration tests with this application.yml sitting in my working dir:

---
grails:
  plugin:
    springsecurity:
      providerNames: ['daoAuthenticationProvider', 'anonymousAuthenticationProvider', 'rememberMeAuthenticationProvider']
      saml:
        active: false

But unfortunately, when doing ./gradlew integrationTest all my tests failed with:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecuritySamlSamlSecurityService': Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'grails.plugin.springsecurity.userdetails.GormUserDetailsService' to required type 'org.grails.plugin.springsecurity.saml.SpringSamlUserDetailsService' for property 'userDetailsService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'grails.plugin.springsecurity.userdetails.GormUserDetailsService' to required type 'org.grails.plugin.springsecurity.saml.SpringSamlUserDetailsService' for property 'userDetailsService': no matching editors or conversion strategy found
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078)
    at org.spockframework.spring.SpringMockTestExecutionListener.beforeTestMethod(SpringMockTestExecutionListener.java:54)
    at org.spockframework.spring.AbstractSpringTestExecutionListener.beforeTestMethod(AbstractSpringTestExecutionListener.java:23)
    at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:269)
    at org.spockframework.spring.SpringTestContextManager.beforeTestMethod(SpringTestContextManager.java:54)
    at org.spockframework.spring.SpringInterceptor.interceptSetupMethod(SpringInterceptor.java:45)
    at org.spockframework.runtime.extension.AbstractMethodInterceptor.intercept(AbstractMethodInterceptor.java:28)
    at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:114)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:57)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:66)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:147)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:129)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:46)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'grails.plugin.springsecurity.userdetails.GormUserDetailsService' to required type 'org.grails.plugin.springsecurity.saml.SpringSamlUserDetailsService' for property 'userDetailsService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'grails.plugin.springsecurity.userdetails.GormUserDetailsService' to required type 'org.grails.plugin.springsecurity.saml.SpringSamlUserDetailsService' for property 'userDetailsService': no matching editors or conversion strategy found
    at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:603)
    at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:615)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:216)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1577)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1536)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
    ... 32 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type 'grails.plugin.springsecurity.userdetails.GormUserDetailsService' to required type 'org.grails.plugin.springsecurity.saml.SpringSamlUserDetailsService' for property 'userDetailsService': no matching editors or conversion strategy found
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:306)
    at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:588)
    ... 38 more

Mind you, it all works fine if I just do ./gradlew bootRun - i.e. I can even login with some users (via form auth) which I have created in the DB.

Grails version: 3.3.2 Plugin version: 3.3.1-SNAPSHOT

irstevenson commented 6 years ago

@valentingoebel provided this advice in matrix:

SamlSecurityService has a dependency on SpringSamlUserDetailsService userDetailsService but I believe it's not actually using it so we could perhaps remove that code.

I've not had a chance to look at that, but sounds good. :+1:

zhimoud commented 5 years ago

I think the problem you are having here is disabling SAML is not taking effect as it's disabled in the code: https://github.com/jeffwils/grails-spring-security-saml/blob/8050170175ada8fa9422cf00b5695eaa0c65267e/src/main/groovy/org/grails/plugin/springsecurity/saml/SpringSecuritySamlGrailsPlugin.groovy#L79-L84

to solve this you could uncomment line 84 or add "|| !conf.saml.active" to the if statment on line 80: if (!conf || !conf.active || !conf.saml.active) { return }

valentingoebel commented 1 year ago

Works as expected.