如果要从ActiveDirectory获取用户详细信息,是否需要编写CustomActiveDirectoryLdapAuthenticationProvider?

如果要从ActiveDirectory获取用户详细信息,是否需要编写CustomActiveDirectoryLdapAuthenticationProvider?,第1张

如果要从ActiveDirectory获取用户详细信息,是否需要编写CustomActiveDirectoryLdapAuthenticationProvider?

你不。Spring Security带有一个

UserDetailsContextMapper
接口

UserDetails mapUserFromContext(DirContextOperations ctx, String username,        Collection<? extends GrantedAuthority> authorities);

默认实现LdapUserDetailsMapper

当前仅映射搜索返回的组。

// Map the rolesfor (int i = 0; (this.roleAttributes != null)        && (i < this.roleAttributes.length); i++) {    String[] rolesForAttribute = ctx.getStringAttributes(this.roleAttributes[i]);    if (rolesForAttribute == null) {        this.logger.debug("Couldn't read role attribute '"     + this.roleAttributes[i] + "' for user " + dn);        continue;    }        for (String role : rolesForAttribute) {        GrantedAuthority authority = createAuthority(role); if (authority != null) { essence.addAuthority(authority);        }    }}

但是,实现自己的 UserDetailsMapper 可以检索从LDAP返回的所有记录。

您只需确定要获取的属性

Object attribute = ctx.getObjectAttribute("some-ldap-attribute");

这是在身份验证事件期间获取自定义值的方式。

如果您只想查询和搜索并从LDAP目录中获取数据,则可以利用SpringSecurityLdapTemplate

它旨在模仿 RestTemplate 对于HTTP而不是LDAP的作用。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5675920.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存