gpt4 book ai didi

java - 为什么 Spring Security 的 BindAuthenticator 需要用户读取权限?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:19:26 24 4
gpt4 key购买 nike

我目前正在使用 Spring Security 3.0 实现/配置 Java Web 应用程序的 LDAP 身份验证。我使用 Microsoft AD LDS 作为 LDAP 服务器并选择了 Spring 的 BindAuthenticator。我发现只有经过身份验证的用户是分区的读者角色的成员时,身份验证才有效。 BindAuthenticator 尝试在身份验证后读取用户的属性,这在从目录服务检索权限的场景中似乎是合理的。

作为 LDAP 和 AD 的新手,当应用程序集成到现有 AD 结构中时,这是一种可接受的做法吗?是否可以微调 an 为用户 dns 仅授予其自身属性的读取权限,而不是将其添加到 Reader 组?

谢谢托马斯


2010 年 3 月 8 日编辑:这是我最终做的:我复制了 Spring 的 BindAuthenticator(整个类)并更改了方法 bindWithDn() 如下。差异用 DIFF 标记。

private DirContextOperations bindWithDn(String userDn, String username, String password) {
BaseLdapPathContextSource ctxSource = (BaseLdapPathContextSource) getContextSource();
DistinguishedName fullDn = new DistinguishedName(userDn);
fullDn.prepend(ctxSource.getBaseLdapPath());

logger.debug("Attempting to bind as " + fullDn);

DirContext ctx = null;
try {
ctx = getContextSource().getContext(fullDn.toString(), password);
// Check for password policy control
PasswordPolicyControl ppolicy = PasswordPolicyControlExtractor.extractControl(ctx);

// *DIFF* Attributes attrs = ctx.getAttributes(userDn, getUserAttributes());

DirContextAdapter result = new DirContextAdapter(null, new DistinguishedName(userDn), // *DIFF*
ctxSource.getBaseLdapPath());

if (ppolicy != null) {
result.setAttributeValue(ppolicy.getID(), ppolicy);
}

return result;
} catch (NamingException e) {
// This will be thrown if an invalid user name is used and the method may
// be called multiple times to try different names, so we trap the exception
// unless a subclass wishes to implement more specialized behaviour.
if ((e instanceof org.springframework.ldap.AuthenticationException)
|| (e instanceof org.springframework.ldap.OperationNotSupportedException)) {
handleBindException(userDn, username, e);
} else {
throw e;
}
// *DIFF* } catch (javax.naming.NamingException e) {
// *DIFF* throw LdapUtils.convertLdapException(e);
} finally {
LdapUtils.closeContext(ctx);
}

return null;
}

最佳答案

这对我来说很有意义,它意味着 BindAuthenticator 执行 LDAP 绑定(bind)“作为”经过身份验证的用户,并使用 LDAP 来填充用户详细信息对象。我猜测 LDAP 服务器要求用户拥有一个角色,使他们有权读取自己的属性。

您是否尝试过将属性集(通过 setUserAttributes)限制为只有几个属性。我认为在 AD 中您可以将 RBAC 放在各个属性上,因此您可能正在读取一个具有“读者”角色保护的属性和其他一些不 protected 属性。

您的其他选择是:

  • 按照您的建议更改 LDAP 服务器上的 RBAC,但我没有适合您的处方。
  • 使用不同的身份验证方法,该方法作为通用服务器主体执行绑定(bind)并读取属性。您可能仍需要绑定(bind)用户才能检查他们的密码。

关于java - 为什么 Spring Security 的 BindAuthenticator 需要用户读取权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2831630/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com