KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > atlassian > seraph > auth > GroupRoleMapper


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 JavaDoc;
7 import java.util.Collection JavaDoc;
8 import java.util.Map JavaDoc;
9 import java.security.Principal JavaDoc;
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 JavaDoc params, SecurityConfig config)
19     {
20     }
21
22     /**
23      * Assume that roles == groups.
24      */

25     public boolean hasRole(Principal JavaDoc user, HttpServletRequest JavaDoc request, String JavaDoc role)
26     {
27         Collection JavaDoc 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 JavaDoc user, HttpServletRequest JavaDoc request)
42     {
43         return user != null;
44     }
45 }
46
Popular Tags