KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.Set JavaDoc;
20
21 /**
22  * The service that encapsulates authorities granted to users.
23  *
24  * This service will refuse to create any user authorities. These should be
25  * managed using the AuthenticationService and PersonServce. Methods that try to
26  * change alter users will throw an exception.
27  *
28  * A string key is used to identify the authority. These follow the contract
29  * defined in AuthorityType. If there are entities linked to these authorities
30  * this key should be used to find them, as userName is used link user and
31  * person.
32  *
33  * @author Andy Hind
34  */

35 public interface AuthorityService
36 {
37     /**
38      * Check of the current user has admin authority.
39      *
40      * There is no contract for who should have this authority, only that it can
41      * be tested here. It could be determined by group membership, role,
42      * authentication mechanism, ...
43      *
44      * @return true if the currently authenticated user has the admin authority
45      */

46     public boolean hasAdminAuthority();
47
48     /**
49      * Get the authorities for the current user
50      *
51      * @return
52      */

53     public Set JavaDoc<String JavaDoc> getAuthorities();
54
55     /**
56      * Get all authorities by type.
57      *
58      * @param type -
59      * the type of authorities.
60      * @return
61      */

62     public Set JavaDoc<String JavaDoc> getAllAuthorities(AuthorityType type);
63
64     /**
65      * Get all root authorities by type. Root authorities are ones that were
66      * created without an authority as the parent authority;
67      *
68      * @param type -
69      * the type of the authority
70      * @return
71      */

72
73     public Set JavaDoc<String JavaDoc> getAllRootAuthorities(AuthorityType type);
74
75     /**
76      * Create an authority. If the parent is null thisw method creates a root
77      * authority.
78      *
79      * @param type -
80      * the type of the authority
81      * @param parentName -
82      * the name of the parent authority. If this is null then a root
83      * authority is created.
84      * @param shortName -
85      * the short name of the authority to create
86      *
87      * @return the name of the authority (this will be the prefix, if any
88      * associated with the type appended with the short name)
89      */

90     public String JavaDoc createAuthority(AuthorityType type, String JavaDoc parentName, String JavaDoc shortName);
91
92     /**
93      * Set an authority to include another authority. For example, adding a
94      * group to a group or adding a user to a group.
95      *
96      * @param parentName -
97      * the string identifier for the parent.
98      * @param childName -
99      * the string identifier for the child.
100      */

101     public void addAuthority(String JavaDoc parentName, String JavaDoc childName);
102
103     /**
104      * Remove an authority as a member of another authority. The child authority
105      * will still exist. If the child authority was not created as a root
106      * authority and you remove its creation link, it will be moved to a root
107      * authority. If you want rid of it, use delete.
108      *
109      * @param parentName -
110      * the string identifier for the parent.
111      * @param childName -
112      * the string identifier for the child.
113      */

114     public void removeAuthority(String JavaDoc parentName, String JavaDoc childName);
115
116     /**
117      * Delete an authority and all its relationships.
118      *
119      * @param name
120      */

121     public void deleteAuthority(String JavaDoc name);
122
123     /**
124      * Get all the authorities that are contained by the given authority.
125      *
126      * For a group you could get all the authorities it contains, just the users
127      * it contains or just the other groups it includes.
128      *
129      * @param type -
130      * if not null, limit to the type of authority specified
131      * @param name -
132      * the name of the containing authority
133      * @param immediate -
134      * if true, limit the depth to just immediate child, if false
135      * find authorities at any depth
136      * @return
137      */

138     public Set JavaDoc<String JavaDoc> getContainedAuthorities(AuthorityType type, String JavaDoc name, boolean immediate);
139
140     /**
141      * Get the authorities that contain the given authority
142      *
143      * For example, this can be used find out all the authorities that contain a
144      * user.
145      *
146      * @param type -
147      * if not null, limit to the type of authority specified
148      * @param name -
149      * the name of the authority for which the containing authorities
150      * are required.
151      * @param immediate -
152      * limit to immediate parents or any ancestor.
153      * @return
154      */

155     public Set JavaDoc<String JavaDoc> getContainingAuthorities(AuthorityType type, String JavaDoc name, boolean immediate);
156
157     /**
158      * Extract the short name of an authority from its full identifier.
159      *
160      * @param name
161      * @return
162      */

163     public String JavaDoc getShortName(String JavaDoc name);
164
165     /**
166      * Create the full identifier for an authority given its short name and
167      * type.
168      *
169      * @param type
170      * @param shortName
171      * @return
172      */

173     public String JavaDoc getName(AuthorityType type, String JavaDoc shortName);
174
175 }
176
Popular Tags