1 43 package net.jforum.security; 44 45 import java.io.Serializable ; 46 47 import net.jforum.dao.security.SecurityDAO; 48 49 56 public class PermissionControl implements Serializable 57 { 58 public static final int ROLE_DENY = 0; 59 public static final int ROLE_ALLOW = 1; 60 61 private RoleCollection roles; 62 private SecurityDAO smodel; 63 64 public void setRoles(RoleCollection roles) 65 { 66 this.roles = roles; 67 } 68 69 public void setSecurityModel(SecurityDAO smodel) 70 { 71 this.smodel = smodel; 72 } 73 74 public void addRole(int id, Role role) throws Exception 75 { 76 this.smodel.addRole(id, role); 77 } 78 79 public void addRole(int id, Role role, RoleValueCollection roleValues) throws Exception 80 { 81 this.smodel.addRole(id, role, roleValues); 82 } 83 84 public void addRoleValue(int id, Role role, RoleValueCollection roleValues) throws Exception 85 { 86 this.smodel.addRoleValue(id, role, roleValues); 87 } 88 89 public void deleteAllRoles(int id) throws Exception 90 { 91 this.smodel.deleteAllRoles(id); 92 } 93 94 100 public Role getRole(String roleName) 101 { 102 return this.roles.get(roleName); 103 } 104 105 108 public boolean canAccess(String roleName) 109 { 110 Role role = this.roles.get(roleName); 111 return (role != null && role.getType() == PermissionControl.ROLE_ALLOW); 112 } 113 114 117 public boolean canAccess(String roleName, String roleValue) 118 { 119 Role role = this.roles.get(roleName); 120 if (role == null) { 121 return false; 122 } 123 124 RoleValue rv = new RoleValue(); 125 rv.setType(PermissionControl.ROLE_ALLOW); 126 rv.setValue(roleValue); 127 128 return role.getValues().contains(rv); 129 } 130 } 131 | Popular Tags |