import java.security.acl.Group;
import javax.security.auth.Subject;
import java.security.Principal;
import java.util.HashSet;
import java.util.Set;
import java.util.Enumeration;
import java.util.Collections;


class SubjectTest
{
    private static class MyGroup implements Group
    {
        private HashSet<Principal> _members;
        private String _name;
        
        MyGroup( String name )
        {
            _name = name;
            _members = new HashSet<Principal>();
        }
        
        public boolean	addMember(Principal user)
        {
            if( _members.contains(user) )
            {
                return false;
            }
            _members.add( user );
            return true;
        }

        public boolean	isMember(Principal member)
        {
            return _members.contains(member);
        }

        public Enumeration<Principal>	members()
        {
            return Collections.enumeration( _members );
        }

        public boolean	removeMember(Principal user)
        {
            if( !_members.contains(user) )
            {
                return false;
            }
            _members.remove( user );
            return true;
        }
        
        public String	getName()
        {
            return _name;
        }
    }
    
    private void test()
    {
        Subject sub = new Subject();
        Set<Principal> prmg =  sub.getPrincipals();
        //Set prl =  sub.getPrincipals(MyGroup.class);
        MyGroup gr = new MyGroup("Roles");
        if( gr instanceof Group )
        {
            System.out.println("is Group");
        }
        prmg.add( gr );
        Set<Group> prl =  sub.getPrincipals(Group.class);
        System.out.println( prl.size() );
        System.out.println( prl.toString() );
    }
    
    public static void main(String[] args)
    {
        SubjectTest st = new SubjectTest();
        st.test();
    }
}
@@ -1292,24 +1292,300 @@
      %7D%0A    %7D
+%0A%0A    private static class MyPrincipal implements Principal%0A    %7B%0A        private String _name;%0A        %0A        MyPrincipal(String name)%0A        %7B%0A            _name = name;%0A        %7D%0A        %0A        public String getName()%0A        %7B%0A            return _name;%0A        %7D%0A    %7D
 %0A    %0A    pr
@@ -1627,16 +1627,20 @@
 ject sub
+ject
  = new S
@@ -1676,61 +1676,38 @@
 al%3E 
-prmg =  sub.getPrincipals();%0A        //Set prl
+rawListOfPrincipals
  =  sub
+ject
 .get
@@ -1721,21 +1721,8 @@
 als(
-MyGroup.class
 );%0A 
@@ -1738,16 +1738,19 @@
 Group gr
+oup
  = new M
@@ -1780,16 +1780,19 @@
   if( gr
+oup
  instanc
@@ -1879,53 +1879,195 @@
     
-prmg.add( gr );%0A        Set%3CGroup%3E prl
+rawListOfPrincipals.add( group );%0A        MyPrincipal id = new MyPrincipal(%22itsMe%22);%0A        rawListOfPrincipals.add( id );%0A        Set%3CGroup%3E principalListFilteredByGroupClass
  =  sub
+ject
 .get
@@ -2125,51 +2125,533 @@
 ( pr
-l.size() );%0A        System.out.println( prl
+incipalListFilteredByGroupClass.size() + %22,%22 +  principalListFilteredByGroupClass.toString() );%0A        Set%3CMyPrincipal%3E principalListFilteredByMyPrincipalClass =  subject.getPrincipals(MyPrincipal.class);%0A        System.out.println( principalListFilteredByMyPrincipalClass.size() + %22,%22 +  principalListFilteredByMyPrincipalClass.toString() );%0A        Set%3CPrincipal%3E readRawListOfPrincipalsAgain =  subject.getPrincipals();%0A        System.out.println( readRawListOfPrincipalsAgain.size() + %22,%22 +  readRawListOfPrincipalsAgain
 .toS

extend test, better variable name