1 18 package org.apache.activemq.security; 19 20 import java.util.HashSet ; 21 import java.util.Set ; 22 import java.util.Collections ; 23 import java.util.concurrent.ConcurrentHashMap ; 24 25 30 abstract public class SecurityContext { 31 32 public static final SecurityContext BROKER_SECURITY_CONTEXT = new SecurityContext("ActiveMQBroker") { 33 @Override 34 public boolean isBrokerContext() { 35 return true; 36 } 37 38 public Set getPrincipals() { 39 return Collections.EMPTY_SET; 40 } 41 }; 42 43 final String userName; 44 45 final ConcurrentHashMap authorizedReadDests = new ConcurrentHashMap (); 46 final ConcurrentHashMap authorizedWriteDests = new ConcurrentHashMap (); 47 48 public SecurityContext(String userName) { 49 this.userName = userName; 50 } 51 52 public boolean isInOneOf(Set allowedPrincipals) { 53 HashSet set = new HashSet (getPrincipals()); 54 set.retainAll(allowedPrincipals); 55 return set.size()>0; 56 } 57 58 abstract public Set getPrincipals(); 59 60 public String getUserName() { 61 return userName; 62 } 63 64 public ConcurrentHashMap getAuthorizedReadDests() { 65 return authorizedReadDests; 66 } 67 68 public ConcurrentHashMap getAuthorizedWriteDests() { 69 return authorizedWriteDests; 70 } 71 72 public boolean isBrokerContext() { 73 return false; 74 } 75 } 76 | Popular Tags |