title: How do I find all the roles a user has in LDAP using the UnboundID LDAP SDK?
body: <p>I am having trouble finding the roles a user belongs to, I've tried the following code and it gives a lot of attributes, but what I am interested in is what roles the user belongs to in a certain app.</p>
  
  <p>The user I am searching for belongs to the following two groups (userrole and adminrole). How do I retreive this information?</p>
  
  <p>DN: cn=userrole,ou=roles,ou=appname,ou=apps,ou=groups,dc=example,dc=no </p>
  
  <p>DN: cn=adminrole,ou=roles,ou=appname,ou=apps,ou=groups,dc=example,dc=no</p>
  
  <pre><code>private final String host = "host.example.com";
  private final int port = 389;
  private final String bindDn = "uid=appname,ou=systems,dc=example,dc=no";
  private final String password = "password";
  private final String searchDn = "dc=example,dc=no";
  
  public SearchResultEntry getUserDetails(String username) {
      try {
          final LDAPConnection connection = new LDAPConnection(host, port,
                  bindDn, password);
          SearchResult searchResults;
          searchResults = connection.search(searchDn, SearchScope.SUB,
                  "(uid=" + username + ")", "+");
  
          if (searchResults.getEntryCount() == 1) {
              SearchResultEntry entry = searchResults.getSearchEntries().get(
                      0);
              connection.close();
              return entry;
          } else {
              LOGGER.error("NOT FOUND!");
              connection.close();
              return null;
          }
      } catch (LDAPException e) {
          LOGGER.error("Exception");
          return null;
      }
  }
  </code></pre>