1 package org.apache.turbine.services.security.torque; 2 3 18 19 import java.util.Iterator ; 20 21 import org.apache.turbine.om.security.Permission; 22 import org.apache.turbine.om.security.Role; 23 import org.apache.turbine.services.security.TurbineSecurity; 24 import org.apache.turbine.util.security.PermissionSet; 25 import org.apache.turbine.util.security.TurbineSecurityException; 26 27 import org.apache.torque.om.Persistent; 28 29 41 42 public class TorqueRole 43 extends TorqueObject 44 implements Role, 45 Comparable , 46 Persistent 47 { 48 49 private PermissionSet permissionSet = null; 50 51 54 public TorqueRole() 55 { 56 super(); 57 } 58 59 64 public TorqueRole(String name) 65 { 66 super(name); 67 } 68 69 76 public TorqueRole(Persistent obj) 77 { 78 super(obj); 79 } 80 81 89 90 public Persistent getPersistentObj() 91 { 92 if (obj == null) 93 { 94 obj = RolePeerManager.newPersistentInstance(); 95 } 96 return obj; 97 } 98 99 104 public String getName() 105 { 106 return RolePeerManager.getRoleName(getPersistentObj()); 107 } 108 109 114 public void setName(String name) 115 { 116 RolePeerManager.setRoleName(getPersistentObj(), name); 117 } 118 119 124 public int getId() 125 { 126 return RolePeerManager.getIdAsObj(getPersistentObj()).intValue(); 127 } 128 129 134 public Integer getIdAsObj() 135 { 136 return RolePeerManager.getIdAsObj(getPersistentObj()); 137 } 138 139 144 public void setId(int id) 145 { 146 RolePeerManager.setId(getPersistentObj(), id); 147 } 148 155 public PermissionSet getPermissions() 156 throws Exception 157 { 158 return permissionSet; 159 } 160 161 166 public void setPermissions(PermissionSet permissionSet) 167 { 168 this.permissionSet = permissionSet; 169 } 170 171 173 180 public Role create(String name) 181 throws TurbineSecurityException 182 { 183 return TurbineSecurity.createRole(name); 184 } 185 186 192 public void save() 193 throws TurbineSecurityException 194 { 195 TurbineSecurity.saveRole(this); 196 } 197 198 203 public void remove() 204 throws TurbineSecurityException 205 { 206 TurbineSecurity.removeRole(this); 207 } 208 209 215 public void rename(String name) 216 throws TurbineSecurityException 217 { 218 TurbineSecurity.renameRole(this, name); 219 } 220 221 228 public void grant(Permission permission) 229 throws TurbineSecurityException 230 { 231 TurbineSecurity.grant(this, permission); 232 } 233 234 241 public void grant(PermissionSet permissionSet) 242 throws TurbineSecurityException 243 { 244 Iterator permissions = permissionSet.iterator(); 245 while (permissions.hasNext()) 246 { 247 TurbineSecurity.grant(this, (Permission) permissions.next()); 248 } 249 } 250 251 258 public void revoke(Permission permission) 259 throws TurbineSecurityException 260 { 261 TurbineSecurity.revoke(this, permission); 262 } 263 264 271 public void revoke(PermissionSet permissionSet) 272 throws TurbineSecurityException 273 { 274 Iterator permissions = permissionSet.iterator(); 275 while (permissions.hasNext()) 276 { 277 TurbineSecurity.revoke(this, (Permission) permissions.next()); 278 } 279 } 280 } 281 | Popular Tags |