use of org.apache.archiva.rest.api.v2.svc.ErrorKeys.REPOSITORY_ADMIN_ERROR in project archiva by apache.
the class DefaultSecurityConfigurationService method getConfigurationProperties.
@Override
public PagedResult<PropertyEntry> getConfigurationProperties(String searchTerm, Integer offset, Integer limit, List<String> orderBy, String order) throws ArchivaRestServiceException {
try {
RedbackRuntimeConfiguration redbackRuntimeConfiguration = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();
log.debug("getRedbackRuntimeConfiguration -> {}", redbackRuntimeConfiguration);
boolean ascending = PROP_QUERY_HELPER.isAscending(order);
Predicate<PropertyEntry> filter = PROP_QUERY_HELPER.getQueryFilter(searchTerm);
Comparator<PropertyEntry> comparator = PROP_QUERY_HELPER.getComparator(orderBy, ascending);
Map<String, String> props = redbackRuntimeConfiguration.getConfigurationProperties();
int totalCount = Math.toIntExact(props.entrySet().stream().map(entry -> new PropertyEntry(entry.getKey(), entry.getValue())).filter(filter).count());
List<PropertyEntry> result = props.entrySet().stream().map(entry -> new PropertyEntry(entry.getKey(), entry.getValue())).filter(filter).sorted(comparator).skip(offset).limit(limit).collect(Collectors.toList());
return new PagedResult<>(totalCount, offset, limit, result);
} catch (ArithmeticException e) {
log.error("The total count of the result properties is higher than max integer value!");
throw new ArchivaRestServiceException(ErrorMessage.of(INVALID_RESULT_SET_ERROR));
} catch (RepositoryAdminException e) {
throw new ArchivaRestServiceException(ErrorMessage.of(REPOSITORY_ADMIN_ERROR));
}
}
use of org.apache.archiva.rest.api.v2.svc.ErrorKeys.REPOSITORY_ADMIN_ERROR 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.ErrorKeys.REPOSITORY_ADMIN_ERROR 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.ErrorKeys.REPOSITORY_ADMIN_ERROR 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.ErrorKeys.REPOSITORY_ADMIN_ERROR 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));
}
}
Aggregations