use of org.forgerock.opendj.ldap.ByteString in project admin-console-beta by connexta.
the class LdapTestDirectorySettings method checkReferencedUser.
boolean checkReferencedUser(Connection ldapConnection, SearchResultEntry group) {
boolean hasReferencedMember = false;
for (ByteString memberRef : group.getAttribute(settings.groupAttributeHoldingMember()).toArray()) {
// This memberRef will be in the format:
// memberAttributeReferencedInGroup + username + baseUserDN
// Strip the baseUserDN and query for the remainder as a Filter
// beneath the baseUserDN
List<String> split = Arrays.asList(memberRef.toString().split(","));
String userFilter = split.get(0);
String checkUserBase = String.join(",", split.subList(1, split.size()));
// found in a matched group
if (checkUserBase.toUpperCase().endsWith(settings.baseUserDn().toUpperCase()) && userFilter.split("=")[0].equalsIgnoreCase(settings.memberAttributeReferencedInGroup())) {
List<SearchResultEntry> foundMember = utils.getLdapQueryResults(ldapConnection, settings.baseUserDn(), userFilter, SearchScope.WHOLE_SUBTREE, 1);
if (!foundMember.isEmpty()) {
hasReferencedMember = true;
break;
}
}
}
return hasReferencedMember;
}
use of org.forgerock.opendj.ldap.ByteString in project admin-console-beta by connexta.
the class LdapQuery method performFunction.
@Override
public MapField.ListImpl performFunction() {
List<SearchResultEntry> searchResults;
List<MapField> convertedSearchResults = new ArrayList<>();
try (LdapConnectionAttempt connectionAttempt = utils.bindUserToLdapConnection(conn, creds)) {
addErrorMessages(connectionAttempt);
if (containsErrorMsgs()) {
return null;
}
searchResults = utils.getLdapQueryResults(connectionAttempt.getResult(), queryBase.getValue(), query.getValue(), SearchScope.WHOLE_SUBTREE, maxQueryResults.getValue() == null ? DEFAULT_MAX_QUERY_RESULTS : maxQueryResults.getValue());
for (SearchResultEntry entry : searchResults) {
MapField entryMap = new MapField();
for (Attribute attri : entry.getAllAttributes()) {
entryMap.put("name", entry.getName().toString());
if (!attri.getAttributeDescriptionAsString().toLowerCase().contains("password")) {
List<String> attributeValueList = attri.parallelStream().map(ByteString::toString).collect(Collectors.toList());
String attributeValue = attributeValueList.size() == 1 ? attributeValueList.get(0) : attributeValueList.toString();
entryMap.put(attri.getAttributeDescriptionAsString(), attributeValue);
}
}
convertedSearchResults.add(entryMap);
}
} catch (IOException e) {
LOGGER.warn("Error closing LDAP connection", e);
}
return new MapField.ListImpl().addAll(convertedSearchResults);
}
Aggregations