Search in sources :

Example 1 with Authenticator

use of org.apache.archiva.redback.authentication.Authenticator in project archiva by apache.

the class DefaultRedbackRuntimeConfigurationService method updateRedbackRuntimeConfiguration.

@Override
public Boolean updateRedbackRuntimeConfiguration(RedbackRuntimeConfiguration redbackRuntimeConfiguration) throws ArchivaRestServiceException {
    try {
        // has user manager impl changed ?
        boolean userManagerChanged = redbackRuntimeConfiguration.getUserManagerImpls().size() != redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration().getUserManagerImpls().size();
        userManagerChanged = userManagerChanged || (redbackRuntimeConfiguration.getUserManagerImpls().toString().hashCode() != redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration().getUserManagerImpls().toString().hashCode());
        boolean rbacManagerChanged = redbackRuntimeConfiguration.getRbacManagerImpls().size() != redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration().getRbacManagerImpls().size();
        rbacManagerChanged = rbacManagerChanged || (redbackRuntimeConfiguration.getRbacManagerImpls().toString().hashCode() != redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration().getRbacManagerImpls().toString().hashCode());
        boolean ldapConfigured = false;
        for (String um : redbackRuntimeConfiguration.getUserManagerImpls()) {
            if (um.contains("ldap")) {
                ldapConfigured = true;
            }
        }
        if (!ldapConfigured) {
            for (String rbm : redbackRuntimeConfiguration.getRbacManagerImpls()) {
                if (rbm.contains("ldap")) {
                    ldapConfigured = true;
                }
            }
        }
        redbackRuntimeConfigurationAdmin.updateRedbackRuntimeConfiguration(redbackRuntimeConfiguration);
        if (userManagerChanged) {
            log.info("user managerImpls changed to {} so reload it", redbackRuntimeConfiguration.getUserManagerImpls());
            userManager.initialize();
        }
        if (rbacManagerChanged) {
            log.info("rbac manager changed to {} so reload it", redbackRuntimeConfiguration.getRbacManagerImpls());
            rbacManager.initialize();
            roleManager.initialize();
        }
        if (ldapConfigured) {
            try {
                ldapConnectionFactory.initialize();
            } catch (Exception e) {
                ArchivaRestServiceException newEx = new ArchivaRestServiceException(e.getMessage(), e);
                newEx.setErrorKey("error.ldap.connectionFactory.init.failed");
                throw newEx;
            }
        }
        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);
            }
        }
        // users cache
        usersCache.setTimeToIdleSeconds(redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToIdleSeconds());
        usersCache.setTimeToLiveSeconds(redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToLiveSeconds());
        usersCache.setMaxElementsInMemory(redbackRuntimeConfiguration.getUsersCacheConfiguration().getMaxElementsInMemory());
        usersCache.setMaxElementsOnDisk(redbackRuntimeConfiguration.getUsersCacheConfiguration().getMaxElementsOnDisk());
        if (ldapConfigured) {
            try {
                ldapUserMapper.initialize();
            } catch (Exception e) {
                ArchivaRestServiceException newEx = new ArchivaRestServiceException(e.getMessage(), e);
                newEx.setErrorKey("error.ldap.userMapper.init.failed");
                throw newEx;
            }
        }
        return Boolean.TRUE;
    } catch (ArchivaRestServiceException e) {
        log.error(e.getMessage(), e);
        throw e;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), e);
    }
}
Also used : PasswordRule(org.apache.archiva.redback.policy.PasswordRule) CookieSettings(org.apache.archiva.redback.policy.CookieSettings) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) LdapException(org.apache.archiva.redback.common.ldap.connection.LdapException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) InvalidNameException(javax.naming.InvalidNameException) Authenticator(org.apache.archiva.redback.authentication.Authenticator)

Aggregations

InvalidNameException (javax.naming.InvalidNameException)1 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)1 Authenticator (org.apache.archiva.redback.authentication.Authenticator)1 LdapException (org.apache.archiva.redback.common.ldap.connection.LdapException)1 CookieSettings (org.apache.archiva.redback.policy.CookieSettings)1 PasswordRule (org.apache.archiva.redback.policy.PasswordRule)1 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)1