Search in sources :

Example 1 with LdapConnectionAttempt

use of org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt in project admin-console-beta by connexta.

the class LdapTestConnection method performFunction.

// Possible message types: CANNOT_CONFIGURE, CANNOT_CONNECT
@Override
public BooleanField performFunction() {
    LdapConnectionAttempt connectionAttempt = utils.getLdapConnection(connection);
    addResultMessages(connectionAttempt.messages());
    return new BooleanField(connectionAttempt.connection().isPresent());
}
Also used : BooleanField(org.codice.ddf.admin.common.fields.base.scalar.BooleanField) LdapConnectionAttempt(org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt)

Example 2 with LdapConnectionAttempt

use of org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt in project admin-console-beta by connexta.

the class LdapTestDirectorySettings 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(settings.baseGroupDnField(), ldapConnection));
        addErrorMessages(utils.checkDirExists(settings.baseUserDnField(), ldapConnection));
        // Short-circuit return here, if either the user or group directory does not exist
        if (containsErrorMsgs()) {
            return new BooleanField(false);
        }
        checkUsersInDir(ldapConnection);
        // Short-circuit return here, if there are no users in base dir
        if (containsErrorMsgs()) {
            return new BooleanField(false);
        }
        if (settings.useCaseField().isAttributeStore()) {
            // Check if group objectClass is on at least one entry in the directory
            checkGroupObjectClass(ldapConnection);
            // Don't check the group if there is no entry with the correct objectClass
            if (containsErrorMsgs()) {
                return new BooleanField(false);
            }
            // Then, check that there is a group entry (of the correct objectClass) that has
            // any member references
            checkGroup(ldapConnection);
        }
    } catch (IOException e) {
        LOGGER.warn("Error closing LDAP connection", e);
    }
    return new BooleanField(!containsErrorMsgs());
}
Also used : BooleanField(org.codice.ddf.admin.common.fields.base.scalar.BooleanField) Connection(org.forgerock.opendj.ldap.Connection) IOException(java.io.IOException) LdapConnectionAttempt(org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt)

Example 3 with LdapConnectionAttempt

use of org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt in project admin-console-beta by connexta.

the class LdapUserAttributes method performFunction.

@Override
public StringField.ListImpl performFunction() {
    StringField.ListImpl entries = null;
    try (LdapConnectionAttempt connectionAttempt = utils.bindUserToLdapConnection(conn, bindInfo)) {
        addErrorMessages(connectionAttempt);
        if (containsErrorMsgs()) {
            return null;
        }
        ServerGuesser serverGuesser = ServerGuesser.buildGuesser(connectionAttempt.getResult());
        Set<String> ldapEntryAttributes = serverGuesser.getClaimAttributeOptions(baseUserDn.getValue());
        entries = new StringField.ListImpl();
        entries.setValue(Arrays.asList(ldapEntryAttributes.toArray()));
    } catch (IOException e) {
        LOGGER.warn("Error closing LDAP connection", e);
    }
    return entries;
}
Also used : StringField(org.codice.ddf.admin.common.fields.base.scalar.StringField) IOException(java.io.IOException) LdapConnectionAttempt(org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt) ServerGuesser(org.codice.ddf.admin.ldap.commons.ServerGuesser)

Example 4 with LdapConnectionAttempt

use of org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt in project admin-console-beta by connexta.

the class LdapTestBind method performFunction.

// Possible message types: CANNOT_CONFIGURE, CANNOT_CONNECT, CANNOT_BIND
@Override
public BooleanField performFunction() {
    LdapConnectionAttempt connectionAttempt = utils.bindUserToLdapConnection(conn, creds);
    addResultMessages(connectionAttempt.messages());
    return new BooleanField(connectionAttempt.connection().isPresent());
}
Also used : BooleanField(org.codice.ddf.admin.common.fields.base.scalar.BooleanField) LdapConnectionAttempt(org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt)

Example 5 with LdapConnectionAttempt

use of org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt in project admin-console-beta by connexta.

the class LdapTestSettings method performFunction.

@Override
public BooleanField performFunction() {
    LdapConnectionAttempt connectionAttempt = utils.bindUserToLdapConnection(conn, bindInfo);
    addResultMessages(connectionAttempt.messages());
    if (!connectionAttempt.connection().isPresent()) {
        return new BooleanField(false);
    }
    Connection ldapConnection = connectionAttempt.connection().get();
    if (!checkDirExists(settings.baseUserDn(), ldapConnection)) {
        addArgumentMessage(BASE_USER_DN_NOT_FOUND.setPath(settings.path()));
    } else {
        addArgumentMessages(checkUsersInDir(settings, ldapConnection));
    }
    if (!checkDirExists(settings.baseGroupDn(), ldapConnection)) {
        addArgumentMessage(BASE_GROUP_DN_NOT_FOUND.setPath(settings.path()));
    } else {
        // First check the group objectClass is on at least one entry in the directory
        addArgumentMessages(checkGroupObjectClass(settings, ldapConnection));
        // Then, check that there is a group entry (of the correct objectClass) that has
        // any member references
        addArgumentMessages(checkGroup(settings, ldapConnection));
    }
    return new BooleanField(!containsErrorMsgs());
}
Also used : BooleanField(org.codice.ddf.admin.common.fields.base.scalar.BooleanField) Connection(org.forgerock.opendj.ldap.Connection) LdapConnectionAttempt(org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt)

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