Search in sources :

Example 1 with CacheBlock

use of com.iplanet.am.sdk.common.CacheBlock in project OpenAM by OpenRock.

the class CachedRemoteServicesImpl method dirtyCache.

private void dirtyCache(Set entries) {
    Iterator itr = entries.iterator();
    while (itr.hasNext()) {
        String entryDN = (String) itr.next();
        String key = LDAPUtils.formatToRFC(entryDN);
        CacheBlock cb = (CacheBlock) sdkCache.get(key);
        if (cb != null) {
            cb.clear();
        }
    }
}
Also used : Iterator(java.util.Iterator) CacheBlock(com.iplanet.am.sdk.common.CacheBlock)

Example 2 with CacheBlock

use of com.iplanet.am.sdk.common.CacheBlock in project OpenAM by OpenRock.

the class CachedRemoteServicesImpl method clearCachedEntries.

private void clearCachedEntries(String affectDNs) {
    Enumeration cacheKeys = sdkCache.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
            CacheBlock cb = (CacheBlock) sdkCache.get(key);
            if (cb != null) {
                cb.clear();
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) CacheBlock(com.iplanet.am.sdk.common.CacheBlock)

Example 3 with CacheBlock

use of com.iplanet.am.sdk.common.CacheBlock in project OpenAM by OpenRock.

the class CachedRemoteServicesImpl method getObjectType.

/**
     * Gets the type of the object given its DN.
     * 
     * @param token
     *            token a valid SSOToken
     * @param dn
     *            DN of the object whose type is to be known.
     * 
     * @throws AMException
     *             if the data store is unavailable or if the objecttype is
     *             unknown
     * @throws SSOException
     *             if ssoToken is invalid or expired.
     */
public int getObjectType(SSOToken token, String dn) throws AMException, SSOException {
    int objectType = AMObject.UNDETERMINED_OBJECT_TYPE;
    String entryDN = LDAPUtils.formatToRFC(dn);
    CacheBlock cb = (CacheBlock) sdkCache.get(entryDN);
    if (cb != null) {
        // Check if the entry exists, if not present throw an exception
        if (!doesEntryExists(token, dn)) {
            String locale = MiscUtils.getUserLocale(token);
            String[] params = { cb.getEntryDN() };
            throw new AMException(AMSDKBundle.getString("461", params, locale), "461", params);
        }
        validateEntry(token, cb);
        objectType = cb.getObjectType();
        if (objectType != AMObject.UNDETERMINED_OBJECT_TYPE) {
            return objectType;
        }
    }
    // Use admintoken to get object type, so that it can be cached
    SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
    // The method below will throw an AMException if the entry does not
    // exist in the directory. If it exists, then create a cache entry for
    // this DN
    objectType = super.getObjectType(adminToken, entryDN);
    if (cb == null) {
        cb = new CacheBlock(entryDN, true);
        sdkCache.put(entryDN, cb);
    }
    cb.setObjectType(objectType);
    if (objectType == AMObject.ORGANIZATION || objectType == AMObject.ORGANIZATIONAL_UNIT) {
        cb.setOrganizationDN(entryDN);
    }
    return objectType;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) AMException(com.iplanet.am.sdk.AMException) CacheBlock(com.iplanet.am.sdk.common.CacheBlock)

Example 4 with CacheBlock

use of com.iplanet.am.sdk.common.CacheBlock in project OpenAM by OpenRock.

the class CachedRemoteServicesImpl method removeCachedAttributes.

// *************************************************************************
// Update/Dirty methods of this class.
// *************************************************************************
private void removeCachedAttributes(String affectDNs, Set attrNames) {
    Enumeration cacheKeys = sdkCache.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
            CacheBlock cb = (CacheBlock) sdkCache.get(key);
            if (cb != null && !cb.hasExpiredAndUpdated() && cb.isExists()) {
                cb.removeAttributes(attrNames);
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) CacheBlock(com.iplanet.am.sdk.common.CacheBlock)

Example 5 with CacheBlock

use of com.iplanet.am.sdk.common.CacheBlock in project OpenAM by OpenRock.

the class CachedRemoteServicesImpl method getOrganizationDN.

/**
     * Gets the Organization DN for the specified entryDN. If the entry itself
     * is an org, then same DN is returned.
     * <p>
     * <b>NOTE:</b> This method will involve serveral directory searches, hence
     * be cautious of Performance hit.
     * 
     * <p>
     * This method does not call its base classes method unlike the rest of the
     * overriden methods to obtain the organization DN, as it requires special
     * processing requirements.
     * 
     * @param token
     *            a valid SSOToken
     * @param entryDN
     *            the entry whose parent Organization is to be obtained
     * @return the DN String of the parent Organization
     * @throws AMException
     *             if an error occured while obtaining the parent Organization
     */
public String getOrganizationDN(SSOToken token, String entryDN) throws AMException {
    DN dnObject = DN.valueOf(entryDN);
    if (entryDN.length() == 0 || dnObject.size() <= 0) {
        getDebug().error("CachedRemoteServicesImpl.getOrganizationDN() " + "Invalid DN: " + entryDN);
        throw new AMException(token, "157");
    }
    String organizationDN = "";
    Set childDNSet = new HashSet();
    boolean errorCondition = false;
    boolean found = false;
    while (!errorCondition && !found) {
        boolean lookupDirectory = true;
        String childDN = dnObject.toString().toLowerCase();
        if (getDebug().messageEnabled()) {
            getDebug().message("CachedRemoteServicesImpl." + "getOrganizationDN() - looping Organization DN for" + " entry: " + childDN);
        }
        CacheBlock cb = (CacheBlock) sdkCache.get(childDN);
        if (cb != null) {
            organizationDN = cb.getOrganizationDN();
            if (organizationDN != null) {
                if (getDebug().messageEnabled()) {
                    getDebug().message("CachedRemoteServicesImpl." + "getOrganizationDN(): found OrganizationDN: " + organizationDN + " for: " + childDN);
                }
                found = true;
                setOrganizationDNs(organizationDN, childDNSet);
                continue;
            } else if (cb.getObjectType() == AMObject.ORGANIZATION || cb.getObjectType() == AMObject.ORGANIZATIONAL_UNIT) {
                // Object type is organization
                organizationDN = childDN;
                found = true;
                childDNSet.add(childDN);
                setOrganizationDNs(organizationDN, childDNSet);
                continue;
            } else if (cb.getObjectType() != AMObject.UNDETERMINED_OBJECT_TYPE) {
                // Don't lookup directory if the object type is unknown
                lookupDirectory = false;
            }
        }
        childDNSet.add(childDN);
        if (lookupDirectory) {
            organizationDN = super.verifyAndGetOrgDN(token, entryDN, childDN);
        }
        if (organizationDN != null && organizationDN.length() > 0) {
            found = true;
            setOrganizationDNs(organizationDN, childDNSet);
        } else if (dnObject.size() == 1) {
            // Reached topmost level
            errorCondition = true;
            getDebug().error("CachedRemoteServicesImpl." + "getOrganizationDN(): Reached root suffix. Unable to" + " get parent Org");
        } else {
            // Climb tree on level up
            dnObject = dnObject.parent();
        }
    }
    return organizationDN;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) AMException(com.iplanet.am.sdk.AMException) DN(org.forgerock.opendj.ldap.DN) CacheBlock(com.iplanet.am.sdk.common.CacheBlock) HashSet(java.util.HashSet)

Aggregations

CacheBlock (com.iplanet.am.sdk.common.CacheBlock)32 Enumeration (java.util.Enumeration)6 AMException (com.iplanet.am.sdk.AMException)5 AMHashMap (com.iplanet.am.sdk.AMHashMap)4 HashSet (java.util.HashSet)4 Iterator (java.util.Iterator)4 Set (java.util.Set)4 SSOToken (com.iplanet.sso.SSOToken)2 Map (java.util.Map)2 DN (org.forgerock.opendj.ldap.DN)2 AMObject (com.iplanet.am.sdk.AMObject)1