Search in sources :

Example 1 with LdapConfiguration

use of org.apache.archiva.rest.api.v2.model.LdapConfiguration in project archiva by apache.

the class DefaultSecurityConfigurationService method verifyLdapConfiguration.

@Override
public Response verifyLdapConfiguration(LdapConfiguration ldapConfiguration) throws ArchivaRestServiceException {
    LdapConnection ldapConnection = null;
    try {
        LdapConnectionConfiguration ldapConnectionConfiguration = new LdapConnectionConfiguration(ldapConfiguration.getHostName(), ldapConfiguration.getPort(), ldapConfiguration.getBaseDn(), ldapConfiguration.getContextFactory(), ldapConfiguration.getBindDn(), ldapConfiguration.getBindPassword(), ldapConfiguration.getAuthenticationMethod(), toProperties(ldapConfiguration.getProperties()));
        ldapConnectionConfiguration.setSsl(ldapConfiguration.isSslEnabled());
        ldapConnection = ldapConnectionFactory.getConnection(ldapConnectionConfiguration);
    } catch (InvalidNameException e) {
        log.warn("LDAP connection check failed with invalid name : {}", e.getMessage(), e);
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.LDAP_INVALID_NAME, e.getMessage()), 400);
    } catch (LdapException e) {
        handleLdapException(e);
    } finally {
        if (ldapConnection != null) {
            try {
                ldapConnection.close();
            } catch (NamingException e) {
                log.error("Could not close connection: {}", e.getMessage());
            }
        }
        ldapConnection = null;
    }
    try {
        // verify groups dn value too
        LdapConnectionConfiguration ldapConnectionConfiguration = new LdapConnectionConfiguration(ldapConfiguration.getHostName(), ldapConfiguration.getPort(), ldapConfiguration.getGroupsBaseDn(), ldapConfiguration.getContextFactory(), ldapConfiguration.getBindDn(), ldapConfiguration.getBindPassword(), ldapConfiguration.getAuthenticationMethod(), toProperties(ldapConfiguration.getProperties()));
        ldapConnectionConfiguration.setSsl(ldapConfiguration.isSslEnabled());
        ldapConnection = ldapConnectionFactory.getConnection(ldapConnectionConfiguration);
    } catch (InvalidNameException e) {
        log.warn("LDAP connection check failed with invalid name : {}", e.getMessage(), e);
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.LDAP_INVALID_NAME, e.getMessage()), 400);
    } catch (LdapException e) {
        handleLdapException(e);
    } finally {
        if (ldapConnection != null) {
            try {
                ldapConnection.close();
            } catch (NamingException e) {
                log.error("Could not close connection: {}", e.getMessage(), e);
            }
        }
    }
    return Response.ok().build();
}
Also used : InvalidNameException(javax.naming.InvalidNameException) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) NamingException(javax.naming.NamingException) LdapConnectionConfiguration(org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration) LdapException(org.apache.archiva.redback.common.ldap.connection.LdapException) LdapConnection(org.apache.archiva.redback.common.ldap.connection.LdapConnection)

Example 2 with LdapConfiguration

use of org.apache.archiva.rest.api.v2.model.LdapConfiguration in project archiva by apache.

the class DefaultSecurityConfigurationService method getLdapConfiguration.

@Override
public LdapConfiguration getLdapConfiguration() throws ArchivaRestServiceException {
    try {
        RedbackRuntimeConfiguration redbackRuntimeConfiguration = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();
        log.debug("getRedbackRuntimeConfiguration -> {}", redbackRuntimeConfiguration);
        LdapConfiguration ldapConfig = LdapConfiguration.of(redbackRuntimeConfiguration.getLdapConfiguration());
        ldapConfig.setAvailableContextFactories(availableContextProviders);
        return ldapConfig;
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(ErrorMessage.of(REPOSITORY_ADMIN_ERROR));
    }
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) LdapConfiguration(org.apache.archiva.rest.api.v2.model.LdapConfiguration) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 3 with LdapConfiguration

use of org.apache.archiva.rest.api.v2.model.LdapConfiguration in project archiva by apache.

the class NativeSecurityConfigurationServiceTest method testUpdateLdapConfiguration.

@Test
void testUpdateLdapConfiguration() {
    String token = getAdminToken();
    try {
        Map<String, Object> jsonMap = new HashMap<>();
        jsonMap.put("host_name", "localhost");
        jsonMap.put("port", 389);
        jsonMap.put("ssl_enabled", false);
        jsonMap.put("writable", true);
        jsonMap.put("base_dn", "dc=apache,dc=org");
        Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().body(jsonMap).put("config/ldap").then().statusCode(200).extract().response();
        assertNotNull(response);
        response = given().spec(getRequestSpec(token)).contentType(JSON).when().get("config/ldap").then().statusCode(200).extract().response();
        assertNotNull(response);
        LdapConfiguration config = response.getBody().jsonPath().getObject("", LdapConfiguration.class);
        assertEquals("localhost", config.getHostName());
        assertEquals(389, config.getPort());
        assertFalse(config.isSslEnabled());
        assertTrue(config.isWritable());
        assertEquals("dc=apache,dc=org", config.getBaseDn());
    } finally {
        Map<String, Object> jsonMap = new HashMap<>();
        jsonMap.put("host_name", "");
        jsonMap.put("port", -1);
        jsonMap.put("ssl_enabled", false);
        jsonMap.put("base_dn", "");
        jsonMap.put("writable", false);
        given().spec(getRequestSpec(token)).contentType(JSON).when().body(jsonMap).put("config/ldap").then().statusCode(200);
    }
}
Also used : Response(io.restassured.response.Response) HashMap(java.util.HashMap) LdapConfiguration(org.apache.archiva.rest.api.v2.model.LdapConfiguration) Test(org.junit.jupiter.api.Test)

Example 4 with LdapConfiguration

use of org.apache.archiva.rest.api.v2.model.LdapConfiguration in project archiva by apache.

the class DefaultSecurityConfigurationService method updateLdapConfiguration.

@Override
public LdapConfiguration updateLdapConfiguration(LdapConfiguration configuration) throws ArchivaRestServiceException {
    try {
        RedbackRuntimeConfiguration redbackRuntimeConfiguration = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();
        log.debug("getRedbackRuntimeConfiguration -> {}", redbackRuntimeConfiguration);
        updateConfig(configuration, redbackRuntimeConfiguration);
        redbackRuntimeConfigurationAdmin.updateRedbackRuntimeConfiguration(redbackRuntimeConfiguration);
        ldapConnectionFactory.initialize();
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(ErrorMessage.of(REPOSITORY_ADMIN_ERROR));
    }
    try {
        return LdapConfiguration.of(redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration().getLdapConfiguration());
    } catch (RepositoryAdminException e) {
        log.error("Error while retrieve updated configuration: {}", e.getMessage());
        throw new ArchivaRestServiceException(ErrorMessage.of(REPOSITORY_ADMIN_ERROR, e.getMessage()));
    }
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Aggregations

ArchivaRestServiceException (org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException)3 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)2 RedbackRuntimeConfiguration (org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration)2 LdapConfiguration (org.apache.archiva.rest.api.v2.model.LdapConfiguration)2 Response (io.restassured.response.Response)1 HashMap (java.util.HashMap)1 InvalidNameException (javax.naming.InvalidNameException)1 NamingException (javax.naming.NamingException)1 LdapConnection (org.apache.archiva.redback.common.ldap.connection.LdapConnection)1 LdapConnectionConfiguration (org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration)1 LdapException (org.apache.archiva.redback.common.ldap.connection.LdapException)1 Test (org.junit.jupiter.api.Test)1