public static Set<String> authorize(String username) {
        Set<String> groups = new HashSet();
        DirContext ctx = null;
        try {
            ctx = ldapContext();
            SearchControls ctrls = new SearchControls();
            ctrls.setSearchScope(SearchControls.SUBTREE_SCOPE);
            String filter = String.format(config.searchFilter, username);
            NamingEnumeration<SearchResult> results = ctx.search(config.searchBase, filter, ctrls);
            if(!results.hasMore()) {
                logger.error("Principal name '" + username + "' not found");
                return null;
            }
            SearchResult result = results.next();
            if(logger.isDebugEnabled()) logger.debug("distinguisedName: " + result.getNameInNamespace());

            Attribute memberOf = result.getAttributes().get("memberOf");
            if(memberOf!=null) {
                for(int idx=0; idx<memberOf.size(); idx++) {
                    groups.add(memberOf.get(idx).toString());
                }
            }
        } catch (Exception e) {
            logger.error("Failed to authorize user " + username, e);
            return null;
        } finally {
            try {
                if(ctx != null) ctx.close();
            } catch(Exception e) {}
        }
        return groups;
    }
@Test
    public void testAuthorization() throws Exception {
        String user = "jduke";
        String expectedGroups = "cn=just-users,ou=users,dc=undertow,dc=io,cn=best-users,ou=users,dc=undertow,dc=io";

        Assert.assertEquals(expectedGroups, String.join(",", LdapUtil.authorize(user)));
    }