class SubjectUtil {

    public static List<String> getGroupnamesFromSubject(Subject subject) {

        List<String> groupList = new ArrayList<String>();

        Set<Group> princSet = null;

        if (subject != null) {

            princSet = subject.getPrincipals(Group.class);
            for (PrincipalImpl g : princSet) {
                String gName = g.getName();
                groupList.add(gName);
            }
        }

        return groupList;
    }

}