【问题标题】:Spring Security LDAP. The SearchControls.OBJECT_SCOPE is used instead of SearchControls.SUBTREE_SCOPE弹簧安全 LDAP。使用 SearchControls.OBJECT_SCOPE 代替 SearchControls.SUBTREE_SCOPE
【发布时间】:2020-06-22 20:31:40
【问题描述】:

spring-boot-starter-security 2.2.4.RELEASE,jdk 11

org.springframework.security.ldap.SpringSecurityLdapTemplate.searchForMultipleAttributeValues方法用于web请求认证时的组搜索。请求通过了认证。但是,没有找到用户组。

它使用范围为 SearchControls.OBJECT_SCOPE 的搜索控件。通过以下方法准备的搜索控件 com.sun.jndi.toolkit.ctx.LdapCtx.c_getAttributes.(Name name, String[] attrIds, 续续) 结果没有找到任何组。 如果我使用具有相同输入(组搜索库、组搜索过滤器、组角色属性)但使用 SearchControls.SUBTREE_SCOPE 的 ldap 模板进行搜索,则可以找到所有组。

我需要更改 org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder 配置以使用 SearchControls.SUBTREE_SCOPE 进行组搜索?

谢谢!

【问题讨论】:

  • 您是直接拨打SpringSecurityLdapTemplate 还是通过LdapAuthoritiesPopulator 之类的方式拨打电话?
  • 是的。我直接创建了模板来检查它使用相同配置返回的内容。
  • SpringSecurityLdapTemplate 默认使用SUBTREE_SCOPE,所以我想我不清楚你在问什么。如果您直接构建它,那么您可以随时调用setSearchControls 使用您需要的任何东西。

标签: java spring spring-security ldap


【解决方案1】:

这是一个配置问题。原始组搜索基指向根节点。这就是为什么使用 SearchControls.SUBTREE_SCOPE 通过 LDAP 模板搜索允许从子节点查找组的原因。不知道为什么 com.sun.jndi.toolkit.ctx.LdapCtx.c_getAttributes 使用 SearchControls.OBJECT_SCOPE 作为默认值。 将群组搜索库更改为特定群组节点即可解决此问题。

【讨论】:

    猜你喜欢
    • 2014-02-15
    • 2016-10-06
    • 2023-01-03
    • 2018-09-08
    • 1970-01-01
    • 2013-04-12
    • 1970-01-01
    • 2014-07-21
    • 2017-08-26
    相关资源
    最近更新 更多