use of org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException in project archiva by apache.
the class DefaultRepositoryGroupService method updateRepositoryGroup.
@Override
public RepositoryGroup updateRepositoryGroup(final String repositoryGroupId, final RepositoryGroup repositoryGroup) throws ArchivaRestServiceException {
if (StringUtils.isEmpty(repositoryGroupId)) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, ""), 404);
}
if (!repositoryRegistry.hasRepositoryGroup(repositoryGroupId)) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND), 404);
}
repositoryGroup.setId(repositoryGroupId);
try {
RepositoryGroupConfiguration configuration = toConfig(repositoryGroup);
CheckedResult<org.apache.archiva.repository.RepositoryGroup, Map<String, List<ValidationError>>> validationResult = repositoryRegistry.putRepositoryGroupAndValidate(configuration);
if (validationResult.isValid()) {
httpServletResponse.setStatus(201);
return RepositoryGroup.of(validationResult.getRepository());
} else {
throw ValidationException.of(validationResult.getResult());
}
} catch (RepositoryException e) {
log.error("Exception during repository group update: {}", e.getMessage(), e);
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_UPDATE_FAILED, e.getMessage()));
}
}
use of org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException in project archiva by apache.
the class DefaultRepositoryGroupService method deleteRepositoryGroup.
@Override
public Response deleteRepositoryGroup(String repositoryGroupId) throws ArchivaRestServiceException {
if (StringUtils.isEmpty(repositoryGroupId)) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, ""), 404);
}
try {
org.apache.archiva.repository.RepositoryGroup group = repositoryRegistry.getRepositoryGroup(repositoryGroupId);
if (group == null) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, ""), 404);
}
repositoryRegistry.removeRepositoryGroup(group);
return Response.ok().build();
} catch (RepositoryException e) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_DELETE_FAILED));
}
}
use of org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException in project archiva by apache.
the class DefaultRepositoryGroupService method addRepositoryToGroup.
@Override
public RepositoryGroup addRepositoryToGroup(String repositoryGroupId, String repositoryId) throws ArchivaRestServiceException {
if (StringUtils.isEmpty(repositoryGroupId)) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, ""), 404);
}
if (StringUtils.isEmpty(repositoryId)) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_NOT_FOUND, ""), 404);
}
try {
org.apache.archiva.repository.RepositoryGroup repositoryGroup = repositoryRegistry.getRepositoryGroup(repositoryGroupId);
if (repositoryGroup == null) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, ""), 404);
}
if (!(repositoryGroup instanceof EditableRepositoryGroup)) {
log.error("This group instance is not editable: {}", repositoryGroupId);
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_UPDATE_FAILED, ""), 500);
}
EditableRepositoryGroup editableRepositoryGroup = (EditableRepositoryGroup) repositoryGroup;
if (editableRepositoryGroup.getRepositories().stream().anyMatch(repo -> repositoryId.equals(repo.getId()))) {
log.info("Repository {} is already member of group {}", repositoryId, repositoryGroupId);
return RepositoryGroup.of(editableRepositoryGroup);
}
org.apache.archiva.repository.ManagedRepository managedRepo = repositoryRegistry.getManagedRepository(repositoryId);
if (managedRepo == null) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_NOT_FOUND, ""), 404);
}
editableRepositoryGroup.addRepository(managedRepo);
org.apache.archiva.repository.RepositoryGroup newGroup = repositoryRegistry.putRepositoryGroup(editableRepositoryGroup);
return RepositoryGroup.of(newGroup);
} catch (RepositoryException e) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_UPDATE_FAILED, e.getMessage()), 500);
}
}
use of org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException 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.svc.ArchivaRestServiceException 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));
}
}
Aggregations