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.util.Iterator; 58 import org.apache.turbine.services.security.TurbineSecurity; 59 import org.apache.turbine.util.security.PermissionSet; 60 import org.apache.turbine.util.security.TurbineSecurityException; 61 62 /*** 63 * This class represents a role played by the User associated with the 64 * current Session. 65 * 66 * @author <a href="mailto:frank.kim@clearink.com">Frank Y. Kim</a> 67 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a> 68 * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a> 69 * @version $Id$ 70 */ 71 public class TurbineRole extends SecurityObject implements Role 72 { 73 /*** 74 * Constructs a new Role 75 */ 76 public TurbineRole() 77 { 78 super(); 79 } 80 81 /*** 82 * Constructs a new Role with the sepcified name. 83 * 84 * @param name The name of the new object. 85 */ 86 public TurbineRole( String name ) 87 { 88 super(name); 89 } 90 91 /*** The permissions for this role. */ 92 private PermissionSet permissionSet = null; 93 94 /*** 95 * Returns the set of Permissions associated with this Role. 96 * 97 * @return A PermissionSet. 98 * @exception Exception, a generic exception. 99 */ 100 public PermissionSet getPermissions() 101 throws Exception 102 { 103 return permissionSet; 104 } 105 106 /*** 107 * Sets the Permissions associated with this Role. 108 * 109 * @param permissionSet A PermissionSet. 110 */ 111 public void setPermissions(PermissionSet permissionSet) 112 { 113 this.permissionSet = permissionSet; 114 } 115 116 // These following methods are wrappers around TurbineSecurity 117 118 /*** 119 * Creates a new Role in the system. 120 * 121 * @param name The name of the new Role. 122 * @return An object representing the new Role. 123 * @throws TurbineSecurityException if the Role could not be created. 124 */ 125 public Role create( String name ) 126 throws TurbineSecurityException 127 { 128 //Role role = new Role(name); 129 Role role = new TurbineRole(name); 130 TurbineSecurity.addRole(role); 131 return role; 132 } 133 134 /*** 135 * Makes changes made to the Role attributes permanent. 136 * 137 * @throws TurbineSecurityException if there is a problem while 138 * saving data. 139 */ 140 public void save() 141 throws TurbineSecurityException 142 { 143 TurbineSecurity.saveRole(this); 144 } 145 146 /*** 147 * Removes a role from the system. 148 * 149 * @throws TurbineSecurityException if the Role could not be removed. 150 */ 151 public void remove() 152 throws TurbineSecurityException 153 { 154 TurbineSecurity.removeRole(this); 155 } 156 157 /*** 158 * Renames the role. 159 * 160 * @param name The new Role name. 161 * @throws TurbineSecurityException if the Role could not be renamed. 162 */ 163 public void rename(String name) 164 throws TurbineSecurityException 165 { 166 TurbineSecurity.renameRole(this, name); 167 } 168 169 /*** 170 * Grants a Permission to this Role. 171 * 172 * @param permission A Permission. 173 * @throws TurbineSecurityException if there is a problem while assigning 174 * the Permission. 175 */ 176 public void grant(Permission permission) 177 throws TurbineSecurityException 178 { 179 TurbineSecurity.grant(this, permission); 180 } 181 182 /*** 183 * Grants Permissions from a PermissionSet to this Role. 184 * 185 * @param permissionSet A PermissionSet. 186 * @throws TurbineSecurityException if there is a problem while assigning 187 * the Permissions. 188 */ 189 public void grant(PermissionSet permissionSet) 190 throws TurbineSecurityException 191 { 192 Iterator permissions = permissionSet.elements(); 193 while(permissions.hasNext()) 194 { 195 TurbineSecurity.grant(this, (Permission)permissions.next()); 196 } 197 } 198 199 /*** 200 * Revokes a Permission from this Role. 201 * 202 * @param permission A Permission. 203 * @throws TurbineSecurityException if there is a problem while unassigning 204 * the Permission. 205 */ 206 public void revoke(Permission permission) 207 throws TurbineSecurityException 208 { 209 TurbineSecurity.revoke(this, permission); 210 } 211 212 /*** 213 * Revokes Permissions from a PermissionSet from this Role. 214 * 215 * @param permissionSet A PermissionSet. 216 * @throws TurbineSecurityException if there is a problem while unassigning 217 * the Permissions. 218 */ 219 public void revoke(PermissionSet permissionSet) 220 throws TurbineSecurityException 221 { 222 Iterator permissions = permissionSet.elements(); 223 while(permissions.hasNext()) 224 { 225 TurbineSecurity.revoke(this, (Permission)permissions.next()); 226 } 227 } 228 }

This page was automatically generated by Maven