code: private List<LDAPGroup> getGroups(final DirContext ldap, final String dn) throws NamingException
  	{
  		// Get the DN of all grouos the user is directly/indirectly a member of
  		final NamingEnumeration<SearchResult> answer;
  		{
  			SearchControls search = new SearchControls();
  
  			search.setSearchScope(SearchControls.SUBTREE_SCOPE);
  			search.setReturningAttributes(new String[]{"dn"});
  
  			final String searchFilter = String.format(this.ldapGroupFilter, dn);
  
  			answer = ldap.search(ldapSearchBase, searchFilter, search);
  		}
  
  		List<LDAPGroup> groups = new ArrayList<>();
  
  		while (answer.hasMoreElements())
  		{
  			SearchResult sr = answer.next();
  
  			final String groupDN = sr.getNameInNamespace();
  
  			groups.add(dnToLdapGroup(groupDN));
  		}
  
  		return groups;
  	}
docs: Get the groups that a user is a member of (either directly or indirectly)
  
  @param ldap
  @param dn
  
  @return
  
  @throws NamingException