Search in sources :

Example 6 with LdapConnectionAttempt

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;
    }
}
Also used : LdapRecommendedSettingsField(org.codice.ddf.admin.ldap.fields.query.LdapRecommendedSettingsField) IOException(java.io.IOException) LdapConnectionAttempt(org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt) ServerGuesser(org.codice.ddf.admin.ldap.commons.ServerGuesser)

Example 7 with LdapConnectionAttempt

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());
}
Also used : Connection(org.forgerock.opendj.ldap.Connection) LdapBindUserInfo(org.codice.ddf.admin.ldap.fields.connection.LdapBindUserInfo) Filter(org.forgerock.opendj.ldap.Filter) LoggerFactory(org.slf4j.LoggerFactory) SearchScope(org.forgerock.opendj.ldap.SearchScope) TestFunctionField(org.codice.ddf.admin.common.fields.base.function.TestFunctionField) LdapConnectionAttempt(org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt) ImmutableList(com.google.common.collect.ImmutableList) BooleanField(org.codice.ddf.admin.common.fields.base.scalar.BooleanField) LdapDistinguishedName(org.codice.ddf.admin.ldap.fields.LdapDistinguishedName) LdapTestingUtils(org.codice.ddf.admin.ldap.commons.LdapTestingUtils) FunctionField(org.codice.ddf.admin.api.fields.FunctionField) LdapConnectionField(org.codice.ddf.admin.ldap.fields.connection.LdapConnectionField) Field(org.codice.ddf.admin.api.Field) ImmutableSet(com.google.common.collect.ImmutableSet) ClaimsMapEntry(org.codice.ddf.admin.security.common.fields.wcpm.ClaimsMapEntry) Logger(org.slf4j.Logger) LdapAttributeName(org.codice.ddf.admin.ldap.fields.LdapAttributeName) Set(java.util.Set) StringField(org.codice.ddf.admin.common.fields.base.scalar.StringField) StsServiceProperties(org.codice.ddf.admin.security.common.services.StsServiceProperties) IOException(java.io.IOException) ConfiguratorSuite(org.codice.ddf.internal.admin.configurator.actions.ConfiguratorSuite) LdapMessages(org.codice.ddf.admin.ldap.commons.LdapMessages) Collectors(java.util.stream.Collectors) SecurityMessages(org.codice.ddf.admin.security.common.SecurityMessages) List(java.util.List) LdapMessages.userAttributeNotFoundError(org.codice.ddf.admin.ldap.commons.LdapMessages.userAttributeNotFoundError) DefaultMessages(org.codice.ddf.admin.common.report.message.DefaultMessages) SecurityValidation(org.codice.ddf.admin.security.common.SecurityValidation) BooleanField(org.codice.ddf.admin.common.fields.base.scalar.BooleanField) ClaimsMapEntry(org.codice.ddf.admin.security.common.fields.wcpm.ClaimsMapEntry) Connection(org.forgerock.opendj.ldap.Connection) IOException(java.io.IOException) LdapConnectionAttempt(org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt)

Example 8 with LdapConnectionAttempt

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);
}
Also used : Attribute(org.forgerock.opendj.ldap.Attribute) ArrayList(java.util.ArrayList) ByteString(org.forgerock.opendj.ldap.ByteString) IOException(java.io.IOException) LdapConnectionAttempt(org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry) MapField(org.codice.ddf.admin.common.fields.common.MapField)

Aggregations

LdapConnectionAttempt (org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt)8 IOException (java.io.IOException)5 BooleanField (org.codice.ddf.admin.common.fields.base.scalar.BooleanField)5 Connection (org.forgerock.opendj.ldap.Connection)3 StringField (org.codice.ddf.admin.common.fields.base.scalar.StringField)2 ServerGuesser (org.codice.ddf.admin.ldap.commons.ServerGuesser)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Field (org.codice.ddf.admin.api.Field)1 FunctionField (org.codice.ddf.admin.api.fields.FunctionField)1 TestFunctionField (org.codice.ddf.admin.common.fields.base.function.TestFunctionField)1 MapField (org.codice.ddf.admin.common.fields.common.MapField)1 DefaultMessages (org.codice.ddf.admin.common.report.message.DefaultMessages)1 LdapMessages (org.codice.ddf.admin.ldap.commons.LdapMessages)1 LdapMessages.userAttributeNotFoundError (org.codice.ddf.admin.ldap.commons.LdapMessages.userAttributeNotFoundError)1 LdapTestingUtils (org.codice.ddf.admin.ldap.commons.LdapTestingUtils)1