use of org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException in project archiva by apache.
the class DefaultSecurityConfigurationService method updateConfigurationProperty.
@Override
public Response updateConfigurationProperty(String propertyName, PropertyEntry propertyValue) throws ArchivaRestServiceException {
if (propertyValue == null) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.MISSING_DATA), 400);
}
try {
RedbackRuntimeConfiguration conf = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();
if (conf.getConfigurationProperties().containsKey(propertyName)) {
conf.getConfigurationProperties().put(propertyName, propertyValue.getValue());
redbackRuntimeConfigurationAdmin.updateRedbackRuntimeConfiguration(conf);
return Response.ok().build();
} else {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.PROPERTY_NOT_FOUND), 404);
}
} catch (RepositoryAdminException e) {
throw new ArchivaRestServiceException(ErrorMessage.of(REPOSITORY_ADMIN_ERROR, e.getMessage()));
}
}
use of org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException in project archiva by apache.
the class DefaultSecurityConfigurationService method updateConfiguration.
@Override
public SecurityConfiguration updateConfiguration(SecurityConfiguration newConfiguration) throws ArchivaRestServiceException {
if (newConfiguration == null) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.MISSING_DATA), 400);
}
try {
RedbackRuntimeConfiguration conf = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();
boolean userManagerChanged = !CollectionUtils.isEqualCollection(newConfiguration.getActiveUserManagers(), conf.getUserManagerImpls());
boolean rbacManagerChanged = !CollectionUtils.isEqualCollection(newConfiguration.getActiveRbacManagers(), conf.getRbacManagerImpls());
boolean ldapConfigured = newConfiguration.getActiveUserManagers().stream().anyMatch(um -> um.contains("ldap"));
if (!ldapConfigured) {
ldapConfigured = newConfiguration.getActiveRbacManagers().stream().anyMatch(um -> um.contains("ldap"));
}
updateConfig(newConfiguration, conf);
redbackRuntimeConfigurationAdmin.updateRedbackRuntimeConfiguration(conf);
if (userManagerChanged) {
log.info("user managerImpls changed to {} so reload it", newConfiguration.getActiveUserManagers());
userManager.initialize();
}
if (rbacManagerChanged) {
log.info("rbac manager changed to {} so reload it", newConfiguration.getActiveRbacManagers());
rbacManager.initialize();
roleManager.initialize();
}
if (ldapConfigured) {
try {
ldapConnectionFactory.initialize();
} catch (Exception e) {
log.error("Could not initialize LDAP connection factory: {}", e.getMessage());
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.LDAP_CF_INIT_FAILED, e.getMessage()));
}
}
Collection<PasswordRule> passwordRules = applicationContext.getBeansOfType(PasswordRule.class).values();
for (PasswordRule passwordRule : passwordRules) {
passwordRule.initialize();
}
Collection<CookieSettings> cookieSettingsList = applicationContext.getBeansOfType(CookieSettings.class).values();
for (CookieSettings cookieSettings : cookieSettingsList) {
cookieSettings.initialize();
}
Collection<Authenticator> authenticators = applicationContext.getBeansOfType(Authenticator.class).values();
for (Authenticator authenticator : authenticators) {
try {
log.debug("Initializing authenticatior " + authenticator.getId());
authenticator.initialize();
} catch (Exception e) {
log.error("Initialization of authenticator failed " + authenticator.getId(), e);
}
}
if (ldapConfigured) {
try {
ldapUserMapper.initialize();
} catch (Exception e) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.LDAP_USER_MAPPER_INIT_FAILED, e.getMessage()));
}
}
} catch (RepositoryAdminException e) {
throw new ArchivaRestServiceException(ErrorMessage.of(REPOSITORY_ADMIN_ERROR, e.getMessage()));
}
try {
return SecurityConfiguration.ofRedbackConfiguration(redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration());
} catch (RepositoryAdminException e) {
log.error("Error while retrieve updated configuration: {}", e.getMessage());
throw new ArchivaRestServiceException(ErrorMessage.of(REPOSITORY_ADMIN_ERROR, e.getMessage()));
}
}
use of org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException 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.svc.ArchivaRestServiceException in project archiva by apache.
the class DefaultSecurityConfigurationService method getCacheConfiguration.
@Override
public CacheConfiguration getCacheConfiguration() throws ArchivaRestServiceException {
try {
RedbackRuntimeConfiguration redbackRuntimeConfiguration = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();
log.debug("getRedbackRuntimeConfiguration -> {}", redbackRuntimeConfiguration);
return CacheConfiguration.of(redbackRuntimeConfiguration.getUsersCacheConfiguration());
} catch (RepositoryAdminException e) {
throw new ArchivaRestServiceException(ErrorMessage.of(REPOSITORY_ADMIN_ERROR));
}
}
use of org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException in project archiva by apache.
the class DefaultSecurityConfigurationService method handleLdapException.
private void handleLdapException(LdapException e) throws ArchivaRestServiceException {
Throwable rootCause = e.getRootCause();
if (rootCause instanceof CommunicationException) {
log.warn("LDAP connection check failed with CommunicationException: {}", e.getMessage(), e);
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.LDAP_COMMUNICATION_ERROR, e.getMessage()), 400);
} else if (rootCause instanceof ServiceUnavailableException) {
log.warn("LDAP connection check failed with ServiceUnavailableException: {}", e.getMessage(), e);
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.LDAP_SERVICE_UNAVAILABLE, e.getMessage()), 400);
} else if (rootCause instanceof AuthenticationException) {
log.warn("LDAP connection check failed with AuthenticationException: {}", e.getMessage(), e);
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.LDAP_SERVICE_AUTHENTICATION_FAILED, e.getMessage()), 400);
} else if (rootCause instanceof AuthenticationNotSupportedException) {
log.warn("LDAP connection check failed with AuthenticationNotSupportedException: {}", e.getMessage(), e);
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.LDAP_SERVICE_AUTHENTICATION_NOT_SUPPORTED, e.getMessage()), 400);
} else if (rootCause instanceof NoPermissionException) {
log.warn("LDAP connection check failed with NoPermissionException: {}", e.getMessage(), e);
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.LDAP_SERVICE_NO_PERMISSION, e.getMessage()), 400);
}
log.warn("LDAP connection check failed: {} - {}", e.getClass().getName(), e.getMessage(), e);
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.LDAP_GENERIC_ERROR, e.getMessage()), 400);
}
Aggregations