View Javadoc
1 package org.apache.turbine.om.security; 2 3 /* ==================================================================== 4 * The Apache Software License, Version 1.1 5 * 6 * Copyright (c) 2001 The Apache Software Foundation. All rights 7 * reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in 18 * the documentation and/or other materials provided with the 19 * distribution. 20 * 21 * 3. The end-user documentation included with the redistribution, 22 * if any, must include the following acknowledgment: 23 * "This product includes software developed by the 24 * Apache Software Foundation (http://www.apache.org/)." 25 * Alternately, this acknowledgment may appear in the software itself, 26 * if and wherever such third-party acknowledgments normally appear. 27 * 28 * 4. The names "Apache" and "Apache Software Foundation" and 29 * "Apache Turbine" must not be used to endorse or promote products 30 * derived from this software without prior written permission. For 31 * written permission, please contact apache@apache.org. 32 * 33 * 5. Products derived from this software may not be called "Apache", 34 * "Apache Turbine", nor may "Apache" appear in their name, without 35 * prior written permission of the Apache Software Foundation. 36 * 37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 48 * SUCH DAMAGE. 49 * ==================================================================== 50 * 51 * This software consists of voluntary contributions made by many 52 * individuals on behalf of the Apache Software Foundation. For more 53 * information on the Apache Software Foundation, please see 54 * <http://www.apache.org/>;. 55 */ 56 57 import java.sql.Connection; 58 import java.util.Iterator; 59 import org.apache.turbine.services.security.TurbineSecurity; 60 import org.apache.turbine.util.security.PermissionSet; 61 import org.apache.turbine.util.security.TurbineSecurityException; 62 63 /*** 64 * This class represents a role played by the User associated with the 65 * current Session. 66 * 67 * @author <a href="mailto:frank.kim@clearink.com">Frank Y. Kim</a> 68 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a> 69 * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a> 70 * @version $Id: TurbineRole.java,v 1.2 2002/07/11 07:34:30 mpoeschl Exp $ 71 */ 72 public class TurbineRole extends SecurityObject implements Role 73 { 74 /*** 75 * Constructs a new Role 76 */ 77 public TurbineRole() 78 { 79 super(); 80 } 81 82 /*** 83 * Constructs a new Role with the sepcified name. 84 * 85 * @param name The name of the new object. 86 */ 87 public TurbineRole( String name ) 88 { 89 super(name); 90 } 91 92 /*** The permissions for this role. */ 93 private PermissionSet permissionSet = null; 94 95 /*** 96 * Returns the set of Permissions associated with this Role. 97 * 98 * @return A PermissionSet. 99 * @exception Exception, a generic exception. 100 */ 101 public PermissionSet getPermissions() 102 throws Exception 103 { 104 return permissionSet; 105 } 106 107 /*** 108 * Sets the Permissions associated with this Role. 109 * 110 * @param permissionSet A PermissionSet. 111 */ 112 public void setPermissions(PermissionSet permissionSet) 113 { 114 this.permissionSet = permissionSet; 115 } 116 117 // These following methods are wrappers around TurbineSecurity 118 119 /*** 120 * Creates a new Role in the system. 121 * 122 * @param name The name of the new Role. 123 * @return An object representing the new Role. 124 * @throws TurbineSecurityException if the Role could not be created. 125 */ 126 public Role create( String name ) 127 throws TurbineSecurityException 128 { 129 //Role role = new Role(name); 130 Role role = new TurbineRole(name); 131 TurbineSecurity.addRole(role); 132 return role; 133 } 134 135 /*** 136 * Makes changes made to the Role attributes permanent. 137 * 138 * @throws TurbineSecurityException if there is a problem while 139 * saving data. 140 */ 141 public void save() 142 throws TurbineSecurityException 143 { 144 TurbineSecurity.saveRole(this); 145 } 146 147 /*** 148 * not implemented 149 * 150 * @param conn 151 * @throws Exception 152 */ 153 public void save(Connection conn) throws Exception 154 { 155 throw new Exception("not implemented"); 156 } 157 158 /*** 159 * not implemented 160 * 161 * @param dbname 162 * @throws Exception 163 */ 164 public void save(String dbname) throws Exception 165 { 166 throw new Exception("not implemented"); 167 } 168 169 /*** 170 * Removes a role from the system. 171 * 172 * @throws TurbineSecurityException if the Role could not be removed. 173 */ 174 public void remove() 175 throws TurbineSecurityException 176 { 177 TurbineSecurity.removeRole(this); 178 } 179 180 /*** 181 * Renames the role. 182 * 183 * @param name The new Role name. 184 * @throws TurbineSecurityException if the Role could not be renamed. 185 */ 186 public void rename(String name) 187 throws TurbineSecurityException 188 { 189 TurbineSecurity.renameRole(this, name); 190 } 191 192 /*** 193 * Grants a Permission to this Role. 194 * 195 * @param permission A Permission. 196 * @throws TurbineSecurityException if there is a problem while assigning 197 * the Permission. 198 */ 199 public void grant(Permission permission) 200 throws TurbineSecurityException 201 { 202 TurbineSecurity.grant(this, permission); 203 } 204 205 /*** 206 * Grants Permissions from a PermissionSet to this Role. 207 * 208 * @param permissionSet A PermissionSet. 209 * @throws TurbineSecurityException if there is a problem while assigning 210 * the Permissions. 211 */ 212 public void grant(PermissionSet permissionSet) 213 throws TurbineSecurityException 214 { 215 Iterator permissions = permissionSet.elements(); 216 while(permissions.hasNext()) 217 { 218 TurbineSecurity.grant(this, (Permission)permissions.next()); 219 } 220 } 221 222 /*** 223 * Revokes a Permission from this Role. 224 * 225 * @param permission A Permission. 226 * @throws TurbineSecurityException if there is a problem while unassigning 227 * the Permission. 228 */ 229 public void revoke(Permission permission) 230 throws TurbineSecurityException 231 { 232 TurbineSecurity.revoke(this, permission); 233 } 234 235 /*** 236 * Revokes Permissions from a PermissionSet from this Role. 237 * 238 * @param permissionSet A PermissionSet. 239 * @throws TurbineSecurityException if there is a problem while unassigning 240 * the Permissions. 241 */ 242 public void revoke(PermissionSet permissionSet) 243 throws TurbineSecurityException 244 { 245 Iterator permissions = permissionSet.elements(); 246 while(permissions.hasNext()) 247 { 248 TurbineSecurity.revoke(this, (Permission)permissions.next()); 249 } 250 } 251 }

This page was automatically generated by Maven