use of io.jans.model.ldap.GluuLdapConfiguration in project jans by JanssenProject.
the class AppInitializer method recreatePersistenceAuthEntryManagers.
public void recreatePersistenceAuthEntryManagers(List<GluuLdapConfiguration> newPersistenceAuthConfigs) {
// Get existing application scoped instance
List<PersistenceEntryManager> oldPersistenceAuthEntryManagers = CdiUtil.getContextBean(beanManager, new ParameterizedTypeImpl(List.class, PersistenceEntryManager.class), ApplicationFactory.PERSISTENCE_AUTH_ENTRY_MANAGER_NAME);
// Recreate components
this.persistenceAuthConfigs = newPersistenceAuthConfigs;
// Close existing connections
closePersistenceEntryManagers(oldPersistenceAuthEntryManagers);
// Destroy old Ldap auth entry managers
for (PersistenceEntryManager oldPersistenceAuthEntryManager : oldPersistenceAuthEntryManagers) {
log.debug("Attempting to destroy {}: {}", ApplicationFactory.PERSISTENCE_AUTH_ENTRY_MANAGER_NAME, oldPersistenceAuthEntryManager);
oldPersistenceAuthEntryManager.destroy();
log.debug("Destroyed {}: {}", ApplicationFactory.PERSISTENCE_AUTH_ENTRY_MANAGER_NAME, oldPersistenceAuthEntryManager);
externalPersistenceExtensionService.executePersistenceExtensionAfterDestroy(oldPersistenceAuthEntryManager);
}
// Force to create new Ldap auth entry managers bean
List<PersistenceEntryManager> persistenceAuthEntryManagers = persistenceAuthEntryManagerInstance.get();
persistenceAuthEntryManagerInstance.destroy(persistenceAuthEntryManagers);
log.info("Recreated instance {}: {}", ApplicationFactory.PERSISTENCE_AUTH_ENTRY_MANAGER_NAME, persistenceAuthEntryManagers);
// Force to create new auth configuration bean
List<GluuLdapConfiguration> oldPersistenceAuthConfigs = persistenceAuthConfigInstance.get();
persistenceAuthConfigInstance.destroy(oldPersistenceAuthConfigs);
}
use of io.jans.model.ldap.GluuLdapConfiguration in project jans by JanssenProject.
the class AppInitializer method reloadConfiguration.
private void reloadConfiguration() {
PersistenceEntryManager localPersistenceEntryManager = persistenceEntryManagerInstance.get();
log.trace("Attempting to use {}: {}", ApplicationFactory.PERSISTENCE_ENTRY_MANAGER_NAME, localPersistenceEntryManager.getOperationService());
GluuConfiguration newConfiguration = loadConfiguration(localPersistenceEntryManager, "jansDbAuth", "jansAuthMode");
List<GluuLdapConfiguration> newPersistenceAuthConfigs = loadPersistenceAuthConfigs(newConfiguration);
if (!this.persistenceAuthConfigs.equals(newPersistenceAuthConfigs)) {
recreatePersistenceAuthEntryManagers(newPersistenceAuthConfigs);
this.persistenceAuthConfigs = newPersistenceAuthConfigs;
event.select(ReloadAuthScript.Literal.INSTANCE).fire(ExternalAuthenticationService.MODIFIED_INTERNAL_TYPES_EVENT_TYPE);
}
setDefaultAuthenticationMethod(newConfiguration);
}
use of io.jans.model.ldap.GluuLdapConfiguration in project jans by JanssenProject.
the class AuthenticationService method externalAuthenticate.
private boolean externalAuthenticate(String keyValue, String password) {
for (int i = 0; i < this.ldapAuthConfigs.size(); i++) {
GluuLdapConfiguration ldapAuthConfig = this.ldapAuthConfigs.get(i);
PersistenceEntryManager ldapAuthEntryManager = this.ldapAuthEntryManagers.get(i);
String primaryKey = "uid";
if (StringHelper.isNotEmpty(ldapAuthConfig.getPrimaryKey())) {
primaryKey = ldapAuthConfig.getPrimaryKey();
}
String localPrimaryKey = "uid";
if (StringHelper.isNotEmpty(ldapAuthConfig.getLocalPrimaryKey())) {
localPrimaryKey = ldapAuthConfig.getLocalPrimaryKey();
}
boolean authenticated = authenticate(ldapAuthConfig, ldapAuthEntryManager, keyValue, password, primaryKey, localPrimaryKey, false);
if (authenticated) {
return authenticated;
}
}
return false;
}
use of io.jans.model.ldap.GluuLdapConfiguration in project jans by JanssenProject.
the class LdapConfigurationService method getIDPAuthConfs.
private List<IDPAuthConf> getIDPAuthConfs(List<GluuLdapConfiguration> ldapConfigurations) {
List<IDPAuthConf> idpConf = new ArrayList<IDPAuthConf>();
for (GluuLdapConfiguration ldapConfig : ldapConfigurations) {
if (shouldEncryptPassword(ldapConfig)) {
try {
ldapConfig.setBindPassword(encryptionService.encrypt(ldapConfig.getBindPassword()));
} catch (StringEncrypter.EncryptionException e) {
throw new RuntimeException("Unable to decrypt password.", e);
}
}
if (ldapConfig.isUseAnonymousBind()) {
ldapConfig.setBindDN(null);
}
IDPAuthConf ldapConfigIdpAuthConf = new IDPAuthConf();
ldapConfig.updateStringsLists();
ldapConfigIdpAuthConf.setType(AUTH);
ldapConfigIdpAuthConf.setVersion(ldapConfigIdpAuthConf.getVersion() + 1);
ldapConfigIdpAuthConf.setName(ldapConfig.getConfigId());
ldapConfigIdpAuthConf.setEnabled(ldapConfig.isEnabled());
ldapConfigIdpAuthConf.setConfig(JacksonUtils.newMapper().valueToTree(ldapConfig));
idpConf.add(ldapConfigIdpAuthConf);
}
return idpConf;
}
use of io.jans.model.ldap.GluuLdapConfiguration in project jans by JanssenProject.
the class LdapConfigurationService method shouldEncryptPassword.
public boolean shouldEncryptPassword(GluuLdapConfiguration ldapConfiguration) {
try {
GluuLdapConfiguration oldConfiguration = findByName(ldapConfiguration.getConfigId());
String encryptedOldPassword = oldConfiguration.getBindPassword();
return !StringUtils.equals(encryptedOldPassword, ldapConfiguration.getBindPassword());
} catch (NoSuchElementException ex) {
return true;
}
}
Aggregations