code: public String[] getRoles(String username, char[] password) throws NamingException
  	{
  		String[] rolesArray = null;
  		DirContext ctx = null;
  		try
  		{
  		
  			String userDN = toDN(username);
  			ctx = initContext(userDN, password);
  			
  			SearchControls sc = new SearchControls();
  			String[] attributeFilter =
  			{ "cn", "mail", "memberOf" };
  			sc.setReturningAttributes(attributeFilter);
  			sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
  
  			String filter = "(&(sAMAccountName=" + username + "))";
  
  			NamingEnumeration<SearchResult> results = ctx.search("", filter, sc);
  
  			ArrayList<String> roles = new ArrayList<String>();
  			while (results.hasMore())
  			{
  				SearchResult sr = results.next();
  				Attributes attrs = sr.getAttributes();
  				//Attribute attr = attrs.get("cn");
  				//attr = attrs.get("mail");
  
  				Attribute attr2 = attrs.get("memberOf");
  				NamingEnumeration<?> ne = attr2.getAll();
  				while (ne.hasMore())
  				{
  					roles.add(ne.next().toString());
  					
  				}
  				rolesArray = new String[roles.size()];
  				roles.toArray(rolesArray);
  				
  				
  				
  			}
  		}
  		finally
  		{
  			try
  			{
  				if (ctx != null)
  					ctx.close();
  			}
  			catch (Exception ex)
  			{
  				Debugger.printError(ex);
  			}
  		}
  		return rolesArray;
  	}
docs: -----------------------------------------------