Search in sources :

Example 21 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager in project oxTrust by GluuFederation.

the class CacheRefreshTimer method loadSourceServerEntries.

private List<GluuSimplePerson> loadSourceServerEntries(CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection[] sourceServerConnections) throws SearchException {
    Filter customFilter = cacheRefreshService.createFilter(cacheRefreshConfiguration.getCustomLdapFilter());
    String[] keyAttributes = getCompoundKeyAttributes(cacheRefreshConfiguration);
    String[] keyAttributesWithoutValues = getCompoundKeyAttributesWithoutValues(cacheRefreshConfiguration);
    String[] keyObjectClasses = getCompoundKeyObjectClasses(cacheRefreshConfiguration);
    String[] sourceAttributes = getSourceAttributes(cacheRefreshConfiguration);
    String[] twoLettersArray = createTwoLettersArray();
    String[] returnAttributes = ArrayHelper.arrayMerge(keyAttributesWithoutValues, sourceAttributes);
    Set<String> addedDns = new HashSet<String>();
    List<GluuSimplePerson> sourcePersons = new ArrayList<GluuSimplePerson>();
    for (LdapServerConnection sourceServerConnection : sourceServerConnections) {
        String sourceServerName = sourceServerConnection.getSourceServerName();
        PersistenceEntryManager sourcePersistenceEntryManager = sourceServerConnection.getPersistenceEntryManager();
        String[] baseDns = sourceServerConnection.getBaseDns();
        for (String keyAttributeStart : twoLettersArray) {
            Filter filter = cacheRefreshService.createFilter(keyAttributes, keyObjectClasses, keyAttributeStart, customFilter);
            if (log.isDebugEnabled()) {
                log.trace("Using next filter to load entris from source server: {}", filter);
            }
            for (String baseDn : baseDns) {
                List<GluuSimplePerson> currentSourcePersons = sourcePersistenceEntryManager.findEntries(baseDn, GluuSimplePerson.class, filter, SearchScope.SUB, returnAttributes, null, 0, 0, cacheRefreshConfiguration.getLdapSearchSizeLimit());
                // Add to result and ignore root entry if needed
                for (GluuSimplePerson currentSourcePerson : currentSourcePersons) {
                    currentSourcePerson.setSourceServerName(sourceServerName);
                    // if (!StringHelper.equalsIgnoreCase(baseDn,
                    // currentSourcePerson.getDn())) {
                    String currentSourcePersonDn = currentSourcePerson.getDn().toLowerCase();
                    if (!addedDns.contains(currentSourcePersonDn)) {
                        sourcePersons.add(currentSourcePerson);
                        addedDns.add(currentSourcePersonDn);
                    }
                // }
                }
            }
        }
    }
    return sourcePersons;
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) Filter(org.gluu.search.filter.Filter) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 22 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager in project oxTrust by GluuFederation.

the class CacheRefreshTimer method getSourcePersonsHashCodesMap.

private HashMap<String, Integer> getSourcePersonsHashCodesMap(LdapServerConnection inumDbServerConnection, Map<CacheCompoundKey, GluuSimplePerson> sourcePersonCacheCompoundKeyMap, HashMap<CacheCompoundKey, GluuInumMap> primaryKeyAttrValueInumMap) {
    PersistenceEntryManager inumDbPersistenceEntryManager = inumDbServerConnection.getPersistenceEntryManager();
    HashMap<String, Integer> result = new HashMap<String, Integer>();
    for (Entry<CacheCompoundKey, GluuSimplePerson> sourcePersonCacheCompoundKeyEntry : sourcePersonCacheCompoundKeyMap.entrySet()) {
        CacheCompoundKey cacheCompoundKey = sourcePersonCacheCompoundKeyEntry.getKey();
        GluuSimplePerson sourcePerson = sourcePersonCacheCompoundKeyEntry.getValue();
        GluuInumMap currentInumMap = primaryKeyAttrValueInumMap.get(cacheCompoundKey);
        result.put(currentInumMap.getInum(), inumDbPersistenceEntryManager.getHashCode(sourcePerson));
    }
    return result;
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) GluuInumMap(org.gluu.oxtrust.ldap.cache.model.GluuInumMap) HashMap(java.util.HashMap) CacheCompoundKey(org.gluu.oxtrust.ldap.cache.model.CacheCompoundKey)

Example 23 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager in project oxTrust by GluuFederation.

the class ConfigurationFactory method loadConfigurationFromDb.

@Override
protected LdapOxTrustConfiguration loadConfigurationFromDb(String... returnAttributes) {
    final PersistenceEntryManager persistenceEntryManager = persistenceEntryManagerInstance.get();
    final String configurationDn = getConfigurationDn();
    try {
        final LdapOxTrustConfiguration conf = persistenceEntryManager.find(configurationDn, LdapOxTrustConfiguration.class, returnAttributes);
        return conf;
    } catch (BasePersistenceException ex) {
        log.error("Failed to load configuration from LDAP", ex);
    }
    return null;
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) LdapOxTrustConfiguration(org.gluu.config.oxtrust.LdapOxTrustConfiguration) BasePersistenceException(org.gluu.persist.exception.BasePersistenceException)

Example 24 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager in project oxTrust by GluuFederation.

the class CacheRefreshTimer method prepareLdapServerConnection.

private LdapServerConnection prepareLdapServerConnection(CacheRefreshConfiguration cacheRefreshConfiguration, GluuLdapConfiguration ldapConfiguration, boolean useLocalConnection) {
    String ldapConfig = ldapConfiguration.getConfigId();
    if (useLocalConnection) {
        return new LdapServerConnection(ldapConfig, ldapEntryManager, getBaseDNs(ldapConfiguration));
    }
    PersistenceEntryManagerFactory entryManagerFactory = applicationFactory.getPersistenceEntryManagerFactory(LdapEntryManagerFactory.class);
    String persistenceType = entryManagerFactory.getPersistenceType();
    Properties ldapProperties = toLdapProperties(entryManagerFactory, ldapConfiguration);
    Properties ldapDecryptedProperties = encryptionService.decryptAllProperties(ldapProperties);
    // Try to get updated password via script
    BindCredentials bindCredentials = externalCacheRefreshService.executeExternalGetBindCredentialsMethods(ldapConfig);
    String bindPasswordPropertyKey = persistenceType + "#" + PropertiesDecrypter.BIND_PASSWORD;
    if (bindCredentials != null) {
        log.error("Using updated password which got from getBindCredentials method");
        ldapDecryptedProperties.setProperty(persistenceType + ".bindDN", bindCredentials.getBindDn());
        ldapDecryptedProperties.setProperty(bindPasswordPropertyKey, bindCredentials.getBindPassword());
    }
    if (log.isTraceEnabled()) {
        Properties clonedLdapDecryptedProperties = (Properties) ldapDecryptedProperties.clone();
        if (clonedLdapDecryptedProperties.getProperty(bindPasswordPropertyKey) != null) {
            clonedLdapDecryptedProperties.setProperty(bindPasswordPropertyKey, "REDACTED");
        }
        log.trace("Attempting to create PersistenceEntryManager with properties: {}", clonedLdapDecryptedProperties);
    }
    PersistenceEntryManager customPersistenceEntryManager = entryManagerFactory.createEntryManager(ldapDecryptedProperties);
    log.info("Created Cache Refresh PersistenceEntryManager: {}", customPersistenceEntryManager);
    if (!customPersistenceEntryManager.getOperationService().isConnected()) {
        log.error("Failed to connect to LDAP server using configuration {}", ldapConfig);
        return null;
    }
    return new LdapServerConnection(ldapConfig, customPersistenceEntryManager, getBaseDNs(ldapConfiguration));
}
Also used : BindCredentials(org.gluu.model.custom.script.model.bind.BindCredentials) PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) PersistenceEntryManagerFactory(org.gluu.persist.PersistenceEntryManagerFactory) Properties(java.util.Properties)

Example 25 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager in project oxTrust by GluuFederation.

the class CacheRefreshTimer method updateTargetEntriesViaVDS.

private List<String> updateTargetEntriesViaVDS(CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection targetServerConnection, Set<String> changedInums) {
    List<String> result = new ArrayList<String>();
    PersistenceEntryManager targetPersistenceEntryManager = targetServerConnection.getPersistenceEntryManager();
    Filter filter = cacheRefreshService.createObjectClassPresenceFilter();
    for (String changedInum : changedInums) {
        String baseDn = "action=synchronizecache," + personService.getDnForPerson(changedInum);
        try {
            targetPersistenceEntryManager.findEntries(baseDn, DummyEntry.class, filter, SearchScope.SUB, null, null, 0, 0, cacheRefreshConfiguration.getLdapSearchSizeLimit());
            result.add(changedInum);
            log.debug("Updated entry with inum {}", changedInum);
        } catch (BasePersistenceException ex) {
            log.error("Failed to update entry with inum '{}' using baseDN {}", changedInum, baseDn, ex);
        }
    }
    return result;
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) Filter(org.gluu.search.filter.Filter) ArrayList(java.util.ArrayList)

Aggregations

PersistenceEntryManager (org.gluu.persist.PersistenceEntryManager)38 Properties (java.util.Properties)8 SchemaEntry (org.gluu.model.SchemaEntry)7 ArrayList (java.util.ArrayList)6 ApplicationScoped (javax.enterprise.context.ApplicationScoped)5 Produces (javax.enterprise.inject.Produces)5 Named (javax.inject.Named)5 GluuSimplePerson (org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson)5 BasePersistenceException (org.gluu.persist.exception.BasePersistenceException)5 PersistenceEntryManagerFactory (org.gluu.persist.PersistenceEntryManagerFactory)4 Filter (org.gluu.search.filter.Filter)4 GluuLdapConfiguration (org.gluu.model.ldap.GluuLdapConfiguration)3 GluuInumMap (org.gluu.oxtrust.ldap.cache.model.GluuInumMap)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 CustomScriptType (org.gluu.model.custom.script.CustomScriptType)2 CacheCompoundKey (org.gluu.oxtrust.ldap.cache.model.CacheCompoundKey)2 ApplicationInitializedEvent (org.gluu.service.cdi.event.ApplicationInitializedEvent)2