001: package org.apache.turbine.om.security;
002:
003: /*
004: * Copyright 2001-2005 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License")
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import java.sql.Connection;
020: import java.util.Iterator;
021:
022: import org.apache.turbine.services.security.TurbineSecurity;
023: import org.apache.turbine.util.security.PermissionSet;
024: import org.apache.turbine.util.security.TurbineSecurityException;
025:
026: /**
027: * This class represents a role played by the User associated with the
028: * current Session.
029: *
030: * @author <a href="mailto:frank.kim@clearink.com">Frank Y. Kim</a>
031: * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
032: * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
033: * @version $Id: TurbineRole.java 278822 2005-09-05 19:53:05Z henning $
034: */
035: public class TurbineRole extends SecurityObject implements Role {
036: /** Serial Version UID */
037: private static final long serialVersionUID = -1354408789347969126L;
038:
039: /**
040: * Constructs a new Role
041: */
042: public TurbineRole() {
043: super ();
044: }
045:
046: /**
047: * Constructs a new Role with the sepcified name.
048: *
049: * @param name The name of the new object.
050: */
051: public TurbineRole(String name) {
052: super (name);
053: }
054:
055: /** The permissions for this role. */
056: private PermissionSet permissionSet = null;
057:
058: /**
059: * Returns the set of Permissions associated with this Role.
060: *
061: * @return A PermissionSet.
062: * @exception Exception a generic exception.
063: */
064: public PermissionSet getPermissions() throws Exception {
065: return permissionSet;
066: }
067:
068: /**
069: * Sets the Permissions associated with this Role.
070: *
071: * @param permissionSet A PermissionSet.
072: */
073: public void setPermissions(PermissionSet permissionSet) {
074: this .permissionSet = permissionSet;
075: }
076:
077: // These following methods are wrappers around TurbineSecurity
078:
079: /**
080: * Creates a new Role in the system.
081: *
082: * @param name The name of the new Role.
083: * @return An object representing the new Role.
084: * @throws TurbineSecurityException if the Role could not be created.
085: */
086: public Role create(String name) throws TurbineSecurityException {
087: //Role role = new Role(name);
088: Role role = new TurbineRole(name);
089: TurbineSecurity.addRole(role);
090: return role;
091: }
092:
093: /**
094: * Makes changes made to the Role attributes permanent.
095: *
096: * @throws TurbineSecurityException if there is a problem while
097: * saving data.
098: */
099: public void save() throws TurbineSecurityException {
100: TurbineSecurity.saveRole(this );
101: }
102:
103: /**
104: * not implemented
105: *
106: * @param conn
107: * @throws Exception
108: */
109: public void save(Connection conn) throws Exception {
110: throw new Exception("not implemented");
111: }
112:
113: /**
114: * not implemented
115: *
116: * @param dbname
117: * @throws Exception
118: */
119: public void save(String dbname) throws Exception {
120: throw new Exception("not implemented");
121: }
122:
123: /**
124: * Removes a role from the system.
125: *
126: * @throws TurbineSecurityException if the Role could not be removed.
127: */
128: public void remove() throws TurbineSecurityException {
129: TurbineSecurity.removeRole(this );
130: }
131:
132: /**
133: * Renames the role.
134: *
135: * @param name The new Role name.
136: * @throws TurbineSecurityException if the Role could not be renamed.
137: */
138: public void rename(String name) throws TurbineSecurityException {
139: TurbineSecurity.renameRole(this , name);
140: }
141:
142: /**
143: * Grants a Permission to this Role.
144: *
145: * @param permission A Permission.
146: * @throws TurbineSecurityException if there is a problem while assigning
147: * the Permission.
148: */
149: public void grant(Permission permission)
150: throws TurbineSecurityException {
151: TurbineSecurity.grant(this , permission);
152: }
153:
154: /**
155: * Grants Permissions from a PermissionSet to this Role.
156: *
157: * @param permissionSet A PermissionSet.
158: * @throws TurbineSecurityException if there is a problem while assigning
159: * the Permissions.
160: */
161: public void grant(PermissionSet permissionSet)
162: throws TurbineSecurityException {
163: for (Iterator permissions = permissionSet.iterator(); permissions
164: .hasNext();) {
165: TurbineSecurity
166: .grant(this , (Permission) permissions.next());
167: }
168: }
169:
170: /**
171: * Revokes a Permission from this Role.
172: *
173: * @param permission A Permission.
174: * @throws TurbineSecurityException if there is a problem while unassigning
175: * the Permission.
176: */
177: public void revoke(Permission permission)
178: throws TurbineSecurityException {
179: TurbineSecurity.revoke(this , permission);
180: }
181:
182: /**
183: * Revokes Permissions from a PermissionSet from this Role.
184: *
185: * @param permissionSet A PermissionSet.
186: * @throws TurbineSecurityException if there is a problem while unassigning
187: * the Permissions.
188: */
189: public void revoke(PermissionSet permissionSet)
190: throws TurbineSecurityException {
191: for (Iterator permissions = permissionSet.iterator(); permissions
192: .hasNext();) {
193: TurbineSecurity.revoke(this , (Permission) permissions
194: .next());
195: }
196: }
197: }
|