栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如果要从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的作用。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/670681.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号