users@glassfish.java.net

Re: Fetch all roles assigned to an user

From: <glassfish_at_javadesktop.org>
Date: Thu, 28 Aug 2008 03:18:42 PDT

A little update:

The code in the blog entry finds all declared roles for the current user. To find all groups for a user, no matter if they're declared or not, I changed Ron's code a bit:

        HashSet<String> groups = new HashSet<String>();
        Subject subject = (Subject) PolicyContext.getContext("javax.security.auth.Subject.container");
        Principal principal;
        
        if (subject != null) {
            Iterator<Principal> principals = subject.getPrincipals().iterator();
            
            while (principals.hasNext()) {
                principal = principals.next();

                if (principal instanceof Group) {
                    groups.add(principal.getName());
                }
            }
        }

Again, thanks Ron for pointing me to the right place!
[Message sent by forum member 'realsnowbird' (realsnowbird)]

http://forums.java.net/jive/thread.jspa?messageID=295853