KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > service > cmr > security > AuthorityType


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.service.cmr.security;
18
19 /**
20  * The types of authority that are available.
21  * <p>
22  * <p>
23  * Available types are:
24  * <ol>
25  * <li>USER - an authority that identifies a user
26  * <li>GROUP - an authority that identifies a group
27  * <li>OWNER - the special authority that applies to the owner of a node
28  * <li>EVERYONE - the special authority that is interpreted as everyone
29  * <li>GUEST - the special authority that applies to a GUEST (An unknown,
30  * unauthenticated user)
31  * </ol>
32  *
33  * @author Andy Hind
34  */

35 public enum AuthorityType
36 {
37     ADMIN
38     {
39         public boolean isFixedString()
40         {
41             return true;
42         }
43
44         public String JavaDoc getFixedString()
45         {
46             return PermissionService.ADMINISTRATOR_AUTHORITY;
47         }
48
49         public boolean isPrefixed()
50         {
51             return false;
52         }
53
54         public String JavaDoc getPrefixString()
55         {
56             return "";
57         }
58     },
59
60     EVERYONE
61     {
62         public boolean isFixedString()
63         {
64             return true;
65         }
66
67         public String JavaDoc getFixedString()
68         {
69             return PermissionService.ALL_AUTHORITIES;
70         }
71
72         public boolean isPrefixed()
73         {
74             return false;
75         }
76
77         public String JavaDoc getPrefixString()
78         {
79             return "";
80         }
81     },
82     OWNER
83     {
84         public boolean isFixedString()
85         {
86             return true;
87         }
88
89         public String JavaDoc getFixedString()
90         {
91             return PermissionService.OWNER_AUTHORITY;
92         }
93
94         public boolean isPrefixed()
95         {
96             return false;
97         }
98
99         public String JavaDoc getPrefixString()
100         {
101             return "";
102         }
103     },
104     GUEST
105     {
106         public boolean isFixedString()
107         {
108             return true;
109         }
110
111         public String JavaDoc getFixedString()
112         {
113             return PermissionService.GUEST_AUTHORITY;
114         }
115
116         public boolean isPrefixed()
117         {
118             return false;
119         }
120
121         public String JavaDoc getPrefixString()
122         {
123             return "";
124         }
125     },
126     GROUP
127     {
128         public boolean isFixedString()
129         {
130             return false;
131         }
132
133         public String JavaDoc getFixedString()
134         {
135             return "";
136         }
137
138         public boolean isPrefixed()
139         {
140             return true;
141         }
142
143         public String JavaDoc getPrefixString()
144         {
145             return PermissionService.GROUP_PREFIX;
146         }
147     },
148     ROLE
149     {
150
151         public boolean isFixedString()
152         {
153             return false;
154         }
155
156         public String JavaDoc getFixedString()
157         {
158             return "";
159         }
160
161         public boolean isPrefixed()
162         {
163             return true;
164         }
165
166         public String JavaDoc getPrefixString()
167         {
168             return PermissionService.ROLE_PREFIX;
169         }
170     },
171     USER
172     {
173         public boolean isFixedString()
174         {
175             return false;
176         }
177
178         public String JavaDoc getFixedString()
179         {
180             return "";
181         }
182
183         public boolean isPrefixed()
184         {
185             return false;
186         }
187
188         public String JavaDoc getPrefixString()
189         {
190             return "";
191         }
192     };
193
194     public abstract boolean isFixedString();
195
196     public abstract String JavaDoc getFixedString();
197
198     public abstract boolean isPrefixed();
199
200     public abstract String JavaDoc getPrefixString();
201
202     public boolean equals(String JavaDoc authority)
203     {
204         return equals(getAuthorityType(authority));
205     }
206
207     public static AuthorityType getAuthorityType(String JavaDoc authority)
208     {
209         AuthorityType authorityType;
210         if (authority.equals(PermissionService.ADMINISTRATOR_AUTHORITY))
211         {
212             authorityType = AuthorityType.ADMIN;
213         }
214         if (authority.equals(PermissionService.ALL_AUTHORITIES))
215         {
216             authorityType = AuthorityType.EVERYONE;
217         }
218         else if (authority.equals(PermissionService.OWNER_AUTHORITY))
219         {
220             authorityType = AuthorityType.OWNER;
221         }
222         else if (authority.equalsIgnoreCase(PermissionService.GUEST_AUTHORITY))
223         {
224             authorityType = AuthorityType.GUEST;
225         }
226         else if (authority.startsWith(PermissionService.GROUP_PREFIX))
227         {
228             authorityType = AuthorityType.GROUP;
229         }
230         else if (authority.startsWith(PermissionService.ROLE_PREFIX))
231         {
232             authorityType = AuthorityType.ROLE;
233         }
234         else
235         {
236             authorityType = AuthorityType.USER;
237         }
238         return authorityType;
239     }
240 }
241
Popular Tags