View Javadoc

1   package org.apache.turbine.om.security;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.sql.Connection;
23  import java.util.Iterator;
24  
25  import org.apache.turbine.services.security.TurbineSecurity;
26  import org.apache.turbine.util.security.PermissionSet;
27  import org.apache.turbine.util.security.TurbineSecurityException;
28  
29  /***
30   * This class represents a role played by the User associated with the
31   * current Session.
32   *
33   * @author <a href="mailto:frank.kim@clearink.com">Frank Y. Kim</a>
34   * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
35   * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
36   *
37   * @deprecated Use {@link org.apache.turbine.services.security.torque.TorqueRole}
38   * instead.
39   *
40   * @version $Id: TurbineRole.java 534527 2007-05-02 16:10:59Z tv $
41   */
42  public class TurbineRole extends SecurityObject implements Role
43  {
44      /*** Serial Version UID */
45      private static final long serialVersionUID = -1354408789347969126L;
46  
47      /***
48       * Constructs a new Role
49       */
50      public TurbineRole()
51      {
52          super();
53      }
54  
55      /***
56       * Constructs a new Role with the sepcified name.
57       *
58       * @param name The name of the new object.
59       */
60      public TurbineRole(String name)
61      {
62          super(name);
63      }
64  
65      /*** The permissions for this role. */
66      private PermissionSet permissionSet = null;
67  
68      /***
69       * Returns the set of Permissions associated with this Role.
70       *
71       * @return A PermissionSet.
72       * @exception Exception a generic exception.
73       */
74      public PermissionSet getPermissions()
75              throws Exception
76      {
77          return permissionSet;
78      }
79  
80      /***
81       * Sets the Permissions associated with this Role.
82       *
83       * @param permissionSet A PermissionSet.
84       */
85      public void setPermissions(PermissionSet permissionSet)
86      {
87          this.permissionSet = permissionSet;
88      }
89  
90      // These following methods are wrappers around TurbineSecurity
91  
92      /***
93       * Creates a new Role in the system.
94       *
95       * @param name The name of the new Role.
96       * @return An object representing the new Role.
97       * @throws TurbineSecurityException if the Role could not be created.
98       */
99      public Role create(String name)
100             throws TurbineSecurityException
101     {
102         //Role role = new Role(name);
103         Role role = new TurbineRole(name);
104         TurbineSecurity.addRole(role);
105         return role;
106     }
107 
108     /***
109      * Makes changes made to the Role attributes permanent.
110      *
111      * @throws TurbineSecurityException if there is a problem while
112      *  saving data.
113      */
114     public void save()
115             throws TurbineSecurityException
116     {
117         TurbineSecurity.saveRole(this);
118     }
119 
120     /***
121      * not implemented
122      *
123      * @param conn
124      * @throws Exception
125      */
126     public void save(Connection conn) throws Exception
127     {
128         throw new Exception("not implemented");
129     }
130 
131     /***
132      * not implemented
133      *
134      * @param dbname
135      * @throws Exception
136      */
137     public void save(String dbname) throws Exception
138     {
139         throw new Exception("not implemented");
140     }
141 
142     /***
143      * Removes a role from the system.
144      *
145      * @throws TurbineSecurityException if the Role could not be removed.
146      */
147     public void remove()
148             throws TurbineSecurityException
149     {
150         TurbineSecurity.removeRole(this);
151     }
152 
153     /***
154      * Renames the role.
155      *
156      * @param name The new Role name.
157      * @throws TurbineSecurityException if the Role could not be renamed.
158      */
159     public void rename(String name)
160             throws TurbineSecurityException
161     {
162         TurbineSecurity.renameRole(this, name);
163     }
164 
165     /***
166      * Grants a Permission to this Role.
167      *
168      * @param permission A Permission.
169      * @throws TurbineSecurityException if there is a problem while assigning
170      * the Permission.
171      */
172     public void grant(Permission permission)
173             throws TurbineSecurityException
174     {
175         TurbineSecurity.grant(this, permission);
176     }
177 
178     /***
179      * Grants Permissions from a PermissionSet to this Role.
180      *
181      * @param permissionSet A PermissionSet.
182      * @throws TurbineSecurityException if there is a problem while assigning
183      * the Permissions.
184      */
185     public void grant(PermissionSet permissionSet)
186             throws TurbineSecurityException
187     {
188         for (Iterator permissions = permissionSet.iterator(); permissions.hasNext();)
189         {
190             TurbineSecurity.grant(this, (Permission) permissions.next());
191         }
192     }
193 
194     /***
195      * Revokes a Permission from this Role.
196      *
197      * @param permission A Permission.
198      * @throws TurbineSecurityException if there is a problem while unassigning
199      * the Permission.
200      */
201     public void revoke(Permission permission)
202             throws TurbineSecurityException
203     {
204         TurbineSecurity.revoke(this, permission);
205     }
206 
207     /***
208      * Revokes Permissions from a PermissionSet from this Role.
209      *
210      * @param permissionSet A PermissionSet.
211      * @throws TurbineSecurityException if there is a problem while unassigning
212      * the Permissions.
213      */
214     public void revoke(PermissionSet permissionSet)
215             throws TurbineSecurityException
216     {
217         for (Iterator permissions = permissionSet.iterator(); permissions.hasNext();)
218         {
219             TurbineSecurity.revoke(this, (Permission) permissions.next());
220         }
221     }
222 }