我无法找到用户所属的角色,我尝试了以下代码,它提供了很多属性,但我感兴趣的是用户在某个应用程序中属于什么角色。
我正在搜索的用户属于以下两个组(userrole 和 adminrole)。我如何检索这些信息?
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;
}
}