在CAS War Overlay服务器中配置Spring嵌入式LDAP服务器

时间:2017-09-20 12:42:02

标签: spring spring-boot cas spring-ldap

我正在尝试配置CAS WAR覆盖服务器以进行测试 https://apereo.github.io/cas/5.1.x/index.html

我想用这个启动一个Spring LDAP嵌入式服务器:

    @Configuration
@EnableWebSecurity(debug = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    public void configure(final AuthenticationManagerBuilder auth) throws Exception {
        auth
                .ldapAuthentication()
                .userSearchBase("")
                .userSearchFilter("(uid={0})")
                .groupSearchBase("ou=Groups")
                .groupSearchFilter("(uniqueMember={0})")
                .userDetailsContextMapper(new InetOrgPersonContextMapper())
                .contextSource(contextSource())
                .passwordCompare()
                    .passwordAttribute("telephoneNumber")
        ;
    }

    @Bean
    public DefaultSpringSecurityContextSource contextSource() {
        return new DefaultSpringSecurityContextSource(
                Arrays.asList("ldap://localhost:" + LDAP_PORT + "/"), "dc=jbcpcalendar,dc=com");
    }

}

并具有以下配置供ldif配置文件使用

〜/ CAS-服务器/ CAS / SRC /主/资源/ application.yml

spring:
  ldap:
    embedded:
      ldif: classpath:/ldif/calendar.ldif
      baseDn: dc=jbcpcalendar,dc=com
      port: ${LDAP_PORT:33389}
#      credential:
#        username: user
#        password: secret

我正在使用Gradle War覆盖CAS项目,并且只尝试添加LDAP。

当我将上面的配置文件(SecurityConfig.java)添加到〜/ cas-server / cas / src / main / java / *

当我添加这些依赖项时:

subprojects {

    dependencies {

            compile "org.apereo.cas:cas-server-support-ldap:${project.'cas.version'}"

        // LDAP:
        // Not sure if I need and/or want this starter:
        compile("org.springframework.boot:spring-boot-starter-data-ldap:${project.'springboot.version'}")

        compile("org.springframework.ldap:spring-ldap-core:2.3.1.RELEASE")
        compile("org.springframework.security:spring-security-ldap:4.2.3.RELEASE")
        // Due to a artifact resolution issue with Gradle,
        // spring-tx must be pulled in or Gradle will fetch an older one that doesn’t work.
        compile("org.springframework:spring-tx")
        compile("com.unboundid:unboundid-ldapsdk")

        // Security:
        compile("org.springframework.boot:spring-boot-starter-security")
    }

到〜/ cas-server / build.gradle我收到此错误:

06:16:37.706 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
06:16:37.706 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] A problem occurred evaluating root project 'chapter10.00-cas-server'.
06:16:37.706 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Could not find method compile() for arguments [org.springframework.boot:spring-boot-starter-data-ldap:1.5.3.RELEASE] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

当我添加这些依赖项时:

            compile "org.apereo.cas:cas-server-support-ldap:${project.'cas.version'}"

        compile("org.springframework.boot:spring-boot-starter-web")
        compile("org.codehaus.groovy:groovy")

        // LDAP:
        // Not sure if I need and/or want this starter:
        compile("org.springframework.boot:spring-boot-starter-data-ldap")

        compile("org.springframework.ldap:spring-ldap-core:2.3.1.RELEASE")
        compile("org.springframework.security:spring-security-ldap:4.2.3.RELEASE")
        // Due to a artifact resolution issue with Gradle,
        // spring-tx must be pulled in or Gradle will fetch an older one that doesn’t work.
        compile("org.springframework:spring-tx")
        compile("com.unboundid:unboundid-ldapsdk")


        // Security:
        compile("org.springframework.boot:spring-boot-starter-security")

到〜/ cas-server / cas / build.gradle我收到此错误:

    06:24:57.567 [QUIET] [system.out] 
    06:24:57.644 [QUIET] [system.out]    __   ____      _      ____   __  
    06:24:57.645 [QUIET] [system.out]   / /  / ___|    / \    / ___|  \ \ 
    06:24:57.645 [QUIET] [system.out]  | |  | |       / _ \   \___ \   | |
    06:24:57.645 [QUIET] [system.out]  | |  | |___   / ___ \   ___) |  | |
    06:24:57.645 [QUIET] [system.out]  | |   \____| /_/   \_\ |____/   | |
    06:24:57.645 [QUIET] [system.out]   \_\                           /_/ 
    06:24:57.645 [QUIET] [system.out] 
    06:24:57.645 [QUIET] [system.out] CAS Version: 5.1.2
    06:24:57.645 [QUIET] [system.out] CAS Commit Id: fae163b426ba91cc78a18e3805b2f2fac9c03b2e
    06:24:57.645 [QUIET] [system.out] CAS Build Date/Time: 2017-09-20T12:19:37Z
    06:24:57.645 [QUIET] [system.out] Spring Boot Version: 1.5.3.RELEASE
    06:24:57.645 [QUIET] [system.out] ------------------------------------------------------------
    06:24:57.645 [QUIET] [system.out] System Date/Time: 2017-09-20T06:24:57.372
    06:24:57.645 [QUIET] [system.out] System Temp Directory: /var/folders/vm/nx7j7v8x4db1f4xsztj_rsmm0000gn/T/
    06:24:57.646 [QUIET] [system.out] ------------------------------------------------------------
    06:24:57.646 [QUIET] [system.out] Java Home: /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre
    06:24:57.646 [QUIET] [system.out] Java Vendor: Oracle Corporation
    06:24:57.646 [QUIET] [system.out] Java Version: 1.8.0_144
    06:24:57.646 [QUIET] [system.out] JCE Installed: no
    06:24:57.646 [QUIET] [system.out] ------------------------------------------------------------
    06:24:57.646 [QUIET] [system.out] OS Architecture: x86_64
    06:24:57.646 [QUIET] [system.out] OS Name: Mac OS X
    06:24:57.646 [QUIET] [system.out] OS Version: 10.12.6
    06:24:57.646 [QUIET] [system.out] ------------------------------------------------------------
    06:24:57.646 [QUIET] [system.out] Apache Tomcat Version: Apache Tomcat/8.5.20
    06:24:57.646 [QUIET] [system.out] ------------------------------------------------------------
    06:24:57.646 [QUIET] [system.out] 
    06:24:57.646 [QUIET] [system.out] 
    06:24:57.833 [QUIET] [system.out] 2017-09-20 06:24:57.833  INFO 17183 --- [           main] .CasCoreBootstrapStandaloneConfiguration : Configuration files found at [/etc/cas/config] are [[/etc/cas/config/application.yml, /etc/cas/config/cas.properties]]
    06:24:57.852 [QUIET] [system.out] 2017-09-20 06:24:57.852  INFO 17183 --- [           main] .CasCoreBootstrapStandaloneConfiguration : Found and loaded [14] setting(s) from [/etc/cas/config]
    06:24:57.852 [QUIET] [system.out] 2017-09-20 06:24:57.852  INFO 17183 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: PropertiesPropertySource {name='standaloneCasConfigService'}
    06:25:00.680 [DEBUG] [org.gradle.launcher.daemon.server.Daemon] DaemonExpirationPeriodicCheck running
    06:25:00.681 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
    06:25:00.681 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
    06:25:00.681 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
    06:25:00.681 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
    06:25:00.681 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
    06:25:00.682 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
    06:25:01.171 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: FAILED
    06:25:01.171 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] **Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/java'' finished with exit value 1 (state: FAILED)**

我还没有看过有关嵌入式ldap服务器的文档,我看过: https://apereo.github.io/2017/03/24/cas51-ldapauthnjasypt-tutorial/ https://apereo.github.io/cas/development/installation/LDAP-Authentication.html

但当然不知道case.properties应放在哪里,并将其添加到: ~/cas-server/src/main/resources/cas.properties

,也不

~/cas-server/cas/src/main/resources/cas.properties

似乎有任何影响。

除此之外,我没有对原始项目下载进行任何改动。

我真的很挣扎。非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

最好使用Docker。将docker-compose文件放在一起,简单地旋转嵌入式ldap服务器,然后再旋转连接到ldap的CAS服务器。

以下是一个让您入门的示例: https://github.com/mmoayyed/dockerized-idp-testbed

您需要将cas-server与正在运行的ldap连接,并从compose中删除所有其他组件。