すべてのActiveDirectoryグループ(現在のユーザーに関連するだけでなく)を取得するにはどうすればよいですか?SpringSecurityLDAPを使用しています。いくつか例を挙げていただけますか?
8456 次
4 に答える
1
できることは、すべてのロールを取得するための追加のメソッドを使用して、実装にLdapAuthoritiesPopulator
一致する の実装を作成することです。DefaultLdapAuthoritiesPopulator
public class ExtendedLdapAuthoritiesPopulator
implements LdapAuthoritiesPopulator {
// Copy implementation of DefaultLdapAuthoritiesPopulator (omitted).
private String allAuthorityFilter
= "(&(objectClass=group)(objectCategory=group))";
public void setAllAuthorityFilter(String allAuthorityFilter) {
Assert.notNull(allAuthorityFilter,
"allAuthorityFilter must not be null");
this.allAuthorityFilter = allAuthorityFilter;
}
public final Collection<GrantedAuthority> getAllAuthorities() {
if (groupSearchBase == null) {
return new HashSet<>();
}
Set<GrantedAuthority> authorities = new HashSet<>();
if (logger.isDebugEnabled()) {
logger.debug("Searching for all roles with filter '"
+ allAuthorityFilter + "' in search base '"
+ groupSearchBase + "'");
}
Set<String> roles = ldapTemplate.searchForSingleAttributeValues(
groupSearchBase,
allAuthorityFilter,
new String[0],
groupRoleAttribute);
if (logger.isDebugEnabled()) {
logger.debug("Roles from search: " + roles);
}
for (String role : roles) {
if (convertToUpperCase) {
role = role.toUpperCase();
}
authorities.add(new SimpleGrantedAuthority(rolePrefix + role));
}
return authorities;
}
}
春のセキュリティ構成DefaultLdapAuthoritiesPopulator
で、新しい実装に変更します。
追加のプロパティは、AllAuthorityFilter
どのグループが返されるかをフィルターで設定できます。
String
インスタンスではなく、ベースのロール名を取得するだけの実装を好む場合がありGrantedAuthority
ます。
于 2013-05-20T03:48:48.417 に答える
-1
このインターフェースを確認してください: http://static.springsource.org/spring-security/site/docs/3.1.x/apidocs/org/springframework/security/ldap/userdetails/LdapAuthoritiesPopulator.html
そしてこのクラスのデフォルト:
それは役に立つことができます
于 2012-11-28T16:25:28.777 に答える