KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gcc > security > Role


1 /*
2  * Copyright 2004 The Apache Software Foundation or its licensors, as
3  * applicable.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19 package gcc.security;
20
21 import gcc.properties.*;
22 import java.util.*;
23
24 public class Role
25 {
26     public static Role getInstance(String rolename)
27     {
28         Role role = (Role)_roleMap.get(rolename);
29         if (role == null)
30         {
31             synchronized (_roleMap)
32             {
33                 role = (Role)_roleMap.get(rolename);
34                 if (role == null)
35                 {
36                     role = new Role();
37                     role.init(rolename);
38                     _roleMap.put(rolename, role);
39                 }
40             }
41         }
42         return role;
43     }
44
45     public static Role getExistingInstance(String rolename)
46     {
47         return (Role)_roleMap.get(rolename);
48     }
49
50     // properties
51

52     public static final StringProperty assignedRolesProperty =
53         new StringProperty(Role.class, "assignedRoles")
54         .displayName("Assigned Roles")
55         .consoleHelp("Names of roles which have been explicitly assigned to this role.")
56         .list()
57         .sortOrder(1);
58
59     public static final StringProperty excludedRolesProperty =
60         new StringProperty(Role.class, "excludedRoles")
61         .displayName("Excluded Roles")
62         .consoleHelp("Names of roles which must be excluded from this role.")
63         .list()
64         .sortOrder(2);
65
66     public static final StringProperty excludedUsersProperty =
67         new StringProperty(Role.class, "excludedUsers")
68         .displayName("Excluded Users")
69         .consoleHelp("Names of users who must be excluded from this role.")
70         .list()
71         .sortOrder(3);
72
73     public static final StringProperty inheritedRolesProperty =
74         new StringProperty(Role.class, "inheritedRoles")
75         .displayName("Inherited Roles")
76         .consoleHelp("Names of roles which have been inherited from this role's assigned roles. This list is read only. It is derived from the assigned roles.")
77         .list()
78         .readOnly()
79         .sortOrder(4);
80
81     public static final StringProperty roleMembersProperty =
82         new StringProperty(Role.class, "roleMembers")
83         .displayName("Role Members")
84         .consoleHelp("Names of users who have been assigned this role, or who have inherited it from an assigned role. This list is read only. To add a user to a role, please edit the user's properties")
85         .list()
86         .readOnly()
87         .sortOrder(5);
88
89     // public constants
90

91     public static final String CLIENT = "[client]";
92
93     public static final String SYSTEM = "[system]";
94
95     // private data
96

97     private static HashMap _roleMap = new HashMap();
98
99     private String _name;
100
101     // internal methods
102

103     protected void init(String rolename)
104     {
105         _name = rolename;
106     }
107
108     // public methods
109

110     public String getName()
111     {
112         return _name;
113     }
114
115     public String toString()
116     {
117         return super.toString() + ":" + _name;
118     }
119 }
120
Popular Tags