Search in sources :

Example 1 with CacheConfiguration

use of org.apache.archiva.admin.model.beans.CacheConfiguration 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 2 with CacheConfiguration

use of org.apache.archiva.admin.model.beans.CacheConfiguration in project archiva by apache.

the class DefaultRedbackRuntimeConfigurationAdmin method build.

private org.apache.archiva.configuration.RedbackRuntimeConfiguration build(RedbackRuntimeConfiguration redbackRuntimeConfiguration) {
    org.apache.archiva.configuration.RedbackRuntimeConfiguration res = getModelMapper().map(redbackRuntimeConfiguration, org.apache.archiva.configuration.RedbackRuntimeConfiguration.class);
    if (redbackRuntimeConfiguration.getLdapConfiguration() == null) {
        redbackRuntimeConfiguration.setLdapConfiguration(new LdapConfiguration());
    }
    res.setLdapConfiguration(getModelMapper().map(redbackRuntimeConfiguration.getLdapConfiguration(), org.apache.archiva.configuration.LdapConfiguration.class));
    if (redbackRuntimeConfiguration.getUsersCacheConfiguration() == null) {
        redbackRuntimeConfiguration.setUsersCacheConfiguration(new CacheConfiguration());
    }
    res.setUsersCacheConfiguration(getModelMapper().map(redbackRuntimeConfiguration.getUsersCacheConfiguration(), org.apache.archiva.configuration.CacheConfiguration.class));
    List<LdapGroupMapping> ldapGroupMappings = redbackRuntimeConfiguration.getLdapGroupMappings();
    if (ldapGroupMappings != null && ldapGroupMappings.size() > 0) {
        List<org.apache.archiva.configuration.LdapGroupMapping> mappings = new ArrayList<>(ldapGroupMappings.size());
        for (LdapGroupMapping ldapGroupMapping : ldapGroupMappings) {
            org.apache.archiva.configuration.LdapGroupMapping mapping = new org.apache.archiva.configuration.LdapGroupMapping();
            mapping.setGroup(ldapGroupMapping.getGroup());
            mapping.setRoleNames(new ArrayList<>(ldapGroupMapping.getRoleNames()));
            mappings.add(mapping);
        }
        res.setLdapGroupMappings(mappings);
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) LdapConfiguration(org.apache.archiva.admin.model.beans.LdapConfiguration) LdapGroupMapping(org.apache.archiva.admin.model.beans.LdapGroupMapping) CacheConfiguration(org.apache.archiva.admin.model.beans.CacheConfiguration)

Example 3 with CacheConfiguration

use of org.apache.archiva.admin.model.beans.CacheConfiguration in project archiva by apache.

the class DefaultArchivaRuntimeConfigurationAdmin method initialize.

@PostConstruct
public void initialize() throws RepositoryAdminException {
    ArchivaRuntimeConfiguration archivaRuntimeConfiguration = getArchivaRuntimeConfiguration();
    boolean save = false;
    // NPE free
    if (archivaRuntimeConfiguration.getFileLockConfiguration() == null) {
        archivaRuntimeConfiguration.setFileLockConfiguration(new FileLockConfiguration());
    }
    // NPE free
    if (archivaRuntimeConfiguration.getUrlFailureCacheConfiguration() == null) {
        archivaRuntimeConfiguration.setUrlFailureCacheConfiguration(new CacheConfiguration());
    }
    // if -1 it means non initialized to take values from the spring bean
    if (archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getTimeToIdleSeconds() < 0) {
        archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().setTimeToIdleSeconds(urlFailureCache.getTimeToIdleSeconds());
        save = true;
    }
    urlFailureCache.setTimeToIdleSeconds(archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getTimeToIdleSeconds());
    if (archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getTimeToLiveSeconds() < 0) {
        archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().setTimeToLiveSeconds(urlFailureCache.getTimeToLiveSeconds());
        save = true;
    }
    urlFailureCache.setTimeToLiveSeconds(archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getTimeToLiveSeconds());
    if (archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getMaxElementsInMemory() < 0) {
        archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().setMaxElementsInMemory(urlFailureCache.getMaxElementsInMemory());
        save = true;
    }
    urlFailureCache.setMaxElementsInMemory(archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getMaxElementsInMemory());
    if (archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getMaxElementsOnDisk() < 0) {
        archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().setMaxElementsOnDisk(urlFailureCache.getMaxElementsOnDisk());
        save = true;
    }
    urlFailureCache.setMaxElementsOnDisk(archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getMaxElementsOnDisk());
    if (save) {
        updateArchivaRuntimeConfiguration(archivaRuntimeConfiguration);
    }
}
Also used : ArchivaRuntimeConfiguration(org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration) CacheConfiguration(org.apache.archiva.admin.model.beans.CacheConfiguration) FileLockConfiguration(org.apache.archiva.admin.model.beans.FileLockConfiguration) PostConstruct(javax.annotation.PostConstruct)

Example 4 with CacheConfiguration

use of org.apache.archiva.admin.model.beans.CacheConfiguration in project archiva by apache.

the class DefaultArchivaRuntimeConfigurationService method updateArchivaRuntimeConfiguration.

@Override
public Boolean updateArchivaRuntimeConfiguration(ArchivaRuntimeConfiguration archivaRuntimeConfiguration) throws ArchivaRestServiceException {
    try {
        archivaRuntimeConfigurationAdmin.updateArchivaRuntimeConfiguration(archivaRuntimeConfiguration);
        CacheConfiguration cacheConfiguration = archivaRuntimeConfiguration.getUrlFailureCacheConfiguration();
        if (cacheConfiguration != null) {
            usersCache.setTimeToLiveSeconds(cacheConfiguration.getTimeToLiveSeconds());
            usersCache.setTimeToIdleSeconds(cacheConfiguration.getTimeToIdleSeconds());
            usersCache.setMaxElementsOnDisk(cacheConfiguration.getMaxElementsOnDisk());
            usersCache.setMaxElementsInMemory(cacheConfiguration.getMaxElementsInMemory());
        }
        FileLockConfiguration fileLockConfiguration = archivaRuntimeConfiguration.getFileLockConfiguration();
        if (fileLockConfiguration != null) {
            fileLockManager.setTimeout(fileLockConfiguration.getLockingTimeout());
            fileLockManager.setSkipLocking(fileLockConfiguration.isSkipLocking());
        }
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(e.getMessage(), e);
    }
    return Boolean.TRUE;
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) CacheConfiguration(org.apache.archiva.admin.model.beans.CacheConfiguration) FileLockConfiguration(org.apache.archiva.admin.model.beans.FileLockConfiguration)

Example 5 with CacheConfiguration

use of org.apache.archiva.admin.model.beans.CacheConfiguration in project archiva by apache.

the class DefaultRedbackRuntimeConfigurationAdmin method build.

private RedbackRuntimeConfiguration build(org.apache.archiva.configuration.RedbackRuntimeConfiguration runtimeConfiguration) {
    RedbackRuntimeConfiguration redbackRuntimeConfiguration = getModelMapper().map(runtimeConfiguration, RedbackRuntimeConfiguration.class);
    if (runtimeConfiguration.getLdapConfiguration() != null) {
        redbackRuntimeConfiguration.setLdapConfiguration(getModelMapper().map(runtimeConfiguration.getLdapConfiguration(), LdapConfiguration.class));
    }
    if (runtimeConfiguration.getUsersCacheConfiguration() != null) {
        redbackRuntimeConfiguration.setUsersCacheConfiguration(getModelMapper().map(runtimeConfiguration.getUsersCacheConfiguration(), CacheConfiguration.class));
    }
    if (redbackRuntimeConfiguration.getLdapConfiguration() == null) {
        // prevent NPE
        redbackRuntimeConfiguration.setLdapConfiguration(new LdapConfiguration());
    }
    if (redbackRuntimeConfiguration.getUsersCacheConfiguration() == null) {
        redbackRuntimeConfiguration.setUsersCacheConfiguration(new CacheConfiguration());
    }
    List<org.apache.archiva.configuration.LdapGroupMapping> mappings = runtimeConfiguration.getLdapGroupMappings();
    if (mappings != null && mappings.size() > 0) {
        List<LdapGroupMapping> ldapGroupMappings = new ArrayList<>(mappings.size());
        for (org.apache.archiva.configuration.LdapGroupMapping mapping : mappings) {
            ldapGroupMappings.add(new LdapGroupMapping(mapping.getGroup(), mapping.getRoleNames()));
        }
        redbackRuntimeConfiguration.setLdapGroupMappings(ldapGroupMappings);
    }
    cleanupProperties(redbackRuntimeConfiguration);
    return redbackRuntimeConfiguration;
}
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) CacheConfiguration(org.apache.archiva.admin.model.beans.CacheConfiguration)

Aggregations

CacheConfiguration (org.apache.archiva.admin.model.beans.CacheConfiguration)5 ArrayList (java.util.ArrayList)3 LdapConfiguration (org.apache.archiva.admin.model.beans.LdapConfiguration)3 LdapGroupMapping (org.apache.archiva.admin.model.beans.LdapGroupMapping)3 PostConstruct (javax.annotation.PostConstruct)2 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)2 FileLockConfiguration (org.apache.archiva.admin.model.beans.FileLockConfiguration)2 RedbackRuntimeConfiguration (org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration)2 ArchivaRuntimeConfiguration (org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration)1 UserConfigurationException (org.apache.archiva.redback.configuration.UserConfigurationException)1 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)1