Search in sources :

Example 6 with ArchivaRestServiceException

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()));
    }
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.rest.api.v2.model.RepositoryGroup) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RepositoryException(org.apache.archiva.repository.RepositoryException) ValidationError(org.apache.archiva.repository.validation.ValidationError) Map(java.util.Map)

Example 7 with ArchivaRestServiceException

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));
    }
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RepositoryException(org.apache.archiva.repository.RepositoryException)

Example 8 with ArchivaRestServiceException

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);
    }
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RepositoryException(org.apache.archiva.repository.RepositoryException) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup)

Example 9 with ArchivaRestServiceException

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();
}
Also used : InvalidNameException(javax.naming.InvalidNameException) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) NamingException(javax.naming.NamingException) LdapConnectionConfiguration(org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration) LdapException(org.apache.archiva.redback.common.ldap.connection.LdapException) LdapConnection(org.apache.archiva.redback.common.ldap.connection.LdapConnection)

Example 10 with ArchivaRestServiceException

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));
    }
}
Also used : SecurityConfiguration(org.apache.archiva.rest.api.v2.model.SecurityConfiguration) LoggerFactory(org.slf4j.LoggerFactory) NamingException(javax.naming.NamingException) StringUtils(org.apache.commons.lang3.StringUtils) AuthenticationException(javax.naming.AuthenticationException) UserManager(org.apache.archiva.redback.users.UserManager) RBACManager(org.apache.archiva.redback.rbac.RBACManager) Map(java.util.Map) Authenticator(org.apache.archiva.redback.authentication.Authenticator) PasswordRule(org.apache.archiva.redback.policy.PasswordRule) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) QueryHelper(org.apache.archiva.components.rest.util.QueryHelper) Predicate(java.util.function.Predicate) Collection(java.util.Collection) INVALID_RESULT_SET_ERROR(org.apache.archiva.rest.api.v2.svc.ErrorKeys.INVALID_RESULT_SET_ERROR) Collectors(java.util.stream.Collectors) CacheConfiguration(org.apache.archiva.rest.api.v2.model.CacheConfiguration) BeanInformation(org.apache.archiva.rest.api.v2.model.BeanInformation) List(java.util.List) LdapConnectionConfiguration(org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration) REPOSITORY_ADMIN_ERROR(org.apache.archiva.rest.api.v2.svc.ErrorKeys.REPOSITORY_ADMIN_ERROR) Response(javax.ws.rs.core.Response) ServiceUnavailableException(javax.naming.ServiceUnavailableException) PostConstruct(javax.annotation.PostConstruct) RedbackRuntimeConfigurationAdmin(org.apache.archiva.admin.model.runtime.RedbackRuntimeConfigurationAdmin) NoPermissionException(javax.naming.NoPermissionException) ErrorKeys(org.apache.archiva.rest.api.v2.svc.ErrorKeys) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ResourceBundle(java.util.ResourceBundle) PropertyEntry(org.apache.archiva.components.rest.model.PropertyEntry) Service(org.springframework.stereotype.Service) SecurityConfigurationService(org.apache.archiva.rest.api.v2.svc.SecurityConfigurationService) AuthenticationNotSupportedException(javax.naming.AuthenticationNotSupportedException) Named(javax.inject.Named) LdapException(org.apache.archiva.redback.common.ldap.connection.LdapException) LdapConfiguration(org.apache.archiva.rest.api.v2.model.LdapConfiguration) LdapConnectionFactory(org.apache.archiva.redback.common.ldap.connection.LdapConnectionFactory) LdapUserMapper(org.apache.archiva.redback.common.ldap.user.LdapUserMapper) Logger(org.slf4j.Logger) Properties(java.util.Properties) RoleManager(org.apache.archiva.redback.role.RoleManager) ApplicationContext(org.springframework.context.ApplicationContext) LdapConnection(org.apache.archiva.redback.common.ldap.connection.LdapConnection) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) CookieSettings(org.apache.archiva.redback.policy.CookieSettings) ErrorMessage(org.apache.archiva.rest.api.v2.svc.ErrorMessage) InvalidNameException(javax.naming.InvalidNameException) CommunicationException(javax.naming.CommunicationException) PagedResult(org.apache.archiva.components.rest.model.PagedResult) Comparator(java.util.Comparator) Collections(java.util.Collections) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) PropertyEntry(org.apache.archiva.components.rest.model.PropertyEntry) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) PagedResult(org.apache.archiva.components.rest.model.PagedResult)

Aggregations

ArchivaRestServiceException (org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException)23 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)9 RedbackRuntimeConfiguration (org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration)8 RepositoryException (org.apache.archiva.repository.RepositoryException)6 Map (java.util.Map)4 PagedResult (org.apache.archiva.components.rest.model.PagedResult)4 AuthenticationException (javax.naming.AuthenticationException)3 AuthenticationNotSupportedException (javax.naming.AuthenticationNotSupportedException)3 CommunicationException (javax.naming.CommunicationException)3 InvalidNameException (javax.naming.InvalidNameException)3 NamingException (javax.naming.NamingException)3 NoPermissionException (javax.naming.NoPermissionException)3 ServiceUnavailableException (javax.naming.ServiceUnavailableException)3 Response (javax.ws.rs.core.Response)3 LdapConnection (org.apache.archiva.redback.common.ldap.connection.LdapConnection)3 LdapConnectionConfiguration (org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration)3 LdapException (org.apache.archiva.redback.common.ldap.connection.LdapException)3 EditableRepositoryGroup (org.apache.archiva.repository.EditableRepositoryGroup)3 LdapConfiguration (org.apache.archiva.rest.api.v2.model.LdapConfiguration)3 ArrayList (java.util.ArrayList)2