Search in sources :

Example 1 with GluuLdapConfiguration

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);
}
Also used : PersistenceEntryManager(io.jans.orm.PersistenceEntryManager) List(java.util.List) ArrayList(java.util.ArrayList) ParameterizedTypeImpl(org.jboss.weld.util.reflection.ParameterizedTypeImpl) GluuLdapConfiguration(io.jans.model.ldap.GluuLdapConfiguration)

Example 2 with GluuLdapConfiguration

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);
}
Also used : PersistenceEntryManager(io.jans.orm.PersistenceEntryManager) GluuConfiguration(io.jans.as.persistence.model.configuration.GluuConfiguration) GluuLdapConfiguration(io.jans.model.ldap.GluuLdapConfiguration)

Example 3 with GluuLdapConfiguration

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;
}
Also used : PersistenceEntryManager(io.jans.orm.PersistenceEntryManager) GluuLdapConfiguration(io.jans.model.ldap.GluuLdapConfiguration)

Example 4 with GluuLdapConfiguration

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;
}
Also used : ArrayList(java.util.ArrayList) IDPAuthConf(io.jans.as.persistence.model.configuration.IDPAuthConf) StringEncrypter(io.jans.util.security.StringEncrypter) GluuLdapConfiguration(io.jans.model.ldap.GluuLdapConfiguration)

Example 5 with GluuLdapConfiguration

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;
    }
}
Also used : GluuLdapConfiguration(io.jans.model.ldap.GluuLdapConfiguration) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

GluuLdapConfiguration (io.jans.model.ldap.GluuLdapConfiguration)9 ArrayList (java.util.ArrayList)5 PersistenceEntryManager (io.jans.orm.PersistenceEntryManager)3 IDPAuthConf (io.jans.as.persistence.model.configuration.IDPAuthConf)2 GluuConfiguration (io.jans.as.persistence.model.configuration.GluuConfiguration)1 ProtectedApi (io.jans.configapi.core.rest.ProtectedApi)1 StringEncrypter (io.jans.util.security.StringEncrypter)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 Properties (java.util.Properties)1 ParameterizedTypeImpl (org.jboss.weld.util.reflection.ParameterizedTypeImpl)1