2012-11-28 6 views
1

모든 Active Directory 그룹을 얻는 방법 (현재 사용자뿐만 아니라)? 스프링 보안 ldap을 사용하고 있습니다. 몇 가지 예를 제공해 주시겠습니까?봄 보안에서 모든 LDAP 그룹을 얻는 방법

+0

[무엇을 시도해 봤습니까?] (http://whathaveyoutried.com) –

+0

사람들이 예제와 질문을 제공 한 다른 스레드를 살펴 보았습니까? 예를 들어 http://stackoverflow.com/questions/7417177/spring-security-authentication-using-ldap – CodeDreamer

답변

-1
+0

예, 특정 사용자에 대한 그룹을 얻는 방법을 보여줍니다. 문제는 모든 기존 LDAP 그룹을 포함하는 목록을 얻는 방법을 찾지 못했기 때문입니다. –

1

당신이 할 수있는 것은 DefaultLdapAuthoritiesPopulator 일치 LdapAuthoritiesPopulator의 구현을 작성하다 모든 역할을 검색하는 추가 메소드로 구현.

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을 설정할 수 있습니다.

GrantedAuthority 인스턴스 대신 String 기반 역할 이름 만 검색하면 구현을 선호 할 수 있습니다.

관련 문제