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();
}
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));
}
}
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);
}
}
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()));
}
}
Aggregations