如果使用DBMS_LDAP在服务器上执行身份验证,如何在Spring启动应用程序中实现LDAP授权 .

如果用户未被授权,则服务器返回 null ,否则返回 user properties .

依赖关系:

compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.ldap:spring-ldap-core")
compile("org.springframework.security:spring-security-ldap")
compile("org.springframework:spring-tx")
compile("com.unboundid:unboundid-ldapsdk")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile("org.apache.directory.server:apacheds-server-jndi:1.5.5")

AuthenticationManagerBuilder配置:

auth
            .ldapAuthentication()
            .userDnPatterns("uid={0},ou=Users")
            .userSearchBase("ou=gk")
            .userSearchFilter("(&(objectClass=user)(objectCategory=person))")
            .groupSearchBase("ou=groups")
            .groupSearchFilter("(&(objectClass=user)(objectCategory=person))")
            .contextSource(contextSource());

好的ContextSource:

@Bean(name = "contextSource")
public LdapContextSource  contextSource() {

    LdapContextSource cs = new LdapContextSource ();
    cs.setUrl( "ldaps://server.corp.company.ru:666/");
    cs.setBase("dc=corp,dc=company,dc=ru");
    cs.setUserDn("cn=username,dc=corp,dc=company,dc=ru");
    cs.setPassword("password");
    cs.afterPropertiesSet();
    return cs;
}

投掷错误:

原因:[LDAP:错误代码49 - 80090308:LdapErr:DSID-0C090400,注释:AcceptSecurityContext错误,数据52e,v1db1];嵌套异常是javax.naming.AuthenticationException:[LDAP:错误代码49 - 80090308:LdapErr:DSID-0C090400,注释:AcceptSecurityContext错误,数据52e,v1db1]