1 package org.apache.fulcrum.security.impl.db.entity; 2 3 56 57 import java.util.Iterator ; 58 import org.apache.fulcrum.security.TurbineSecurity; 59 import org.apache.fulcrum.security.entity.Permission; 60 import org.apache.fulcrum.security.entity.Role; 61 import org.apache.fulcrum.security.entity.SecurityEntity; 62 import org.apache.fulcrum.security.util.PermissionSet; 63 import org.apache.fulcrum.security.util.TurbineSecurityException; 64 65 75 public class TurbineRole 76 extends org.apache.fulcrum.security.impl.db.entity.BaseTurbineRole 77 implements Role, Comparable 78 { 79 80 81 private PermissionSet permissionSet = null; 82 83 86 public TurbineRole() 87 { 88 } 89 90 95 public TurbineRole(String name) 96 { 97 this.setName(name); 98 } 99 100 106 public PermissionSet getPermissions() 107 throws Exception 108 { 109 return permissionSet; 110 } 111 112 117 public void setPermissions(PermissionSet permissionSet) 118 { 119 this.permissionSet = permissionSet; 120 } 121 122 124 131 public Role create(String name) 132 throws TurbineSecurityException 133 { 134 Role role = new TurbineRole(name); 136 TurbineSecurity.addRole(role); 137 return role; 138 } 139 140 146 public void save() 147 throws TurbineSecurityException 148 { 149 TurbineSecurity.saveRole(this); 150 } 151 152 157 public void remove() 158 throws TurbineSecurityException 159 { 160 TurbineSecurity.removeRole(this); 161 } 162 163 169 public void rename(String name) 170 throws TurbineSecurityException 171 { 172 TurbineSecurity.renameRole(this, name); 173 } 174 175 182 public void grant(Permission permission) 183 throws TurbineSecurityException 184 { 185 TurbineSecurity.grant(this, permission); 186 } 187 188 195 public void grant(PermissionSet permissionSet) 196 throws TurbineSecurityException 197 { 198 Iterator permissions = permissionSet.elements(); 199 while(permissions.hasNext()) 200 { 201 TurbineSecurity.grant(this, (Permission)permissions.next()); 202 } 203 } 204 205 212 public void revoke(Permission permission) 213 throws TurbineSecurityException 214 { 215 TurbineSecurity.revoke(this, permission); 216 } 217 218 225 public void revoke(PermissionSet permissionSet) 226 throws TurbineSecurityException 227 { 228 Iterator permissions = permissionSet.elements(); 229 while(permissions.hasNext()) 230 { 231 TurbineSecurity.revoke(this, (Permission)permissions.next()); 232 } 233 } 234 235 242 public int compareTo(Object obj) 243 { 244 if(this.getClass() != obj.getClass()) 245 throw new ClassCastException (); 246 String name1 = ((SecurityEntity)obj).getName(); 247 String name2 = this.getName(); 248 249 return name2.compareTo(name1); 250 } 251 252 } 253 | Popular Tags |