繁体   English   中英

在 LDAP 子树中验证用户 (FilterBasedLdapUserSearch)

[英]Authenticate user in LDAP subtree (FilterBasedLdapUserSearch)

我通过 LDAP 成功地对我的用户进行身份验证和授权:

    @Bean
    BaseLdapPathContextSource contextSource() {
        final var url = environment.getRequiredProperty("spring.ldap.url");
        final var baseDn = environment.getRequiredProperty("spring.ldap.base");
        final var connectionString = url + "/" + baseDn;
        var contextSource = new DefaultSpringSecurityContextSource(connectionString);
        contextSource.afterPropertiesSet();
        contextSource.setUserDn(environment.getRequiredProperty("spring.ldap.userdn"));
        contextSource.setPassword(environment.getRequiredProperty("spring.ldap.password"));
        return contextSource;
    }

    @Bean
    BindAuthenticator bindAuthenticator(
        final BaseLdapPathContextSource contextSource) {
        var bindAuthenticator = new BindAuthenticator(contextSource);
        bindAuthenticator.setUserDnPatterns(new String[]{environment.getRequiredProperty("spring.ldap.userdnpattern")});
/*
        var userSearch =
            new FilterBasedLdapUserSearch(
                environment.getRequiredProperty("spring.ldap.base"),
                environment.getRequiredProperty("spring.ldap.searchfilter"),
                contextSource);
        userSearch.setSearchSubtree(true);
        bindAuthenticator.setUserSearch(userSearch);
*/
        bindAuthenticator.afterPropertiesSet();
        return bindAuthenticator;
    }

application.properties

spring.ldap.url=ldap://pre-adcorp.myorg.example
spring.ldap.base=OU=IVR,OU=apps,DC=pre,DC=myorg
spring.ldap.userdnpattern=cn={0}
spring.ldap.searchfilter=(&(cn={0})(objectclass=user))
spring.ldap.roleattributes=memberOf

现在,问题是我不习惯连接到ldap://pre-adcord.myorg.example/OU=IVR,OU=apps,DC=pre,DC=myorg因为我认为将来我需要验证属于 OU=apps 但属于其他 OU 的其他用户(例如,OU=ABC,OU=apps...)。 所以我希望能够在子树中搜索。

我已经尝试使用注释的源代码(使用 FilterBasedLdapUserSearch),但我总是得到 401 Unauthorized 失败,ldap dase "OU=IVR,OU=apps,DC=pre,DC=myorg" 和 "OU=apps,DC =pre,DC=myorg”。 我究竟做错了什么?

更新:我确实为FilterBasedLdapUserSearch创建了一个包装器; 事实证明,在调用searchForUser(String)时会引发绑定错误:

org.springframework.ldap.UncategorizedLdapException:LDAP处理过程中出现未分类异常; 嵌套异常是 javax.naming.NamingException:[LDAP:错误代码 1 - 000004DC:LdapErr:DSID-0C09075A,注释:为了执行此操作,必须在连接上成功绑定。,数据 0,v1db1]; 剩余名称 'ou=Aplicaciones,dc=pre,dc=aplssib'
在 org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:228) ~[spring-ldap-core-2.4.0.jar:2.4.0] 在 org.springframework.ldap.core.LdapTemplate.executeWithContext( LdapTemplate.java:824) ~[spring-ldap-core-2.4.0.jar:2.4.0]
[...]
引起:javax.naming.NamingException:[LDAP:错误代码 1 - 000004DC:LdapErr:DSID-0C09075A,注释:为了执行此操作,必须在连接上成功绑定。,数据 0,v1db1] 在 java .naming/com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3300) ~[na:na] at java.naming/com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3206) ~[na:na] at java.naming/com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2997) ~[na:na]

然而,如果我只是通过setUserDnPatterns搜索,它与我使用的上下文源相同。

回答只是为了避免人们浪费时间; 最后,这是绑定凭据的问题。

我仍然不知道最初的解决方案是如何工作的。

暂无
暂无

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

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