Class NestedLdapAuthoritiesPopulator

  • All Implemented Interfaces:

    public class NestedLdapAuthoritiesPopulator
    implements org.springframework.beans.factory.InitializingBean
    Uses a map, defined in Spring, that maps child roles to parent roles. Using this map, one can specify a hierarchy of roles that doesn't necessarily exist in the directory. Why would you need this? It is potentially prohibitive to repeatedly query the directory to recursively find all parents of a given child role.

    The map below specifies that the Marketing and Sales roles are child roles of the BIReporting role. So if user suzy belongs to the Marketing role, she will be assigned both Marketing and BIReporting roles by the time this populator returns.

    Any role prefix and/or case manipulation must be present in this mapping. In other words, if a role prefix has been set to ROLE_, and convertToUpperCase has been set to true, then both the keys and values must begin with ROLE_ and be all uppercase.

     <property name="extraRolesMapping">
         <entry key="Marketing" value="BIReporting" />
         <entry key="Sales" value="BIReporting" />

    Based on

    • Constructor Detail

      • NestedLdapAuthoritiesPopulator

        public NestedLdapAuthoritiesPopulator​(org.springframework.ldap.core.ContextSource contextSource,
                                              String groupSearchBase)
    • Method Detail

      • getGroupMembershipRoles

        public Set getGroupMembershipRoles​(String userDn,
                                           String username)
        Calls super's implementation then adds extra roles.
        getGroupMembershipRoles in class
      • getParentRoles

        protected Set getParentRoles​(Set children)
        Iterates over the set, using the items as keys into the extraRolesMapping.
        children - Set of keys
        Set of values retrieved from keys
      • toGrantedAuthorities

        protected Set toGrantedAuthorities​(Set rolesAsStringsSet)
        Converts a set of strings into a set of granted authorities.
        rolesAsStringsSet - Set of String instances
        Set of GrantedAuthority instances
      • getExtraRolesMapping

        public Map getExtraRolesMapping()
      • setExtraRolesMapping

        public void setExtraRolesMapping​(Map extraRolesMapping)
      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws Exception
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean