You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2004/09/23 23:13:20 UTC
cvs commit: jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security SecurityHelper.java
taylor 2004/09/23 14:13:20
Modified: components/security/src/java/org/apache/jetspeed/security
SecurityHelper.java
Log:
helper function to get a list of all principals of a given Principal class
CVS: ----------------------------------------------------------------------
CVS: PR:
CVS: If this change addresses a PR in the problem report tracking
CVS: database, then enter the PR number(s) here.
CVS: Obtained from:
CVS: If this change has been taken from another system, such as NCSA,
CVS: then name the system in this line, otherwise delete it.
CVS: Submitted by:
CVS: If this code has been contributed to Apache by someone else; i.e.,
CVS: they sent us a patch or a new module, then include their name/email
CVS: address here. If this is your work then delete this line.
CVS: Reviewed by:
CVS: If we are doing pre-commit code reviews and someone else has
CVS: reviewed your changes, include their name(s) here.
CVS: If you have not had it reviewed then delete this line.
Revision Changes Path
1.5 +26 -1 jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/SecurityHelper.java
Index: SecurityHelper.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/SecurityHelper.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SecurityHelper.java 18 Sep 2004 19:33:35 -0000 1.4
+++ SecurityHelper.java 23 Sep 2004 21:13:20 -0000 1.5
@@ -17,6 +17,8 @@
import java.security.Principal;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Set;
import javax.security.auth.Subject;
@@ -126,4 +128,27 @@
principals.add(principal);
return new Subject(true, principals, new HashSet(), new HashSet());
}
+
+ /**
+ * <p>Given a subject, finds all principals of the given classe for that subject.
+ * If no principals of the given class is not found, null is returned.</p>
+ * @param subject The subject supplying the principals.
+ * @param classe A class or interface derived from java.security.InternalPrincipal.
+ * @return A List of all principals of type Principal matching a principal classe parameter.
+ */
+ public static List getPrincipals(Subject subject, Class classe)
+ {
+ List result = new LinkedList();
+ Iterator principals = subject.getPrincipals().iterator();
+ while (principals.hasNext())
+ {
+ Principal p = (Principal) principals.next();
+ if (classe.isInstance(p))
+ {
+ result.add(p);
+ }
+ }
+ return result;
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org