Search in sources :

Example 1 with AuthServiceBackendTestResult

use of org.graylog.security.authservice.test.AuthServiceBackendTestResult in project graylog2-server by Graylog2.

the class LDAPAuthServiceBackend method testConnection.

@Override
public AuthServiceBackendTestResult testConnection(@Nullable AuthServiceBackendDTO existingBackendConfig) {
    final LDAPAuthServiceBackendConfig testConfig = buildTestConfig(existingBackendConfig);
    final LDAPConnectorConfig config = testConfig.getLDAPConnectorConfig();
    if (config.serverList().size() == 1) {
        return testSingleConnection(config, config.serverList().get(0));
    }
    // Test each server separately, so we can see the result for each
    final List<AuthServiceBackendTestResult> testResults = config.serverList().stream().map(server -> testSingleConnection(config, server)).collect(Collectors.toList());
    if (testResults.stream().anyMatch(res -> !res.isSuccess())) {
        return AuthServiceBackendTestResult.createFailure("Test failure", testResults.stream().map(r -> {
            if (r.isSuccess()) {
                return r.message();
            } else {
                return r.message() + " : " + String.join(",", r.errors());
            }
        }).collect(Collectors.toList()));
    } else {
        return AuthServiceBackendTestResult.createSuccess("Successfully connected to " + config.serverList());
    }
}
Also used : LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) UnboundLDAPConnector(org.graylog.security.authservice.ldap.UnboundLDAPConnector) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) LDAPUser(org.graylog.security.authservice.ldap.LDAPUser) Assisted(com.google.inject.assistedinject.Assisted) Inject(javax.inject.Inject) AuthServiceBackendDTO(org.graylog.security.authservice.AuthServiceBackendDTO) AuthServiceBackendTestResult(org.graylog.security.authservice.test.AuthServiceBackendTestResult) GeneralSecurityException(java.security.GeneralSecurityException) ImmutableList(com.google.common.collect.ImmutableList) AuthenticationDetails(org.graylog.security.authservice.AuthenticationDetails) Map(java.util.Map) LDAPException(com.unboundid.ldap.sdk.LDAPException) Nullable(javax.annotation.Nullable) UserDetails(org.graylog.security.authservice.UserDetails) EncryptedValue(org.graylog2.security.encryption.EncryptedValue) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) AuthenticationServiceUnavailableException(org.graylog2.shared.security.AuthenticationServiceUnavailableException) Collectors(java.util.stream.Collectors) List(java.util.List) AuthServiceCredentials(org.graylog.security.authservice.AuthServiceCredentials) UnboundLDAPConfig(org.graylog.security.authservice.ldap.UnboundLDAPConfig) AuthServiceBackend(org.graylog.security.authservice.AuthServiceBackend) ProvisionerService(org.graylog.security.authservice.ProvisionerService) LDAPConnectorConfig(org.graylog.security.authservice.ldap.LDAPConnectorConfig) Optional(java.util.Optional) Collections(java.util.Collections) AuthServiceBackendTestResult(org.graylog.security.authservice.test.AuthServiceBackendTestResult) LDAPConnectorConfig(org.graylog.security.authservice.ldap.LDAPConnectorConfig)

Example 2 with AuthServiceBackendTestResult

use of org.graylog.security.authservice.test.AuthServiceBackendTestResult in project graylog2-server by Graylog2.

the class ADAuthServiceBackend method testConnection.

@Override
public AuthServiceBackendTestResult testConnection(@Nullable AuthServiceBackendDTO existingBackendConfig) {
    final ADAuthServiceBackendConfig testConfig = buildTestConfig(existingBackendConfig);
    final LDAPConnectorConfig config = testConfig.getLDAPConnectorConfig();
    if (config.serverList().size() == 1) {
        return testSingleConnection(config, config.serverList().get(0));
    }
    // Test each server separately, so we can see the result for each
    final List<AuthServiceBackendTestResult> testResults = config.serverList().stream().map(server -> testSingleConnection(config, server)).collect(Collectors.toList());
    if (testResults.stream().anyMatch(res -> !res.isSuccess())) {
        return AuthServiceBackendTestResult.createFailure("Test failure", testResults.stream().map(r -> {
            if (r.isSuccess()) {
                return r.message();
            } else {
                return r.message() + " : " + String.join(",", r.errors());
            }
        }).collect(Collectors.toList()));
    } else {
        return AuthServiceBackendTestResult.createSuccess("Successfully connected to " + config.serverList());
    }
}
Also used : LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) UnboundLDAPConnector(org.graylog.security.authservice.ldap.UnboundLDAPConnector) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) LDAPUser(org.graylog.security.authservice.ldap.LDAPUser) Assisted(com.google.inject.assistedinject.Assisted) Inject(javax.inject.Inject) AuthServiceBackendDTO(org.graylog.security.authservice.AuthServiceBackendDTO) AuthServiceBackendTestResult(org.graylog.security.authservice.test.AuthServiceBackendTestResult) GeneralSecurityException(java.security.GeneralSecurityException) ImmutableList(com.google.common.collect.ImmutableList) AuthenticationDetails(org.graylog.security.authservice.AuthenticationDetails) Map(java.util.Map) LDAPException(com.unboundid.ldap.sdk.LDAPException) Nullable(javax.annotation.Nullable) UserDetails(org.graylog.security.authservice.UserDetails) EncryptedValue(org.graylog2.security.encryption.EncryptedValue) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) AuthenticationServiceUnavailableException(org.graylog2.shared.security.AuthenticationServiceUnavailableException) Collectors(java.util.stream.Collectors) List(java.util.List) AuthServiceCredentials(org.graylog.security.authservice.AuthServiceCredentials) UnboundLDAPConfig(org.graylog.security.authservice.ldap.UnboundLDAPConfig) AuthServiceBackend(org.graylog.security.authservice.AuthServiceBackend) ProvisionerService(org.graylog.security.authservice.ProvisionerService) LDAPConnectorConfig(org.graylog.security.authservice.ldap.LDAPConnectorConfig) Optional(java.util.Optional) Filter(com.unboundid.ldap.sdk.Filter) Collections(java.util.Collections) AuthServiceBackendTestResult(org.graylog.security.authservice.test.AuthServiceBackendTestResult) LDAPConnectorConfig(org.graylog.security.authservice.ldap.LDAPConnectorConfig)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Assisted (com.google.inject.assistedinject.Assisted)2 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)2 LDAPException (com.unboundid.ldap.sdk.LDAPException)2 GeneralSecurityException (java.security.GeneralSecurityException)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Nullable (javax.annotation.Nullable)2 Inject (javax.inject.Inject)2 AuthServiceBackend (org.graylog.security.authservice.AuthServiceBackend)2 AuthServiceBackendDTO (org.graylog.security.authservice.AuthServiceBackendDTO)2 AuthServiceCredentials (org.graylog.security.authservice.AuthServiceCredentials)2 AuthenticationDetails (org.graylog.security.authservice.AuthenticationDetails)2 ProvisionerService (org.graylog.security.authservice.ProvisionerService)2 UserDetails (org.graylog.security.authservice.UserDetails)2