use of org.apache.archiva.rest.api.v2.model.SecurityConfiguration 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.model.SecurityConfiguration in project archiva by apache.
the class DefaultSecurityConfigurationService method getConfiguration.
@Override
public SecurityConfiguration getConfiguration() throws ArchivaRestServiceException {
try {
RedbackRuntimeConfiguration redbackRuntimeConfiguration = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();
log.debug("getRedbackRuntimeConfiguration -> {}", redbackRuntimeConfiguration);
return SecurityConfiguration.ofRedbackConfiguration(redbackRuntimeConfiguration);
} catch (RepositoryAdminException e) {
throw new ArchivaRestServiceException(ErrorMessage.of(REPOSITORY_ADMIN_ERROR));
}
}
Aggregations