繁体   English   中英

Spring Boot配置-2配置LDAP-Yml文件

[英]Spring Boot configuration - 2 configuration LDAP - Yml File

我想在我的应用程序中使用2个不同的ldap配置。 我的文件是application.yml:

management:

context-path: /management
health:
    mail:
        enabled: false # When using the MailService, configure an SMTP server and set this to true

spring:
    application:
        name: matrice2
    profiles:
    # The commented value for `active` can be replaced with valid spring profiles to load.
    # Otherwise, it will be filled in by maven when building the WAR file
    # Either way, it can be overridden by `--spring.profiles.active` value passed in the commandline or `-Dspring.profiles.active` set in `JAVA_OPTS`
        active: #spring.profiles.active#
    jpa:
        open-in-view: false
        hibernate:
            ddl-auto: none
            naming-strategy: org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy
    messages:
        basename: i18n/messages
    mvc:
        favicon:
            enabled: false
    thymeleaf:
        mode: XHTML

security:

    basic:
        enabled: false


jhipster: 
    async:
        corePoolSize: 2
        maxPoolSize: 50
        queueCapacity: 10000
    mail:
        from: matrice2@localhost
    swagger:
        title: matrice2 API
        description: matrice2 API documentation
        version: 0.0.1
        termsOfServiceUrl:
        contactName:
        contactUrl:
        contactEmail:
        license:
        licenseUrl:
ldap:
    url: ldap://ldap.east.app.company.com:389
    base: DC=west,DC=app,DC=company,DC=com
    manager:
        dn: CN=toto,OU=CDS,OU=Company_Commun,DC=west,DC=app,DC=company,DC=com
    password: toto    
    grpAdmin : GRP_PROJECT_ADMIN
    grpUser : GRP_PROJECT_ADMIN


ldap:
    url: ldap://ba-dc1.app.company.com:389
    base: DC=app,DC=company,DC=com
    manager:
        dn: CN=ad_c_s,OU=C_d_S,DC=app,DC=company,DC=com
        password: toto!service    
    grpAdmin : GRP_PROJECT_ADMIN
    grpUser : GRP_PROJECT_ADMIN

我得到这个错误:

Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: while parsing MappingNode
in 'reader', line 14, column 1:
management:

Duplicate key : ldap in 'reader', line 97, column 1.

有没有办法拥有多个配置ldap? 有人有主意吗?

谢谢

我们有一个类似的问题。 您必须注册自己的WebSecurityConfig才能使其与您自己的@ConfigProperies 该方法不是理想的方法,因为如果您要更改要验证的LDAP服务器的数量,则需要更改代码,但这不是什么大问题。 由于对于我们的系统来说,凭据是相同的,因此我们只有一个LDAP设置,也许您必须对此进行调整。 但这应该给您一个提示。

application.yaml

ldap:
  amUrl: ldaps://us-server
  emeaUrl: ldaps://eu-server
  bindCn: CN=blah,OU=blah,DC=blah,DC=local
  bindPass: my-secret-password

SecurityConfigProperties

@Data
@ConfigurationProperties(prefix = "ldap")
public class SecurityConfigProperties {
    private String emeaLdapUrl;
    private String amLdapUrl;
    private int ldapPort;
    private String bindCn;
    private String bindPass; 
}

安全配置

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    // Don't hit me for this Oli!
    @Autowired
    private SecurityConfigProperties conf;

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder authBuilder) throws Exception {
        authBuilder
            .ldapAuthentication()
            .userSearchFilter("(sAMAccountName={0})")
            .userSearchBase("dc=am,dc=blah,dc=local")
            .groupSearchBase("ou=groups,dc=am,dc=blah,dc=local")
            .groupSearchFilter("member={0}")
            .contextSource()
                .url(conf.getAmLdapUrl())
                .managerDn(conf.getBindCn())
                .managerPassword(conf.getBindPass())
            .and()          
            .and()
            .ldapAuthentication()
            .userSearchFilter("(sAMAccountName={0})")
            .userSearchBase("dc=emea,dc=blah,dc=local")
            .groupSearchBase("ou=groups,dc=emea,dc=blah,dc=local")
            .groupSearchFilter("member={0}")
            .contextSource()
                .url(conf.getEmeaLdapUrl())
                .managerDn(conf.getBindCn()) 
                .managerPassword(conf.getBindPass())
        ;
    }
}

希望有帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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