将ldap插件与grails应用程序结合使用

时间:2014-06-17 16:31:03

标签: grails ldap

我有一个grails应用程序,我已经添加了spring security ldap plugin。我在IDE中构建应用程序时,本地主机的一切正常,但是当我部署war文件时,我收到以下错误

''2014-06-17 11:15:06,412 [Thread-29] ERROR context.GrailsContextLoader  - Error initializing the application: Error creating bean with name 'ldapAuthoritiesPopulator': Cannot resolve reference to bean 'contextSource' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contextSource': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.ldap.DefaultSpringSecurityContextSource]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.security.ldap.DefaultSpringSecurityContextSource.setAuthenticationStrategy(Lorg/springframework/ldap/core/support/DirContextAuthenticationStrategy;)V
'org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ldapAuthoritiesPopulator': Cannot resolve reference to bean 'contextSource' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contextSource': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.ldap.DefaultSpringSecurityContextSource]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.security.ldap.DefaultSpringSecurityContextSource.setAuthenticationStrategy(Lorg/springframework/ldap/core/support/DirContextAuthenticationStrategy;)V
        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:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:679)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contextSource': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.ldap.DefaultSpringSecurityContextSource]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.security.ldap.DefaultSpringSecurityContextSource.setAuthenticationStrategy(Lorg/springframework/ldap/core/support/DirContextAuthenticationStrategy;)V
        ... 5 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.ldap.DefaultSpringSecurityContextSource]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.security.ldap.DefaultSpringSecurityContextSource.setAuthenticationStrategy(Lorg/springframework/ldap/core/support/DirContextAuthenticationStrategy;)V
        ... 5 more
Caused by: java.lang.NoSuchMethodError: org.springframework.security.ldap.DefaultSpringSecurityContextSource.setAuthenticationStrategy(Lorg/springframework/ldap/core/support/DirContextAuthenticationStrategy;)V
        ... 5 more
'2014-06-17 11:15:06,412 [Thread-29] ERROR context.GrailsContextLoader  - Error initializing the application: Error creating bean with name 'ldapAuthoritiesPopulator': Cannot resolve reference to bean 'contextSource' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contextSource': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.ldap.DefaultSpringSecurityContextSource]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.security.ldap.DefaultSpringSecurityContextSource.setAuthenticationStrategy(Lorg/springframework/ldap/core/support/DirContextAuthenticationStrategy;)V
'org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ldapAuthoritiesPopulator': Cannot resolve reference to bean 'contextSource' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contextSource': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.ldap.DefaultSpringSecurityContextSource]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.security.ldap.DefaultSpringSecurityContextSource.setAuthenticationStrategy(Lorg/springframework/ldap/core/support/DirContextAuthenticationStrategy;)V
        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:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:679)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contextSource': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.ldap.DefaultSpringSecurityContextSource]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.security.ldap.DefaultSpringSecurityContextSource.setAuthenticationStrategy(Lorg/springframework/ldap/core/support/DirContextAuthenticationStrategy;)V
        ... 5 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.ldap.DefaultSpringSecurityContextSource]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.security.ldap.DefaultSpringSecurityContextSource.setAuthenticationStrategy(Lorg/springframework/ldap/core/support/DirContextAuthenticationStrategy;)V
        ... 5 more
Caused by: java.lang.NoSuchMethodError: org.springframework.security.ldap.DefaultSpringSecurityContextSource.setAuthenticationStrategy(Lorg/springframework/ldap/core/support/DirContextAuthenticationStrategy;)V
        ... 5 more
'2014-06-17 11:15:06,413 [Thread-29] ERROR context.GrailsContextLoader  - Error initializing Grails: Error creating bean with name 'ldapAuthoritiesPopulator': Cannot resolve reference to bean 'contextSource' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contextSource': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.ldap.DefaultSpringSecurityContextSource]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.security.ldap.DefaultSpringSecurityContextSource.setAuthenticationStrategy(Lorg/springframework/ldap/core/support/DirContextAuthenticationStrategy;)V
'org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ldapAuthoritiesPopulator': Cannot resolve reference to bean 'contextSource' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contextSource': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.ldap.DefaultSpringSecurityContextSource]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.security.ldap.DefaultSpringSecurityContextSource.setAuthenticationStrategy(Lorg/springframework/ldap/core/support/DirContextAuthenticationStrategy;)V
        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:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:679)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contextSource': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.ldap.DefaultSpringSecurityContextSource]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.security.ldap.DefaultSpringSecurityContextSource.setAuthenticationStrategy(Lorg/springframework/ldap/core/support/DirContextAuthenticationStrategy;)V
        ... 5 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.ldap.DefaultSpringSecurityContextSource]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.security.ldap.DefaultSpringSecurityContextSource.setAuthenticationStrategy(Lorg/springframework/ldap/core/support/DirContextAuthenticationStrategy;)V
        ... 5 more
Caused by: java.lang.NoSuchMethodError: org.springframework.security.ldap.DefaultSpringSecurityContextSource.setAuthenticationStrategy(Lorg/springframework/ldap/core/support/DirContextAuthenticationStrategy;)V
        ... 5 more
'2014-06-17 11:15:06,413 [Thread-29] ERROR context.GrailsContextLoader  - Error initializing Grails: Error creating bean with name 'ldapAuthoritiesPopulator': Cannot resolve reference to bean 'contextSource' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contextSource': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.ldap.DefaultSpringSecurityContextSource]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.security.ldap.DefaultSpringSecurityContextSource.setAuthenticationStrategy(Lorg/springframework/ldap/core/support/DirContextAuthenticationStrategy;)V
'org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ldapAuthoritiesPopulator': Cannot resolve reference to bean 'contextSource' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contextSource': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.ldap.DefaultSpringSecurityContextSource]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.security.ldap.DefaultSpringSecurityContextSource.setAuthenticationStrategy(Lorg/springframework/ldap/core/support/DirContextAuthenticationStrategy;)V
        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:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:679)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contextSource': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.ldap.DefaultSpringSecurityContextSource]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.security.ldap.DefaultSpringSecurityContextSource.setAuthenticationStrategy(Lorg/springframework/ldap/core/support/DirContextAuthenticationStrategy;)V
        ... 5 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.ldap.DefaultSpringSecurityContextSource]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.security.ldap.DefaultSpringSecurityContextSource.setAuthenticationStrategy(Lorg/springframework/ldap/core/support/DirContextAuthenticationStrategy;)V
        ... 5 more
Caused by: java.lang.NoSuchMethodError: org.springframework.security.ldap.DefaultSpringSecurityContextSource.setAuthenticationStrategy(Lorg/springframework/ldap/core/support/DirContextAuthenticationStrategy;)V
        ... 5 more
'2014-06-17 11:15:06,422 [stop children - Catalina:j2eeType=WebModule,name=//localhost/SpineProcedures-0.1,J2EEApplication=none,J2EEServer=none] WARN  lifecycle.ShutdownOperations  - Error occurred running shutdown operation: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
'java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
        at java.lang.Thread.run(Thread.java:679)

外部配置文件

environments {
    development {
        println("Overriding development environment configuration")

        // Common values
        def ldapDn = 'exampleDN'
        def ldapPassword = 'examplePW'
        def ldapUrl = 'ldap://<domain>.location.example.edu'
        def ldapBase = 'OU=exampleDomain,OU=Non-Standard,DC=<domain>,DC=location,DC=example,DC=edu'

        // Spring Security
        grails.plugins.springsecurity.ldap.context.managerDn = ldapDn
        grails.plugins.springsecurity.ldap.context.managerPassword = ldapPassword
        grails.plugins.springsecurity.ldap.context.server = ldapUrl

        grails.plugins.springsecurity.ldap.search.base = ldapBase
        grails.plugins.springsecurity.ldap.authorities.groupSearchBase = ldapBase

        // LDAP
        ldap {
            directories {
                directory1 {
                    url = ldapUrl
                    base = ldapBase
                    userDn = ldapDn
                    password = ldapPassword
                }
            }
        }

        grails.logging.jul.usebridge = true
        grails.serverURL = "http://localhost:8080/Website"
    }
    test {
        println("Overriding test environment configuration")
    }
    production {
        println("Overriding production environment configuration")

        // Common values
        def ldapDn = 'exampleDN'
        def ldapPassword = 'examplePW'
        def ldapUrl = 'ldap://<domain>.location.example.edu'
        def ldapBase = 'OU=exampleDomain,OU=Non-Standard,DC=<domain>,DC=location,DC=example,DC=edu'

        // Spring Security
        grails.plugins.springsecurity.ldap.context.managerDn = ldapDn
        grails.plugins.springsecurity.ldap.context.managerPassword = ldapPassword
        grails.plugins.springsecurity.ldap.context.server = ldapUrl

        grails.plugins.springsecurity.ldap.search.base = ldapBase
        grails.plugins.springsecurity.ldap.authorities.groupSearchBase = ldapBase

        // LDAP
        ldap {
            directories {
                directory1 {
                    url = ldapUrl
                    base = ldapBase
                    userDn = ldapDn
                    password = ldapPassword
                }
            }
        }

        // Data source
        dataSource {
            username = "spineproc"
            password = "spineproc"
            url      = "jdbc:mysql://localhost/spine_proc_0-1"
        }

        grails.serverURL = "https://r-spineproc.<domain>.location.example.edu/SpineProcedures-0.1"

        // Turn on DBConsole
        grails.dbconsole.enabled

        // Turn on the DBDoc controller
        grails.plugin.databasemigration.dbDocController.enabled = true
    }


}

可以使用一些建议,谢谢。

2 个答案:

答案 0 :(得分:2)

删除

解决了此问题

compile ":ldap:0.8.2"

我的buildConfig文件中的

插件

答案 1 :(得分:1)

显然spring-security-ldap与由spring-ldap插件提取的ldap发生冲突。 删除ldap插件不是需要运行LDAP查询的人的解决方案。

插件ldap:0.8.2附带了/lib文件夹中修复的库。我们要删除spring-ldap-1.2.1.jar以解决库冲突问题。为避免将其打包在war文件中,我们必须明确删除它(在BuildConfig.groovy中)。

    grails.war.resources = { stagingDir ->
            delete(file:"${stagingDir}/WEB-INF/lib/spring-ldap-1.2.1.jar")
    }

这使ldap使用spring-ldap-core提供的sping-security-ldap,假设我们将其作为插件添加。

    +--- org.grails.plugins:spring-security-ldap:2.0-RC2
    |    \--- org.springframework.security:spring-security-ldap:3.2.0.RC1
    |    \--- org.springframework.ldap:spring-ldap-core:1.3.2.RELEASE
相关问题