use of org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt in project admin-console-beta by connexta.
the class LdapRecommendedSettings method performFunction.
@Override
public LdapRecommendedSettingsField performFunction() {
try (LdapConnectionAttempt connectionAttempt = utils.bindUserToLdapConnection(conn, creds)) {
addErrorMessages(connectionAttempt);
if (!connectionAttempt.isResultPresent()) {
return null;
}
ServerGuesser guesser = ServerGuesser.buildGuesser(ldapType.getValue(), connectionAttempt.getResult());
return new LdapRecommendedSettingsField().userDns(guesser.getUserBaseChoices()).groupDns(guesser.getGroupBaseChoices()).loginUserAttributes(guesser.getLoginUserAttribute()).groupObjectClasses(guesser.getGroupObjectClass()).groupAttributesHoldingMember(guesser.getGroupAttributeHoldingMember()).memberAttributesReferencedInGroup(guesser.getMemberAttributeReferencedInGroup()).queryBases(guesser.getBaseContexts());
} catch (IOException e) {
LOGGER.warn("Error closing LDAP connection", e);
return null;
}
}
use of org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt in project admin-console-beta by connexta.
the class LdapTestClaimMappings method performFunction.
@Override
public BooleanField performFunction() {
try (LdapConnectionAttempt connectionAttempt = utils.bindUserToLdapConnection(conn, bindInfo)) {
addErrorMessages(connectionAttempt);
if (containsErrorMsgs()) {
return new BooleanField(false);
}
Connection ldapConnection = connectionAttempt.getResult();
addErrorMessages(utils.checkDirExists(baseUserDn, ldapConnection));
// Short-circuit return here, if either the user or group directory does not exist
if (containsErrorMsgs()) {
return new BooleanField(false);
}
claimMappings.getList().stream().map(ClaimsMapEntry::claimValueField).filter(claim -> !mappingAttributeFound(ldapConnection, claim.getValue())).forEach(claim -> addErrorMessage(userAttributeNotFoundError(claim.getPath())));
} catch (IOException e) {
LOGGER.warn("Error closing LDAP connection", e);
}
return new BooleanField(!containsErrorMsgs());
}
use of org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt 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