code: public Collection<Group> findGroupByMembership(String userName, String membershipType) throws Exception
     {
        List<Group> groups = new ArrayList<Group>();
  
        Session session = service.getStorageSession();
        try
        {
           Node userNode;
           try
           {
              userNode = utils.getUserNode(session, userName);
           }
           catch (PathNotFoundException e)
           {
              return new ArrayList<Group>();
           }
  
           PropertyIterator refUserProps = userNode.getReferences();
           while (refUserProps.hasNext())
           {
              Node refUserNode = refUserProps.nextProperty().getParent();
              if (membershipType == null
                 || refUserNode.hasNode(membershipType.equals(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE)
                    ? JCROrganizationServiceImpl.JOS_MEMBERSHIP_TYPE_ANY : membershipType))
              {
                 Node groupNode = refUserNode.getParent().getParent();
                 groups.add(readGroup(groupNode));
              }
           }
        }
        finally
        {
           session.logout();
        }
  
        return groups;
     }
docs: {@inheritDoc}