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.
The user I am searching for belongs to the following two groups (userrole and adminrole). How do I retreive this information?
DN: cn=userrole,ou=roles,ou=appname,ou=apps,ou=groups,dc=example,dc=no
DN: cn=adminrole,ou=roles,ou=appname,ou=apps,ou=groups,dc=example,dc=no
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;
}
}