1 18 package org.apache.activemq.security; 19 20 import org.apache.activemq.command.ActiveMQDestination; 21 import org.apache.activemq.filter.DestinationMap; 22 23 import java.util.HashSet ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import java.util.Set ; 27 28 37 public class DefaultAuthorizationMap extends DestinationMap implements AuthorizationMap { 38 39 private AuthorizationEntry defaultEntry; 40 41 private TempDestinationAuthorizationEntry tempDestinationAuthorizationEntry; 42 43 public DefaultAuthorizationMap() { 44 } 45 46 public DefaultAuthorizationMap(List authorizationEntries) { 47 setAuthorizationEntries(authorizationEntries); 48 49 } 50 51 52 public void setTempDestinationAuthorizationEntry(TempDestinationAuthorizationEntry tempDestinationAuthorizationEntry) { 53 this.tempDestinationAuthorizationEntry = tempDestinationAuthorizationEntry; 54 } 55 56 public TempDestinationAuthorizationEntry getTempDestinationAuthorizationEntry() { 57 return this.tempDestinationAuthorizationEntry; 58 } 59 60 public Set getTempDestinationAdminACLs() { 61 if(tempDestinationAuthorizationEntry != null) 62 return tempDestinationAuthorizationEntry.getAdminACLs(); 63 else 64 return null; 65 } 66 67 public Set getTempDestinationReadACLs() { 68 if(tempDestinationAuthorizationEntry != null) 69 return tempDestinationAuthorizationEntry.getReadACLs(); 70 else 71 return null; 72 } 73 74 public Set getTempDestinationWriteACLs() { 75 if(tempDestinationAuthorizationEntry != null) 76 return tempDestinationAuthorizationEntry.getWriteACLs(); 77 else 78 return null; 79 } 80 81 public Set getAdminACLs(ActiveMQDestination destination) { 82 Set entries = getAllEntries(destination); 83 Set answer = new HashSet (); 84 for (Iterator iter = entries.iterator(); iter.hasNext();) { 86 AuthorizationEntry entry = (AuthorizationEntry) iter.next(); 87 answer.addAll(entry.getAdminACLs()); 88 } 89 return answer; 90 } 91 92 public Set getReadACLs(ActiveMQDestination destination) { 93 Set entries = getAllEntries(destination); 94 Set answer = new HashSet (); 95 96 for (Iterator iter = entries.iterator(); iter.hasNext();) { 98 AuthorizationEntry entry = (AuthorizationEntry) iter.next(); 99 answer.addAll(entry.getReadACLs()); 100 } 101 return answer; 102 } 103 104 public Set getWriteACLs(ActiveMQDestination destination) { 105 Set entries = getAllEntries(destination); 106 Set answer = new HashSet (); 107 108 for (Iterator iter = entries.iterator(); iter.hasNext();) { 110 AuthorizationEntry entry = (AuthorizationEntry) iter.next(); 111 answer.addAll(entry.getWriteACLs()); 112 } 113 return answer; 114 } 115 116 public AuthorizationEntry getEntryFor(ActiveMQDestination destination) { 117 AuthorizationEntry answer = (AuthorizationEntry) chooseValue(destination); 118 if (answer == null) { 119 answer = getDefaultEntry(); 120 } 121 return answer; 122 } 123 124 129 public void setAuthorizationEntries(List entries) { 130 super.setEntries(entries); 131 } 132 133 public AuthorizationEntry getDefaultEntry() { 134 return defaultEntry; 135 } 136 137 public void setDefaultEntry(AuthorizationEntry defaultEntry) { 138 this.defaultEntry = defaultEntry; 139 } 140 141 protected Class getEntryClass() { 142 return AuthorizationEntry.class; 143 } 144 protected Set getAllEntries(ActiveMQDestination destination) { 145 Set entries = get(destination); 146 if (defaultEntry != null) { 147 entries.add(defaultEntry); 148 } 149 return entries; 150 } 151 152 153 } 154 | Popular Tags |