Java 如何将广告组映射到用户角色Spring Security LDAP
我有一个使用JavaSpringMVC构建的web应用程序 我只是将spring security设置为连接到LDAP服务器进行身份验证 我已经成功地设置了它,这样我就可以登录到我的应用程序,但是我找不到任何东西来帮助我将广告组映射到Java中的用户角色,因为我只能获得403禁止页面,也就是说,我已经过身份验证,但还没有权限 我目前有:Java 如何将广告组映射到用户角色Spring Security LDAP,java,spring,spring-security,ldap,mapping,Java,Spring,Spring Security,Ldap,Mapping,我有一个使用JavaSpringMVC构建的web应用程序 我只是将spring security设置为连接到LDAP服务器进行身份验证 我已经成功地设置了它,这样我就可以登录到我的应用程序,但是我找不到任何东西来帮助我将广告组映射到Java中的用户角色,因为我只能获得403禁止页面,也就是说,我已经过身份验证,但还没有权限 我目前有: <http auto-config="true"> <intercept-url pattern="/**" access="ROLE
<http auto-config="true">
<intercept-url pattern="/**" access="ROLE_USER" />
</http>
<ldap-server id="ldapServer" url="LDAPURL" manager-dn="USER" manager-password="PASSWORD" />
<authentication-manager >
<ldap-authentication-provider
group-search-base="OU=GROUPS"
group-search-filter="sAMAccountName={0}"
user-search-base="OU=USERS"
user-search-filter="sAMAccountName={0}"
/>
</authentication-manager>
假设该用户是广告组g-group-UK-user的一部分,然后我希望能够将该广告组映射到ROLE_user,这样用户就可以看到整个web应用程序
我似乎只能找到非常简单的示例,其中组是ADMIN或USER,在这种情况下,前缀角色只是添加到组中,或者其他方法似乎使用UserDetailContextMapper,但我找不到明确的用法。为此,我在authentication manager中使用了以下方法:
user-context-mapper-ref="customUserContextMapper"
然后,我使用以下类检查该用户是否属于某个广告组,然后将该角色分配给他们的权限:
@Override
public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> authorities)
{
Attributes attributes = ctx.getAttributes();
Object[] groups = new Object[100];
groups = ctx.getObjectAttributes("memberOf");
LOGGER.debug("Attributes: {}", attributes);
Set<GrantedAuthority> authority = new HashSet<GrantedAuthority>();
for(Object group: groups)
{
if (group.toString().toLowerCase().contains("AD_GROUP_NAME".toLowerCase()) == true)
{
authority.add(new SimpleGrantedAuthority("ROLE_USER"));
break;
}
}
User userDetails = new User(username, "", false, false, false, false, authority);
return userDetails;
}
@覆盖
公共用户详细信息mapUserFromContext(DirContextOperations ctx、字符串用户名、集合