Results 1 to 4 of 4

Thread: Get users's group name once authenticated

  1. #1
    Join Date
    Nov 2009
    Posts
    8

    Default Get users's group name once authenticated

    I am using authority groups and once the user is logged in I need to do different things depending what group the user is in (there are a number of hard coded groups).

    I cannot see anyway to get this information from the Authentication object retrieved by :
    Authentication auth = SecurityContextHolder.getContext().getAuthenticati on();

    I have the following defined in the applicationContext-security.xml. I can possibly get the group from the JdbcUserDetailsManager but I see no way to access that from java.

    <authentication-manager alias="authenticationManager">
    <authentication-provider>
    <jdbc-user-service data-source-ref="dataSource"
    group-authorities-by-username-query="..."
    users-by-username-query="..."
    authorities-by-username-query="..."/>
    </authentication-provider>
    </authentication-manager>

    <beans:bean id="userDetailsManager" class="org.springframework.security.provisioning.J dbcUserDetailsManager">
    <beansroperty name="dataSource" ref="dataSource"/>
    <beansroperty name="authenticationManager" ref="authenticationManager"/>

    <!-- enable lookup of permissions via user's group -->
    <beansroperty name="enableGroups" value="true"/>

    <!-- disable direct lookup of user's permissions (require lookup via group) -->
    <beansroperty name="enableAuthorities" value="false"/>
    </beans:bean>

  2. #2
    Join Date
    Nov 2009
    Posts
    1

  3. #3
    Join Date
    Nov 2009
    Posts
    8

    Default

    I already have everything configured in the applicationSecurity-context.xml as in the link you posted (I just didn't include it in the post). What I am after is a way to get the group of the user within java from a controller. I can get to the user and authorities via:

    Authentication auth = SecurityContextHolder.getContext().getAuthenticati on();
    User user = (User)auth.getPrincipal();
    Collection<GrantedAuthority> authorities = auth.getAuthorities();

    But the authorities only gives me the users roles and not their group.

    Any suggestions??

  4. #4
    Luke Taylor is offline Senior Member Acegi Security System TeamSpring Team
    Join Date
    Aug 2004
    Location
    Glasgow, Scotland
    Posts
    3,449

    Default

    The "groups" in this context are more of a logical construct for administering authorities. You'll need to customize the logic for loading the authorities if you want access to the groups from within the application.
    Spring - by Pivotal
    twitter @tekul

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •