Search in sources :

Example 6 with RepositoryAdminException

use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.

the class DefaultRedbackRuntimeConfigurationAdmin method getBoolean.

@Override
public boolean getBoolean(String key, boolean defaultValue) {
    if (UserConfigurationKeys.LDAP_SSL.equals(key)) {
        return getRedbackRuntimeConfiguration().getLdapConfiguration().isSsl();
    }
    if (UserConfigurationKeys.LDAP_WRITABLE.equals(key)) {
        return getRedbackRuntimeConfiguration().getLdapConfiguration().isWritable();
    }
    if (UserConfigurationKeys.LDAP_GROUPS_USE_ROLENAME.equals(key)) {
        return getRedbackRuntimeConfiguration().getLdapConfiguration().isUseRoleNameAsGroup();
    }
    if (UserConfigurationKeys.LDAP_BIND_AUTHENTICATOR_ENABLED.equals(key)) {
        return getRedbackRuntimeConfiguration().getLdapConfiguration().isBindAuthenticatorEnabled();
    }
    RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
    if (conf.getConfigurationProperties().containsKey(key)) {
        return Boolean.valueOf(conf.getConfigurationProperties().get(key));
    }
    boolean value = userConfiguration.getBoolean(key, defaultValue);
    conf.getConfigurationProperties().put(key, Boolean.toString(value));
    try {
        updateRedbackRuntimeConfiguration(conf);
    } catch (RepositoryAdminException e) {
        log.error("fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e);
        throw new RuntimeException(e.getMessage(), e);
    }
    return value;
}
Also used : RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 7 with RepositoryAdminException

use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.

the class DefaultRedbackRuntimeConfigurationAdmin method updateRedbackRuntimeConfiguration.

@Override
public void updateRedbackRuntimeConfiguration(RedbackRuntimeConfiguration redbackRuntimeConfiguration) throws RepositoryAdminException {
    org.apache.archiva.configuration.RedbackRuntimeConfiguration runtimeConfiguration = build(redbackRuntimeConfiguration);
    Configuration configuration = archivaConfiguration.getConfiguration();
    configuration.setRedbackRuntimeConfiguration(runtimeConfiguration);
    try {
        archivaConfiguration.save(configuration);
    } catch (RegistryException e) {
        throw new RepositoryAdminException(e.getMessage(), e);
    } catch (IndeterminateConfigurationException e) {
        throw new RepositoryAdminException(e.getMessage(), e);
    }
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) CacheConfiguration(org.apache.archiva.admin.model.beans.CacheConfiguration) LdapConfiguration(org.apache.archiva.admin.model.beans.LdapConfiguration) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) Configuration(org.apache.archiva.configuration.Configuration) UserConfiguration(org.apache.archiva.redback.configuration.UserConfiguration) IndeterminateConfigurationException(org.apache.archiva.configuration.IndeterminateConfigurationException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RegistryException(org.apache.archiva.redback.components.registry.RegistryException)

Example 8 with RepositoryAdminException

use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.

the class DefaultRedbackRuntimeConfigurationAdmin method initialize.

@PostConstruct
@Override
public void initialize() throws UserConfigurationException {
    try {
        RedbackRuntimeConfiguration redbackRuntimeConfiguration = getRedbackRuntimeConfiguration();
        // migrate or not data from redback
        if (!redbackRuntimeConfiguration.isMigratedFromRedbackConfiguration()) {
            // not migrated so build a new fresh one
            redbackRuntimeConfiguration = new RedbackRuntimeConfiguration();
            // so migrate if available
            String userManagerImpl = // 
            userConfiguration.getConcatenatedList(// 
            UserConfigurationKeys.USER_MANAGER_IMPL, DEFAULT_USER_MANAGER_IMPL);
            if (StringUtils.isNotEmpty(userManagerImpl)) {
                String[] impls = StringUtils.split(userManagerImpl, ',');
                for (String impl : impls) {
                    if (StringUtils.equalsIgnoreCase("jdo", impl)) {
                        impl = DEFAULT_USER_MANAGER_IMPL;
                    }
                    redbackRuntimeConfiguration.getUserManagerImpls().add(impl);
                }
            } else {
                redbackRuntimeConfiguration.getUserManagerImpls().add(DEFAULT_USER_MANAGER_IMPL);
            }
            String rbacManagerImpls = // 
            userConfiguration.getConcatenatedList(// 
            UserConfigurationKeys.RBAC_MANAGER_IMPL, DEFAULT_RBAC_MANAGER_IMPL);
            if (StringUtils.isNotEmpty(rbacManagerImpls)) {
                String[] impls = StringUtils.split(rbacManagerImpls, ',');
                for (String impl : impls) {
                    if (StringUtils.equalsIgnoreCase("jdo", impl)) {
                        impl = DEFAULT_RBAC_MANAGER_IMPL;
                    }
                    redbackRuntimeConfiguration.getRbacManagerImpls().add(impl);
                }
            } else {
                redbackRuntimeConfiguration.getRbacManagerImpls().add(DEFAULT_RBAC_MANAGER_IMPL);
            }
            // now ldap
            LdapConfiguration ldapConfiguration = redbackRuntimeConfiguration.getLdapConfiguration();
            if (ldapConfiguration == null) {
                ldapConfiguration = new LdapConfiguration();
                redbackRuntimeConfiguration.setLdapConfiguration(ldapConfiguration);
            }
            ldapConfiguration.setHostName(userConfiguration.getString(UserConfigurationKeys.LDAP_HOSTNAME, null));
            ldapConfiguration.setPort(userConfiguration.getInt(UserConfigurationKeys.LDAP_PORT, -1));
            ldapConfiguration.setSsl(userConfiguration.getBoolean(UserConfigurationKeys.LDAP_SSL, false));
            ldapConfiguration.setBaseDn(userConfiguration.getConcatenatedList(UserConfigurationKeys.LDAP_BASEDN, null));
            ldapConfiguration.setBaseGroupsDn(userConfiguration.getConcatenatedList(UserConfigurationKeys.LDAP_GROUPS_BASEDN, ldapConfiguration.getBaseDn()));
            ldapConfiguration.setContextFactory(userConfiguration.getString(UserConfigurationKeys.LDAP_CONTEX_FACTORY, isSunContextFactoryAvailable() ? "com.sun.jndi.ldap.LdapCtxFactory" : ""));
            ldapConfiguration.setBindDn(userConfiguration.getConcatenatedList(UserConfigurationKeys.LDAP_BINDDN, null));
            ldapConfiguration.setPassword(userConfiguration.getString(UserConfigurationKeys.LDAP_PASSWORD, null));
            ldapConfiguration.setAuthenticationMethod(userConfiguration.getString(UserConfigurationKeys.LDAP_AUTHENTICATION_METHOD, null));
            ldapConfiguration.setWritable(userConfiguration.getBoolean(UserConfigurationKeys.LDAP_WRITABLE, false));
            ldapConfiguration.setUseRoleNameAsGroup(userConfiguration.getBoolean(UserConfigurationKeys.LDAP_GROUPS_USE_ROLENAME, false));
            boolean ldapBindAuthenticatorEnabled = userConfiguration.getBoolean(UserConfigurationKeys.LDAP_BIND_AUTHENTICATOR_ENABLED, false);
            ldapConfiguration.setBindAuthenticatorEnabled(ldapBindAuthenticatorEnabled);
            // LDAP groups mapping reading !!
            // UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY
            // userConfiguration.getKeys()
            Collection<String> keys = userConfiguration.getKeys();
            List<LdapGroupMapping> ldapGroupMappings = new ArrayList<>();
            for (String key : keys) {
                if (key.startsWith(UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY)) {
                    String group = StringUtils.substringAfter(key, UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY);
                    String val = userConfiguration.getConcatenatedList(key, "");
                    if (!StringUtils.isEmpty(val)) {
                        String[] roles = StringUtils.split(val, ',');
                        ldapGroupMappings.add(new LdapGroupMapping(group, roles));
                    }
                }
            }
            redbackRuntimeConfiguration.setLdapGroupMappings(ldapGroupMappings);
            redbackRuntimeConfiguration.setMigratedFromRedbackConfiguration(true);
            updateRedbackRuntimeConfiguration(redbackRuntimeConfiguration);
        }
        // we must ensure userManagerImpls list is not empty if so put at least jdo one !
        if (redbackRuntimeConfiguration.getUserManagerImpls().isEmpty()) {
            log.info("redbackRuntimeConfiguration with empty userManagerImpls so force at least jdo implementation !");
            redbackRuntimeConfiguration.getUserManagerImpls().add("jdo");
            updateRedbackRuntimeConfiguration(redbackRuntimeConfiguration);
        } else {
            log.info("using userManagerImpls: {}", redbackRuntimeConfiguration.getUserManagerImpls());
        }
        // we ensure rbacManagerImpls is not empty if so put at least cached
        if (redbackRuntimeConfiguration.getRbacManagerImpls().isEmpty()) {
            log.info("redbackRuntimeConfiguration with empty rbacManagerImpls so force at least cached implementation !");
            redbackRuntimeConfiguration.getRbacManagerImpls().add("cached");
            updateRedbackRuntimeConfiguration(redbackRuntimeConfiguration);
        } else {
            log.info("using rbacManagerImpls: {}", redbackRuntimeConfiguration.getRbacManagerImpls());
        }
        boolean save = false;
        // NPE free
        if (redbackRuntimeConfiguration.getUsersCacheConfiguration() == null) {
            redbackRuntimeConfiguration.setUsersCacheConfiguration(new CacheConfiguration());
        }
        // if -1 it means non initialized to take values from the spring bean
        if (redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToIdleSeconds() < 0) {
            redbackRuntimeConfiguration.getUsersCacheConfiguration().setTimeToIdleSeconds(usersCache.getTimeToIdleSeconds());
            save = true;
        }
        usersCache.setTimeToIdleSeconds(redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToIdleSeconds());
        if (redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToLiveSeconds() < 0) {
            redbackRuntimeConfiguration.getUsersCacheConfiguration().setTimeToLiveSeconds(usersCache.getTimeToLiveSeconds());
            save = true;
        }
        usersCache.setTimeToLiveSeconds(redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToLiveSeconds());
        if (redbackRuntimeConfiguration.getUsersCacheConfiguration().getMaxElementsInMemory() < 0) {
            redbackRuntimeConfiguration.getUsersCacheConfiguration().setMaxElementsInMemory(usersCache.getMaxElementsInMemory());
            save = true;
        }
        usersCache.setMaxElementsInMemory(redbackRuntimeConfiguration.getUsersCacheConfiguration().getMaxElementsInMemory());
        if (redbackRuntimeConfiguration.getUsersCacheConfiguration().getMaxElementsOnDisk() < 0) {
            redbackRuntimeConfiguration.getUsersCacheConfiguration().setMaxElementsOnDisk(usersCache.getMaxElementsOnDisk());
            save = true;
        }
        usersCache.setMaxElementsOnDisk(redbackRuntimeConfiguration.getUsersCacheConfiguration().getMaxElementsOnDisk());
        if (save) {
            updateRedbackRuntimeConfiguration(redbackRuntimeConfiguration);
        }
    } catch (RepositoryAdminException e) {
        throw new UserConfigurationException(e.getMessage(), e);
    }
}
Also used : LdapGroupMapping(org.apache.archiva.admin.model.beans.LdapGroupMapping) ArrayList(java.util.ArrayList) LdapConfiguration(org.apache.archiva.admin.model.beans.LdapConfiguration) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) CacheConfiguration(org.apache.archiva.admin.model.beans.CacheConfiguration) UserConfigurationException(org.apache.archiva.redback.configuration.UserConfigurationException) PostConstruct(javax.annotation.PostConstruct)

Example 9 with RepositoryAdminException

use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.

the class DefaultRedbackRuntimeConfigurationAdmin method getInt.

@Override
public int getInt(String key, int defaultValue) {
    if (UserConfigurationKeys.LDAP_PORT.equals(key)) {
        return getRedbackRuntimeConfiguration().getLdapConfiguration().getPort();
    }
    RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
    if (conf.getConfigurationProperties().containsKey(key)) {
        return Integer.valueOf(conf.getConfigurationProperties().get(key));
    }
    int value = userConfiguration.getInt(key, defaultValue);
    conf.getConfigurationProperties().put(key, Integer.toString(value));
    try {
        updateRedbackRuntimeConfiguration(conf);
    } catch (RepositoryAdminException e) {
        log.error("fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e);
        throw new RuntimeException(e.getMessage(), e);
    }
    return value;
}
Also used : RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 10 with RepositoryAdminException

use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.

the class DefaultRepositoryCommonValidator method basicValidation.

/**
 * @param abstractRepository
 * @param update             in update mode if yes already exists won't be check
 * @throws RepositoryAdminException
 */
@Override
public void basicValidation(AbstractRepository abstractRepository, boolean update) throws RepositoryAdminException {
    Configuration config = archivaConfiguration.getConfiguration();
    String repoId = abstractRepository.getId();
    if (!update) {
        if (config.getManagedRepositoriesAsMap().containsKey(repoId)) {
            throw new RepositoryAdminException("Unable to add new repository with id [" + repoId + "], that id already exists as a managed repository.");
        } else if (config.getRepositoryGroupsAsMap().containsKey(repoId)) {
            throw new RepositoryAdminException("Unable to add new repository with id [" + repoId + "], that id already exists as a repository group.");
        } else if (config.getRemoteRepositoriesAsMap().containsKey(repoId)) {
            throw new RepositoryAdminException("Unable to add new repository with id [" + repoId + "], that id already exists as a remote repository.");
        }
    }
    if (StringUtils.isBlank(repoId)) {
        throw new RepositoryAdminException("Repository ID cannot be empty.");
    }
    if (!GenericValidator.matchRegexp(repoId, REPOSITORY_ID_VALID_EXPRESSION)) {
        throw new RepositoryAdminException("Invalid repository ID. Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-).");
    }
    String name = abstractRepository.getName();
    if (StringUtils.isBlank(name)) {
        throw new RepositoryAdminException("repository name cannot be empty");
    }
    if (!GenericValidator.matchRegexp(name, REPOSITORY_NAME_VALID_EXPRESSION)) {
        throw new RepositoryAdminException("Invalid repository name. Repository Name must only contain alphanumeric characters, white-spaces(' '), " + "forward-slashes(/), open-parenthesis('('), close-parenthesis(')'),  underscores(_), dots(.), and dashes(-).");
    }
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) Configuration(org.apache.archiva.configuration.Configuration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Aggregations

RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)67 Configuration (org.apache.archiva.configuration.Configuration)18 Path (java.nio.file.Path)15 RedbackRuntimeConfiguration (org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration)14 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)14 RepositoryException (org.apache.archiva.repository.RepositoryException)13 IOException (java.io.IOException)12 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)10 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)10 ArrayList (java.util.ArrayList)9 RepositoryGroupConfiguration (org.apache.archiva.configuration.RepositoryGroupConfiguration)7 NetworkProxy (org.apache.archiva.admin.model.beans.NetworkProxy)6 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)6 IndexUpdateFailedException (org.apache.archiva.indexer.IndexUpdateFailedException)6 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)6 RemoteRepository (org.apache.archiva.repository.RemoteRepository)6 Date (java.util.Date)5 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)5 PostConstruct (javax.annotation.PostConstruct)4 LdapGroupMapping (org.apache.archiva.admin.model.beans.LdapGroupMapping)4