Search in sources :

Example 1 with GluuInumMap

use of org.gluu.oxtrust.ldap.cache.model.GluuInumMap in project oxTrust by GluuFederation.

the class CacheRefreshTimer method removeTargetEntries.

private Pair<List<String>, List<String>> removeTargetEntries(LdapServerConnection inumDbServerConnection, LdapEntryManager targetLdapEntryManager, List<GluuSimplePerson> removedPersons, HashMap<String, GluuInumMap> inumInumMap) {
    String runDate = ldapEntryManager.encodeGeneralizedTime(new Date(this.lastFinishedTime));
    LdapEntryManager inumDbLdapEntryManager = inumDbServerConnection.getLdapEntryManager();
    List<String> result1 = new ArrayList<String>();
    List<String> result2 = new ArrayList<String>();
    for (GluuSimplePerson removedPerson : removedPersons) {
        String inum = removedPerson.getAttribute(OxTrustConstants.inum);
        // Update GluuInumMap if it exist
        GluuInumMap currentInumMap = inumInumMap.get(inum);
        if (currentInumMap == null) {
            log.warn("Can't find inum entry of person with DN: {}", removedPerson.getDn());
        } else {
            GluuInumMap removedInumMap = getMarkInumMapEntryAsRemoved(currentInumMap, runDate);
            try {
                inumDbLdapEntryManager.merge(removedInumMap);
                result2.add(removedInumMap.getInum());
            } catch (BaseMappingException ex) {
                log.error("Failed to update entry with inum '{}' and DN: {}", currentInumMap.getInum(), currentInumMap.getDn(), ex);
                continue;
            }
        }
        // Remove person from target server
        try {
            targetLdapEntryManager.removeRecursively(removedPerson.getDn());
            result1.add(inum);
        } catch (BaseMappingException ex) {
            log.error("Failed to remove person entry with inum '{}' and DN: {}", inum, removedPerson.getDn(), ex);
            continue;
        }
        log.debug("Person with DN: '{}' removed from target server", removedPerson.getDn());
    }
    return new Pair<List<String>, List<String>>(result1, result2);
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) GluuInumMap(org.gluu.oxtrust.ldap.cache.model.GluuInumMap) LdapEntryManager(org.gluu.persist.ldap.impl.LdapEntryManager) ArrayList(java.util.ArrayList) Date(java.util.Date) Pair(org.xdi.util.Pair)

Example 2 with GluuInumMap

use of org.gluu.oxtrust.ldap.cache.model.GluuInumMap in project oxTrust by GluuFederation.

the class CacheRefreshTimer method addGluuInumMap.

private GluuInumMap addGluuInumMap(String inumbBaseDn, LdapEntryManager inumDbLdapEntryManager, String[] primaryKeyAttrName, String[][] primaryKeyValues) {
    String inum = cacheRefreshService.generateInumForNewInumMap(inumbBaseDn, inumDbLdapEntryManager);
    String inumDn = cacheRefreshService.getDnForInum(inumbBaseDn, inum);
    GluuInumMap inumMap = new GluuInumMap();
    inumMap.setDn(inumDn);
    inumMap.setInum(inum);
    inumMap.setPrimaryKeyAttrName(primaryKeyAttrName[0]);
    inumMap.setPrimaryKeyValues(primaryKeyValues[0]);
    if (primaryKeyAttrName.length > 1) {
        inumMap.setSecondaryKeyAttrName(primaryKeyAttrName[1]);
        inumMap.setSecondaryKeyValues(primaryKeyValues[1]);
    }
    if (primaryKeyAttrName.length > 2) {
        inumMap.setTertiaryKeyAttrName(primaryKeyAttrName[2]);
        inumMap.setTertiaryKeyValues(primaryKeyValues[2]);
    }
    inumMap.setStatus(GluuStatus.ACTIVE);
    cacheRefreshService.addInumMap(inumDbLdapEntryManager, inumMap);
    return inumMap;
}
Also used : GluuInumMap(org.gluu.oxtrust.ldap.cache.model.GluuInumMap)

Example 3 with GluuInumMap

use of org.gluu.oxtrust.ldap.cache.model.GluuInumMap in project oxTrust by GluuFederation.

the class CacheRefreshTimer method removeTargetEntries.

private Pair<List<String>, List<String>> removeTargetEntries(LdapServerConnection inumDbServerConnection, PersistenceEntryManager targetPersistenceEntryManager, List<GluuSimplePerson> removedPersons, HashMap<String, GluuInumMap> inumInumMap) {
    Date runDate = new Date(this.lastFinishedTime);
    PersistenceEntryManager inumDbPersistenceEntryManager = inumDbServerConnection.getPersistenceEntryManager();
    List<String> result1 = new ArrayList<String>();
    List<String> result2 = new ArrayList<String>();
    for (GluuSimplePerson removedPerson : removedPersons) {
        String inum = removedPerson.getAttribute(OxTrustConstants.inum);
        // Update GluuInumMap if it exist
        GluuInumMap currentInumMap = inumInumMap.get(inum);
        if (currentInumMap == null) {
            log.warn("Can't find inum entry of person with DN: {}", removedPerson.getDn());
        } else {
            GluuInumMap removedInumMap = getMarkInumMapEntryAsRemoved(currentInumMap, ldapEntryManager.encodeTime(removedPerson.getDn(), runDate));
            try {
                inumDbPersistenceEntryManager.merge(removedInumMap);
                result2.add(removedInumMap.getInum());
            } catch (BasePersistenceException ex) {
                log.error("Failed to update entry with inum '{}' and DN: {}", currentInumMap.getInum(), currentInumMap.getDn(), ex);
                continue;
            }
        }
        // Remove person from target server
        try {
            targetPersistenceEntryManager.removeRecursively(removedPerson.getDn());
            result1.add(inum);
        } catch (BasePersistenceException ex) {
            log.error("Failed to remove person entry with inum '{}' and DN: {}", inum, removedPerson.getDn(), ex);
            continue;
        }
        log.debug("Person with DN: '{}' removed from target server", removedPerson.getDn());
    }
    return new Pair<List<String>, List<String>>(result1, result2);
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) GluuInumMap(org.gluu.oxtrust.ldap.cache.model.GluuInumMap) BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) ArrayList(java.util.ArrayList) Date(java.util.Date) Pair(org.gluu.util.Pair)

Example 4 with GluuInumMap

use of org.gluu.oxtrust.ldap.cache.model.GluuInumMap in project oxTrust by GluuFederation.

the class CacheRefreshTimer method addNewInumServerEntries.

private HashMap<CacheCompoundKey, GluuInumMap> addNewInumServerEntries(CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection inumDbServerConnection, Map<CacheCompoundKey, GluuSimplePerson> sourcePersonCacheCompoundKeyMap, HashMap<CacheCompoundKey, GluuInumMap> primaryKeyAttrValueInumMap) {
    PersistenceEntryManager inumDbPersistenceEntryManager = inumDbServerConnection.getPersistenceEntryManager();
    String inumbaseDn = inumDbServerConnection.getBaseDns()[0];
    HashMap<CacheCompoundKey, GluuInumMap> result = new HashMap<CacheCompoundKey, GluuInumMap>();
    String[] keyAttributesWithoutValues = getCompoundKeyAttributesWithoutValues(cacheRefreshConfiguration);
    for (Entry<CacheCompoundKey, GluuSimplePerson> sourcePersonCacheCompoundKeyEntry : sourcePersonCacheCompoundKeyMap.entrySet()) {
        CacheCompoundKey cacheCompoundKey = sourcePersonCacheCompoundKeyEntry.getKey();
        GluuSimplePerson sourcePerson = sourcePersonCacheCompoundKeyEntry.getValue();
        if (log.isTraceEnabled()) {
            log.trace("Checking source entry with key: '{}', and DN: {}", cacheCompoundKey, sourcePerson.getDn());
        }
        GluuInumMap currentInumMap = primaryKeyAttrValueInumMap.get(cacheCompoundKey);
        if (currentInumMap == null) {
            String[][] keyAttributesValues = getKeyAttributesValues(keyAttributesWithoutValues, sourcePerson);
            currentInumMap = addGluuInumMap(inumbaseDn, inumDbPersistenceEntryManager, keyAttributesWithoutValues, keyAttributesValues);
            result.put(cacheCompoundKey, currentInumMap);
            log.debug("Added new inum entry for DN: {}", sourcePerson.getDn());
        } else {
            log.trace("Inum entry for DN: '{}' exist", sourcePerson.getDn());
        }
    }
    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) CacheCompoundKey(org.gluu.oxtrust.ldap.cache.model.CacheCompoundKey) HashMap(java.util.HashMap)

Example 5 with GluuInumMap

use of org.gluu.oxtrust.ldap.cache.model.GluuInumMap 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)

Aggregations

GluuInumMap (org.gluu.oxtrust.ldap.cache.model.GluuInumMap)8 GluuSimplePerson (org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson)4 PersistenceEntryManager (org.gluu.persist.PersistenceEntryManager)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 CacheCompoundKey (org.gluu.oxtrust.ldap.cache.model.CacheCompoundKey)2 BasePersistenceException (org.gluu.persist.exception.BasePersistenceException)2 SocketException (java.net.SocketException)1 EntryPersistenceException (org.gluu.persist.exception.EntryPersistenceException)1 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)1 SearchException (org.gluu.persist.exception.operation.SearchException)1 LdapEntryManager (org.gluu.persist.ldap.impl.LdapEntryManager)1 Pair (org.gluu.util.Pair)1 Pair (org.xdi.util.Pair)1