Search in sources :

Example 11 with ArchivaRestServiceException

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()));
    }
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 12 with ArchivaRestServiceException

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()));
    }
}
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) PasswordRule(org.apache.archiva.redback.policy.PasswordRule) CookieSettings(org.apache.archiva.redback.policy.CookieSettings) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) NamingException(javax.naming.NamingException) AuthenticationException(javax.naming.AuthenticationException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) NoPermissionException(javax.naming.NoPermissionException) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) AuthenticationNotSupportedException(javax.naming.AuthenticationNotSupportedException) LdapException(org.apache.archiva.redback.common.ldap.connection.LdapException) InvalidNameException(javax.naming.InvalidNameException) CommunicationException(javax.naming.CommunicationException) Authenticator(org.apache.archiva.redback.authentication.Authenticator)

Example 13 with ArchivaRestServiceException

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));
    }
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) LdapConfiguration(org.apache.archiva.rest.api.v2.model.LdapConfiguration) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 14 with ArchivaRestServiceException

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));
    }
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 15 with ArchivaRestServiceException

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);
}
Also used : CommunicationException(javax.naming.CommunicationException) AuthenticationException(javax.naming.AuthenticationException) AuthenticationNotSupportedException(javax.naming.AuthenticationNotSupportedException) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) NoPermissionException(javax.naming.NoPermissionException) ServiceUnavailableException(javax.naming.ServiceUnavailableException)

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