简体   繁体   中英

Spring Bean not found for Spring Security RememberMe?

In my Grails app with Spring Security I want to initialize the following Spring bean in conf/spring/resource.groovy:

beans = { 

    if (grailsApplication.config.grails.plugins.springsecurity.rememberMe.persistent) {
        rememberMeServices(MyPersistentTokenBasedRememberMeService) {
            userDetailsService = ref('userDetailsService')
            key = grailsApplication.config.grails.plugins.springsecurity.rememberMe.key
            cookieName = grailsApplication.config.grails.plugins.springsecurity.rememberMe.cookieName
            alwaysRemember = grailsApplication.config.grails.plugins.springsecurity.rememberMe.alwaysRemember
            tokenValiditySeconds = grailsApplication.config.grails.plugins.springsecurity.rememberMe.tokenValiditySeconds
            parameter = grailsApplication.config.grails.plugins.springsecurity.rememberMe.parameter
            useSecureCookie = grailsApplication.config.grails.plugins.springsecurity.rememberMe.useSecureCookie // false

            tokenRepository = ref('tokenRepository')
            seriesLength = grailsApplication.config.grails.plugins.springsecurity.rememberMe.persistentToken.seriesLength // 16
            tokenLength = grailsApplication.config.grails.plugins.springsecurity.rememberMe.persistentToken.tokenLength // 16
        }
    }

}

I found this code here at the bottom of the page.

I get the following error:

ERROR context.GrailsContextLoader  - Error initializing the application: Error creating bean with name 'authenticationProcessingFilter': Cannot resolve reference to bean 'rememberMeServices' while setting bean property 'rememberMeServices'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rememberMeServices': Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'groovy.util.ConfigObject' to required type 'int' for property 'tokenLength'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [groovy.util.ConfigObject] to required type [int] for property 'tokenLength': PropertyEditor [org.springframework.beans.propertyeditors.CustomNumberEditor] returned inappropriate value of type [groovy.util.ConfigObject]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationProcessingFilter': Cannot resolve reference to bean 'rememberMeServices' while setting bean property 'rememberMeServices'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rememberMeServices': Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'groovy.util.ConfigObject' to required type 'int' for property 'tokenLength'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [groovy.util.ConfigObject] to required type [int] for property 'tokenLength': PropertyEditor [org.springframework.beans.propertyeditors.CustomNumberEditor] returned inappropriate value of type [groovy.util.ConfigObject]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)

What do I have to change in order to get the bean initialized correctly?

Cannot convert value of type [groovy.util.ConfigObject] to required type [int] for property 'tokenLength'

This suggests to me that you don't have a grails.plugins.springsecurity.rememberMe.persistentToken.tokenLength property set in your grailsApplication.config - when you ask a ConfigObject for a non-existent key what it returns to you is a new empty ConfigObject .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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