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);
}
}
Aggregations