KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > services > security > JetspeedPermissionManagement


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

16
17 package org.apache.jetspeed.services.security;
18
19 import java.util.Iterator JavaDoc;
20
21
22 // Turbine
23
import org.apache.turbine.services.TurbineServices;
24
25
26 import org.apache.jetspeed.om.security.Permission;
27
28 /**
29  * <p> The <code>PermissionManagement</code> interface describes contract between
30  * the portal and security provider required for Jetspeed Permission Management.
31  * This interface enables an application to be independent of the underlying
32  * permission management technology.
33  *
34  * @author <a HREF="mailto:david@bluesunrise.com">David Sean Taylor</a>
35  * @version $Id: JetspeedPermissionManagement.java,v 1.4 2004/02/23 03:58:11 jford Exp $
36  */

37
38 public abstract class JetspeedPermissionManagement
39 {
40     public String JavaDoc SERVICE_NAME = "PermissionManagement";
41
42     /*
43      * Utility method for accessing the service
44      * implementation
45      *
46      * @return a PermissionManagement implementation instance
47      */

48     protected static PermissionManagement getService()
49     {
50         return (PermissionManagement)TurbineServices
51         .getInstance().getService(PermissionManagement.SERVICE_NAME);
52     }
53
54     /**
55      * Retrieves all <code>Permission</code>s for a given rolename principal.
56      *
57      * The security service may optionally check the current user context
58      * to determine if the requestor has permission to perform this action.
59      *
60      * @param rolename a role name identity to be retrieved.
61      * @return Iterator over all permissions associated to the role principal.
62      * @exception PermissionException when the security provider has a general failure.
63      * @exception InsufficientPrivilegeException when the requestor is denied due to insufficient privilege
64      */

65     public static Iterator JavaDoc getPermissions(String JavaDoc rolename)
66         throws JetspeedSecurityException
67     {
68         return getService().getPermissions(rolename);
69     }
70
71     /**
72      * Retrieves all <code>Permission</code>s.
73      *
74      * The security service may optionally check the current user context
75      * to determine if the requestor has permission to perform this action.
76      *
77      * @return Iterator over all permissions.
78      * @exception PermissionException when the security provider has a general failure.
79      * @exception InsufficientPrivilegeException when the requestor is denied due to insufficient privilege
80      */

81     public static Iterator JavaDoc getPermissions()
82         throws JetspeedSecurityException
83     {
84         return getService().getPermissions();
85     }
86
87     /**
88      * Adds a <code>Permission</code> into permanent storage.
89      *
90      * The security service may optionally check the current user context
91      * to determine if the requestor has permission to perform this action.
92      *
93      * @exception PermissionException when the security provider has a general failure.
94      * @exception InsufficientPrivilegeException when the requestor is denied due to insufficient privilege
95      */

96     public static void addPermission(Permission permission)
97         throws JetspeedSecurityException
98     {
99         getService().addPermission(permission);
100     }
101
102     /**
103      * Saves a <code>Permission</code> into permanent storage.
104      *
105      * The security service may optionally check the current user context
106      * to determine if the requestor has permission to perform this action.
107      *
108      * @exception PermissionException when the security provider has a general failure.
109      * @exception InsufficientPrivilegeException when the requestor is denied due to insufficient privilege
110      */

111     public static void savePermission(Permission permission)
112         throws JetspeedSecurityException
113     {
114         getService().savePermission(permission);
115     }
116
117     /**
118      * Removes a <code>Permission</code> from the permanent store.
119      *
120      * The security service may optionally check the current user context
121      * to determine if the requestor has permission to perform this action.
122      *
123      * @param permissionName the principal identity of the permission to be retrieved.
124      * @exception PermissionException when the security provider has a general failure.
125      * @exception InsufficientPrivilegeException when the requestor is denied due to insufficient privilege
126      */

127     public static void removePermission(String JavaDoc permissionName)
128         throws JetspeedSecurityException
129     {
130         getService().removePermission(permissionName);
131     }
132
133     /**
134      * Grants a permission to a role.
135      *
136      * The security service may optionally check the current user context
137      * to determine if the requestor has permission to perform this action.
138      *
139      * @param roleName grant a permission to this role.
140      * @param permissionName the permission to grant to the role.
141      * @exception PermissionException when the security provider has a general failure retrieving permissions.
142      * @exception InsufficientPrivilegeException when the requestor is denied due to insufficient privilege
143      */

144     public static void grantPermission(String JavaDoc roleName, String JavaDoc permissionName)
145         throws JetspeedSecurityException
146     {
147         getService().grantPermission(roleName, permissionName);
148     }
149
150     /**
151      * Revokes a permission from a role.
152      *
153      * The security service may optionally check the current user context
154      * to determine if the requestor has permission to perform this action.
155      *
156      * @param roleName grant a permission to this role.
157      * @param permissionName the permission to grant to the role.
158      * @exception PermissionException when the security provider has a general failure retrieving permissions.
159      * @exception InsufficientPrivilegeException when the requestor is denied due to insufficient privilege
160      */

161     public static void revokePermission(String JavaDoc roleName, String JavaDoc permissionName)
162         throws JetspeedSecurityException
163     {
164         getService().revokePermission(roleName,permissionName);
165     }
166
167     /**
168      * Checks for the relationship of role has a permission. Returns true when the role has the given permission.
169      *
170      * The security service may optionally check the current user context
171      * to determine if the requestor has permission to perform this action.
172      *
173      * @param roleName grant a permission to this role.
174      * @param permissionName the permission to grant to the role.
175      * @exception PermissionException when the security provider has a general failure retrieving permissions.
176      * @exception InsufficientPrivilegeException when the requestor is denied due to insufficient privilege
177      */

178     public static boolean hasPermission(String JavaDoc roleName, String JavaDoc permissionName)
179         throws JetspeedSecurityException
180     {
181         return getService().hasPermission(roleName,permissionName);
182     }
183
184     /**
185      * Retrieves a single <code>Permission</code> for a given permissionName principal.
186      *
187      * The security service may optionally check the current user context
188      * to determine if the requestor has permission to perform this action.
189      *
190      * @param permissionName a permission principal identity to be retrieved.
191      * @return Permission the permission record retrieved.
192      * @exception PermissionException when the security provider has a general failure.
193      * @exception InsufficientPrivilegeException when the requestor is denied due to insufficient privilege
194      */

195     public static Permission getPermission(String JavaDoc permissionName)
196         throws JetspeedSecurityException
197     {
198         return getService().getPermission(permissionName);
199     }
200
201 }
202
203
204
205
206
207
208
209
210
211
212
213
Popular Tags