From c6de4d7e56b79cc0d567836bc26cb061f07c1d9d Mon Sep 17 00:00:00 2001 From: Bosanac Dejan Date: Fri, 18 Dec 2009 11:12:32 +0000 Subject: [PATCH] https://issues.apache.org/activemq/browse/AMQ-2508 - SecurityContext.isInOneOf() git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@892220 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/activemq/security/SecurityContext.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/security/SecurityContext.java b/activemq-core/src/main/java/org/apache/activemq/security/SecurityContext.java index 40f8057f21..0d6a665291 100644 --- a/activemq-core/src/main/java/org/apache/activemq/security/SecurityContext.java +++ b/activemq-core/src/main/java/org/apache/activemq/security/SecurityContext.java @@ -18,6 +18,7 @@ package org.apache.activemq.security; import java.util.Collections; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -52,9 +53,17 @@ public abstract class SecurityContext { } public boolean isInOneOf(Set allowedPrincipals) { - HashSet set = new HashSet(getPrincipals()); - set.retainAll(allowedPrincipals); - return set.size() > 0; + Iterator allowedIter = allowedPrincipals.iterator(); + HashSet userPrincipals = new HashSet(getPrincipals()); + while (allowedIter.hasNext()) { + Iterator userIter = userPrincipals.iterator(); + Object allowedPrincipal = allowedIter.next(); + while (userIter.hasNext()) { + if (allowedPrincipal.equals(userIter.next())) + return true; + } + } + return false; } public abstract Set getPrincipals();