1 22 package org.jboss.metadata; 23 24 import java.security.Principal ; 25 import java.util.HashMap ; 26 import java.util.HashSet ; 27 import java.util.Iterator ; 28 import java.util.Map ; 29 import java.util.Set ; 30 31 39 public class AssemblyDescriptorMetaData extends MetaData 40 { 41 42 private HashMap securityRoles = new HashMap (); 43 44 45 private HashMap messageDestinations = new HashMap (); 46 47 public void addSecurityRoleMetaData(SecurityRoleMetaData srMetaData) 48 { 49 securityRoles.put(srMetaData.getRoleName(), srMetaData); 50 } 51 52 public Map getSecurityRoles() 53 { 54 return new HashMap (securityRoles); 55 } 56 57 61 public void mergeSecurityRoles(Map applRoles) 62 { 63 Iterator it = applRoles.entrySet().iterator(); 64 while (it.hasNext()) 65 { 66 Map.Entry entry = (Map.Entry ) it.next(); 67 String roleName = (String )entry.getKey(); 68 SecurityRoleMetaData appRole = (SecurityRoleMetaData)entry.getValue(); 69 SecurityRoleMetaData srMetaData = (SecurityRoleMetaData)securityRoles.get(roleName); 70 if (srMetaData != null) 71 { 72 Set principalNames = appRole.getPrincipals(); 73 srMetaData.addPrincipalNames(principalNames); 74 } 75 else 76 { 77 securityRoles.put(roleName, entry.getValue()); 78 } 79 } 80 } 81 82 public SecurityRoleMetaData getSecurityRoleByName(String roleName) 83 { 84 return (SecurityRoleMetaData)securityRoles.get(roleName); 85 } 86 87 public Set getSecurityRoleNamesByPrincipal(String userName) 88 { 89 HashSet roleNames = new HashSet (); 90 Iterator it = securityRoles.values().iterator(); 91 while (it.hasNext()) 92 { 93 SecurityRoleMetaData srMetaData = (SecurityRoleMetaData) it.next(); 94 if (srMetaData.getPrincipals().contains(userName)) 95 roleNames.add(srMetaData.getRoleName()); 96 } 97 return roleNames; 98 } 99 100 104 public Map getPrincipalVersusRolesMap() 105 { 106 Map principalRolesMap = null; 107 108 Iterator iter = securityRoles.keySet().iterator(); 109 while(iter.hasNext()) 110 { 111 if(principalRolesMap == null) 112 principalRolesMap = new HashMap (); 113 String rolename = (String )iter.next(); 114 SecurityRoleMetaData srm = (SecurityRoleMetaData) securityRoles.get(rolename); 115 Iterator principalIter = srm.getPrincipals().iterator(); 116 while(principalIter.hasNext()) 117 { 118 String pr = (String )principalIter.next(); 119 Set roleset = (Set )principalRolesMap.get(pr); 120 if(roleset == null) 121 roleset = new HashSet (); 122 if(!roleset.contains(rolename)) 123 roleset.add(rolename); 124 principalRolesMap.put(pr, roleset); 125 } 126 } 127 return principalRolesMap; 128 } 129 130 public void addMessageDestinationMetaData(MessageDestinationMetaData metaData) 131 { 132 messageDestinations.put(metaData.getName(), metaData); 133 } 134 135 public MessageDestinationMetaData getMessageDestinationMetaData(String name) 136 { 137 return (MessageDestinationMetaData) messageDestinations.get(name); 138 } 139 } 140 | Popular Tags |