View Javadoc

1   package com.atlassian.seraph.auth;
2   
3   import com.atlassian.seraph.util.GroupCache;
4   import com.atlassian.seraph.config.SecurityConfig;
5   
6   import javax.servlet.http.HttpServletRequest;
7   import java.util.Collection;
8   import java.util.Map;
9   import java.security.Principal;
10  
11  /**
12   * A simple RoleMapper which maps directly between group names and role names.
13   *
14   * If a user is a member of someGroup, the are in the 'someGroup' role.  Users can log in if they exist.
15   */
16  public class GroupRoleMapper implements RoleMapper
17  {
18      public void init(Map params, SecurityConfig config)
19      {
20      }
21  
22      /**
23       * Assume that roles == groups.
24       */
25      public boolean hasRole(Principal user, HttpServletRequest request, String role)
26      {
27          Collection groups = GroupCache.getGroups(request);
28  
29          if (groups == null && role == null)
30              return true;
31          else if (groups == null)
32              return false;
33          else
34              return groups.contains(role);
35      }
36  
37      /**
38       * Users can login if they exist.
39  
40       */
41      public boolean canLogin(Principal user, HttpServletRequest request)
42      {
43          return user != null;
44      }
45  }