Search in sources :

Example 21 with IdCacheBlock

use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.

the class IdRemoteCachedServicesImpl method isExists.

// @Override
public boolean isExists(SSOToken token, IdType type, String name, String amOrgName) throws SSOException, IdRepoException {
    AMIdentity id = new AMIdentity(token, name, type, amOrgName, null);
    String dn = id.getUniversalId().toLowerCase();
    IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(dn);
    if (cb == null) {
        // Entry not present in cache
        if (DEBUG.messageEnabled()) {
            DEBUG.message("IdRemoteCachedServicesImpl." + "isExist(): NO entry found in Cachefor key = " + dn);
        }
        return super.isExists(token, type, name, amOrgName);
    }
    // Get the principal DN
    AMIdentity tokenId = IdUtils.getIdentity(token);
    String principalDN = tokenId.getUniversalId();
    if (cb.hasCache(principalDN)) {
        return true;
    } else {
        return super.isExists(token, type, name, amOrgName);
    }
}
Also used : AMIdentity(com.sun.identity.idm.AMIdentity) IdCacheBlock(com.sun.identity.idm.common.IdCacheBlock)

Example 22 with IdCacheBlock

use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.

the class IdRemoteCachedServicesImpl method removeCachedAttributes.

// *************************************************************************
// Update/Dirty methods of this class.
// *************************************************************************
private void removeCachedAttributes(String affectDNs, Set attrNames) {
    Enumeration cacheKeys = idRepoCache.keys();
    while (cacheKeys.hasMoreElements()) {
        String key = (String) cacheKeys.nextElement();
        int l1 = key.length();
        int l2 = affectDNs.length();
        if (key.regionMatches(true, (l1 - l2), affectDNs, 0, l2)) {
            // key ends with 'affectDN' string
            IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(key);
            if (cb != null) {
                // key ends with 'affectDN' string
                if ((attrNames != null) && !cb.hasExpiredAndUpdated() && cb.isExists()) {
                    cb.removeAttributes(attrNames);
                } else {
                    cb.clear();
                }
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) IdCacheBlock(com.sun.identity.idm.common.IdCacheBlock)

Example 23 with IdCacheBlock

use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.

the class IdRemoteCachedServicesImpl method getAttributes.

// @Override
public Map getAttributes(SSOToken token, IdType type, String name, String amOrgName, String amsdkDN) throws IdRepoException, SSOException {
    cacheStats.incrementGetRequestCount(getSize());
    if (SystemProperties.isServerMode() && MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
        long li = (long) getSize();
        monIdRepo.incGetRqts(li);
    }
    // Get identity DN
    AMIdentity id = new AMIdentity(token, name, type, amOrgName, amsdkDN);
    String dn = id.getUniversalId().toLowerCase();
    // Get the principal DN
    AMIdentity tokenId = IdUtils.getIdentity(token);
    String principalDN = tokenId.getUniversalId();
    IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(dn);
    AMHashMap attributes;
    if ((cb != null) && cb.hasCompleteSet(principalDN)) {
        cacheStats.updateGetHitCount(getSize());
        if (SystemProperties.isServerMode() && MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
            long li = (long) getSize();
            monIdRepo.incCacheHits(li);
        }
        if (DEBUG.messageEnabled()) {
            DEBUG.message("IdRemoteCachedServicesImpl." + "getAttributes(): found all attributes in " + "Cache.");
        }
        attributes = (AMHashMap) cb.getAttributes(principalDN, false);
    } else {
        // Get the whole set from DS and store it;
        if (DEBUG.messageEnabled()) {
            DEBUG.message("IdRemoteCachedServicesImpl." + "getAttributes(): complete attribute set NOT " + "found in cache. Getting from DS.");
        }
        attributes = (AMHashMap) super.getAttributes(token, type, name, amOrgName, amsdkDN);
        if (cb == null) {
            cb = new IdCacheBlock(dn, true);
            idRepoCache.put(dn, cb);
        }
        cb.putAttributes(principalDN, attributes, null, true, false);
        if (DEBUG.messageEnabled()) {
            DEBUG.message("IdRemoteCachedServicesImpl." + "getAttributes(): attributes NOT found in cache. " + "Fetched from DS.");
        }
    }
    return attributes;
}
Also used : AMHashMap(com.iplanet.am.sdk.AMHashMap) AMIdentity(com.sun.identity.idm.AMIdentity) IdCacheBlock(com.sun.identity.idm.common.IdCacheBlock)

Aggregations

IdCacheBlock (com.sun.identity.idm.common.IdCacheBlock)23 AMIdentity (com.sun.identity.idm.AMIdentity)13 AMHashMap (com.iplanet.am.sdk.AMHashMap)6 Set (java.util.Set)6 Enumeration (java.util.Enumeration)4 IdRepoException (com.sun.identity.idm.IdRepoException)2 IdSearchResults (com.sun.identity.idm.IdSearchResults)2 Map (java.util.Map)2