Including ldap granule plugin

I have a grails application and I added spring security ldap plugin. Everything works fine from the local host when I create the application in IDE, but when I deploy the war file, I get the following error

''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)

external configuration file

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
    }


}

You can use some tips, thanks.

+4
source share
2 answers

This issue was resolved by uninstalling

compile ":ldap:0.8.2"

in my buildConfig file

+2
source

Apparently spring-security-ldapencounters with spring-ldapwhich is pulled by the plugin ldap. Removing the plugin is ldapnot a solution for those who need to run LDAP queries.

ldap:0.8.2 , /lib. spring-ldap-1.2.1.jar, . , ( 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
+1

Source: https://habr.com/ru/post/1544946/


All Articles