1 16 17 18 package org.apache.jetspeed.services.security; 19 20 import java.util.HashMap ; 21 import java.util.Iterator ; 22 23 import org.apache.jetspeed.om.security.BaseJetspeedGroup; 24 import org.apache.jetspeed.om.security.BaseJetspeedGroupRole; 25 import org.apache.jetspeed.om.security.Group; 26 import org.apache.jetspeed.om.security.GroupRole; 27 import org.apache.jetspeed.om.security.Role; 28 29 36 public class CachedAcl 37 { 38 protected HashMap groupRoles = new HashMap (); 39 protected String userName; 40 41 44 public CachedAcl(String userName) 45 { 46 this.userName = userName; 47 } 48 49 52 public void addRole(Role role) 53 { 54 Group group = new BaseJetspeedGroup(); 55 group.setName(GroupManagement.DEFAULT_GROUP_NAME); 56 addRole(role, group); 57 } 58 59 63 public void addRole(Role role, Group group) 64 { 65 GroupRole gr = new BaseJetspeedGroupRole(); 66 gr.setRole(role); 67 gr.setGroup(group); 68 String key = getGroupRoleKey(group.getName(), role.getName()); 69 groupRoles.put(key, gr); 70 } 71 72 76 public Role getRole(String roleName) 77 { 78 return getRole(roleName, GroupManagement.DEFAULT_GROUP_NAME); 79 } 80 81 86 public Role getRole(String roleName, String groupName) 87 { 88 GroupRole gr = (GroupRole) groupRoles.get(getGroupRoleKey(groupName, roleName)); 89 return gr != null ? gr.getRole() : null; 90 } 91 92 95 public Iterator getRoles() 96 { 97 return groupRoles.values().iterator(); 98 } 99 100 103 public String getUserName() 104 { 105 return this.userName; 106 } 107 108 112 public boolean hasRole(String roleName) 113 { 114 return hasRole(roleName, GroupManagement.DEFAULT_GROUP_NAME); 115 } 116 117 122 public boolean hasRole(String roleName, String groupName) 123 { 124 return groupRoles.containsKey(getGroupRoleKey(groupName, roleName)); 125 } 126 127 130 public void removeRole(String roleName) 131 { 132 removeRole(roleName, GroupManagement.DEFAULT_GROUP_NAME); 133 } 134 135 139 public void removeRole(String roleName, String groupName) 140 { 141 groupRoles.remove(getGroupRoleKey(groupName, roleName)); 142 } 143 144 147 public void setRoles(Iterator grouproles) 148 { 149 while (grouproles.hasNext()) 150 { 151 GroupRole grouprole = (GroupRole) grouproles.next(); 152 String key = getGroupRoleKey(grouprole.getGroup().getName(), grouprole.getRole().getName()); 153 this.groupRoles.put(key, grouprole); 154 } 155 } 156 157 162 private String getGroupRoleKey(String groupName, String roleName) 163 { 164 StringBuffer key = new StringBuffer (); 165 key.append(groupName); 166 key.append(roleName); 167 168 return key.toString(); 169 } 170 171 } 172 | Popular Tags |