org.acegisecurity.providers.ldap.populator
Class DefaultLdapAuthoritiesPopulator

java.lang.Object
  extended by org.acegisecurity.providers.ldap.populator.DefaultLdapAuthoritiesPopulator
All Implemented Interfaces:
LdapAuthoritiesPopulator

public class DefaultLdapAuthoritiesPopulator
extends Object
implements LdapAuthoritiesPopulator

The default strategy for obtaining user role information from the directory.

It obtains roles by performing a search for "groups" the user is a member of.

A typical group search scenario would be where each group/role is specified using the groupOfNames (or groupOfUniqueNames) LDAP objectClass and the user's DN is listed in the member (or uniqueMember) attribute to indicate that they should be assigned that role. The following LDIF sample has the groups stored under the DN ou=groups,dc=acegisecurity,dc=org and a group called "developers" with "ben" and "marissa" as members:

dn: ou=groups,dc=acegisecurity,dc=orgobjectClass: top
 objectClass: organizationalUnitou: groupsdn: cn=developers,ou=groups,dc=acegisecurity,dc=org
 objectClass: groupOfNamesobjectClass: topcn: developersdescription: Acegi Security Developers
 member: uid=ben,ou=people,dc=acegisecurity,dc=orgmember: uid=marissa,ou=people,dc=acegisecurity,dc=orgou: developer
 

The group search is performed within a DN specified by the groupSearchBase property, which should be relative to the root DN of its InitialDirContextFactory. If the search base is null, group searching is disabled. The filter used in the search is defined by the groupSearchFilter property, with the filter argument {0} being the full DN of the user. You can also specify which attribute defines the role name by setting the groupRoleAttribute property (the default is "cn").

The configuration below shows how the group search might be performed with the above schema.

 <bean id="ldapAuthoritiesPopulator" class="org.acegisecurity.providers.ldap.populator.DefaultLdapAuthoritiesPopulator">
   <constructor-arg><ref local="initialDirContextFactory"/></constructor-arg>
   <constructor-arg><value>ou=groups</value></constructor-arg>
   <property name="groupRoleAttribute"><value>ou</value></property>
 <!-- the following properties are shown with their default values -->
   <property name="searchSubTree"><value>false</value></property>
   <property name="rolePrefix"><value>ROLE_</value></property>
   <property name="convertToUpperCase"><value>true</value></property>
 </bean>
 
A search for roles for user "uid=ben,ou=people,dc=acegisecurity,dc=org" would return the single granted authority "ROLE_DEVELOPER".

Version:
$Id: DefaultLdapAuthoritiesPopulator.java 1585 2006-07-20 13:15:55Z carlossg $
Author:
Luke Taylor

Constructor Summary
DefaultLdapAuthoritiesPopulator(InitialDirContextFactory initialDirContextFactory, String groupSearchBase)
          Constructor for group search scenarios.
 
Method Summary
protected  Set getAdditionalRoles(LdapUserDetails ldapUser)
          This method should be overridden if required to obtain any additional roles for the given user (on top of those obtained from the standard search implemented by this class).
 GrantedAuthority[] getGrantedAuthorities(LdapUserDetails userDetails)
          Obtains the authorities for the user who's directory entry is represented by the supplied LdapUserDetails object.
protected  Set getGroupMembershipRoles(String userDn, Attributes userAttributes)
          Deprecated. Subclasses should implement getAdditionalRoles instead.
 Set getGroupMembershipRoles(String userDn, String username)
           
protected  InitialDirContextFactory getInitialDirContextFactory()
           
 void setConvertToUpperCase(boolean convertToUpperCase)
           
 void setDefaultRole(String defaultRole)
          The default role which will be assigned to all users.
 void setGroupRoleAttribute(String groupRoleAttribute)
           
 void setGroupSearchFilter(String groupSearchFilter)
           
 void setRolePrefix(String rolePrefix)
           
 void setSearchSubtree(boolean searchSubtree)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultLdapAuthoritiesPopulator

public DefaultLdapAuthoritiesPopulator(InitialDirContextFactory initialDirContextFactory,
                                       String groupSearchBase)
Constructor for group search scenarios. userRoleAttributes may still be set as a property.

Parameters:
initialDirContextFactory - supplies the contexts used to search for user roles.
groupSearchBase - if this is an empty string the search will be performed from the root DN of the context factory.
Method Detail

getAdditionalRoles

protected Set getAdditionalRoles(LdapUserDetails ldapUser)
This method should be overridden if required to obtain any additional roles for the given user (on top of those obtained from the standard search implemented by this class).

Parameters:
ldapUser - the user who's roles are required
Returns:
the extra roles which will be merged with those returned by the group search

getGrantedAuthorities

public final GrantedAuthority[] getGrantedAuthorities(LdapUserDetails userDetails)
Obtains the authorities for the user who's directory entry is represented by the supplied LdapUserDetails object.

Specified by:
getGrantedAuthorities in interface LdapAuthoritiesPopulator
Parameters:
userDetails - the user who's authorities are required
Returns:
the set of roles granted to the user.

getGroupMembershipRoles

public Set getGroupMembershipRoles(String userDn,
                                   String username)

getGroupMembershipRoles

protected Set getGroupMembershipRoles(String userDn,
                                      Attributes userAttributes)
Deprecated. Subclasses should implement getAdditionalRoles instead.

Searches for groups the user is a member of.

Parameters:
userDn - the user's distinguished name.
userAttributes - the retrieved user's attributes (unused by default).
Returns:
the set of roles obtained from a group membership search, or null if groupSearchBase has been set.

getInitialDirContextFactory

protected InitialDirContextFactory getInitialDirContextFactory()

setConvertToUpperCase

public void setConvertToUpperCase(boolean convertToUpperCase)

setDefaultRole

public void setDefaultRole(String defaultRole)
The default role which will be assigned to all users.

Parameters:
defaultRole - the role name, including any desired prefix.

setGroupRoleAttribute

public void setGroupRoleAttribute(String groupRoleAttribute)

setGroupSearchFilter

public void setGroupSearchFilter(String groupSearchFilter)

setRolePrefix

public void setRolePrefix(String rolePrefix)

setSearchSubtree

public void setSearchSubtree(boolean searchSubtree)


Copyright © 2004-2006 Acegi Technology Pty Limited. All Rights Reserved.