Search in sources :

Example 16 with AMHashMap

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

the class CachedRemoteServicesImpl method getAttributes.

/**
     * Gets the specific attributes corresponding to the entryDN. This method
     * obtains the DC Tree node attributes and also performs compliance related
     * verification checks in compliance mode. Note: In compliance mode you can
     * skip the compliance checks by setting ignoreCompliance to "false".
     * 
     * @param token
     *            a valid SSOToken
     * @param entryDN
     *            the DN of the entry whose attributes need to retrieved
     * @param attrNames
     *            a Set of names of the attributes that need to be retrieved.
     *            The attrNames should not be null
     * @param ignoreCompliance
     *            a boolean value specificying if compliance related entries
     *            need to ignored or not. Ignored if true.
     * @return a Map containing attribute names as keys and Set of values
     *         corresponding to each key.
     * @throws AMException
     *             if an error is encountered in fetching the attributes
     */
public Map getAttributes(SSOToken token, String entryDN, Set attrNames, boolean ignoreCompliance, boolean byteValues, int profileType) throws AMException, SSOException {
    if (attrNames == null || attrNames.isEmpty()) {
        return getAttributes(token, entryDN, ignoreCompliance, byteValues, profileType);
    }
    // Attributes are being requested; increment cache stats request counter
    cacheStats.incrementRequestCount(getSize());
    // Not good for performance, but fix later TODO (Deepa)
    if (dcTreeServicesImpl.isRequired()) {
        // TODO: This needs to be fixed!
        getAttributes(token, entryDN, ignoreCompliance, byteValues, profileType);
    }
    String principalDN = MiscUtils.getPrincipalDN(token);
    if (getDebug().messageEnabled()) {
        getDebug().message("In CachedRemoteServicesImpl.getAttributes(" + "SSOToken entryDN, attrNames, ignoreCompliance, " + "byteValues) " + "(" + principalDN + ", " + entryDN + ", " + attrNames + ", " + ignoreCompliance + ", " + byteValues + " method.");
    }
    String dn = LDAPUtils.formatToRFC(entryDN);
    CacheBlock cb = (CacheBlock) sdkCache.get(dn);
    if (cb == null) {
        // Entry not present in cache
        if (getDebug().messageEnabled()) {
            getDebug().message("CachedRemoteServicesImpl." + "getAttributes():  NO entry found in Cache. Getting" + " all these attributes from DS: " + attrNames);
        }
        // If the attributes returned here have an empty set as value, then
        // such attributes do not have a value or invalid attributes.
        // Internally keep track of these attributes.
        AMHashMap attributes = (AMHashMap) super.getAttributes(token, entryDN, attrNames, ignoreCompliance, byteValues, profileType);
        // These attributes are either not present or not found in DS.
        // Try to check if they need to be fetched by external
        // plugins
        Set missAttrNames = attributes.getMissingAndEmptyKeys(attrNames);
        cb = new CacheBlock(dn, true);
        cb.putAttributes(principalDN, attributes, missAttrNames, false, byteValues);
        sdkCache.put(dn, cb);
        if (!missAttrNames.isEmpty()) {
            attributes = getPluginAttrsAndUpdateCache(token, principalDN, entryDN, cb, attributes, missAttrNames, byteValues, profileType);
        }
        return attributes;
    } else {
        // Entry present in cache
        // Entry may be an invalid entry
        validateEntry(token, cb);
        AMHashMap attributes = (AMHashMap) cb.getAttributes(principalDN, attrNames, byteValues);
        // Find the missing attributes that need to be obtained from DS
        // Only find the missing keys as the ones with empty sets are not
        // found in DS
        Set missAttrNames = attributes.getMissingKeys(attrNames);
        if (!missAttrNames.isEmpty()) {
            boolean isComplete = cb.hasCompleteSet(principalDN);
            AMHashMap dsAttributes = null;
            if (!isComplete || // Check for "nsRole" and "nsRoleDN" attributes
            missAttrNames.contains(NSROLEDN_ATTR) || missAttrNames.contains(NSROLE_ATTR)) {
                if (getDebug().messageEnabled()) {
                    getDebug().message("CachedRemoteServicesImpl." + "getAttributes(): Trying to get these missing" + " attributes from DS: " + missAttrNames);
                }
                dsAttributes = (AMHashMap) super.getAttributes(token, entryDN, missAttrNames, ignoreCompliance, byteValues, profileType);
                if (dsAttributes != null) {
                    attributes.putAll(dsAttributes);
                    // Add these attributes, may be found in DS or just mark
                    // as invalid (Attribute level Negative caching)
                    Set newMissAttrNames = dsAttributes.getMissingAndEmptyKeys(missAttrNames);
                    // Update dsAttributes with rest of the attributes
                    // in cache
                    dsAttributes.putAll(cb.getAttributes(principalDN, byteValues));
                    // Update the cache
                    cb.putAttributes(principalDN, dsAttributes, newMissAttrNames, isComplete, byteValues);
                    missAttrNames = newMissAttrNames;
                }
            } else {
                // Update cache with invalid attributes
                cb.putAttributes(principalDN, cb.getAttributes(principalDN, byteValues), missAttrNames, isComplete, byteValues);
            }
            if (!missAttrNames.isEmpty()) {
                attributes = getPluginAttrsAndUpdateCache(token, principalDN, entryDN, cb, attributes, missAttrNames, byteValues, profileType);
            }
        } else {
            // All attributes found in cache
            if (getDebug().messageEnabled()) {
                getDebug().message("CachedRemoteServicesImpl." + "getAttributes():  found all attributes in " + "Cache.");
            }
            cacheStats.updateHitCount(getSize());
        }
        // Remove all the empty values from the return attributes
        return attributes;
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) AMHashMap(com.iplanet.am.sdk.AMHashMap) CacheBlock(com.iplanet.am.sdk.common.CacheBlock)

Example 17 with AMHashMap

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

the class RemoteServicesImpl method getAttributes.

public Map getAttributes(SSOToken token, String entryDN, int profileType) throws AMException, SSOException {
    try {
        String tokenID = token.getTokenID().toString();
        Object[] objs = { tokenID, entryDN, new Integer(profileType) };
        Map map = (Map) client.send(client.encodeMessage("getAttributes1", objs), sessionCookies.getLBCookie(tokenID), null);
        AMHashMap res = new AMHashMap();
        res.copy(map);
        return res;
    } catch (AMRemoteException amrex) {
        if (getDebug().messageEnabled()) {
            getDebug().message("RemoteServicesImpl.getAttributes: entryDN=" + entryDN + ";  AMRemoteException caught exception=", amrex);
        }
        throw convertException(amrex);
    } catch (RemoteException rex) {
        getDebug().error("RemoteServicesImpl.getAttributes: caught exception=", rex);
        throw new AMException(AMSDKBundle.getString("1000"), "1000");
    } catch (SSOException ssoe) {
        getDebug().error("RemoteServicesImpl.getAttributes: caught SSOException=", ssoe);
        throw ssoe;
    } catch (Exception ex) {
        if (getDebug().messageEnabled()) {
            getDebug().message("RemoteServicesImpl.getAttributes: entryDN=" + entryDN + ";  caught exception=", ex);
        }
        throw new AMException(AMSDKBundle.getString("1000"), "1000");
    }
}
Also used : AMHashMap(com.iplanet.am.sdk.AMHashMap) AMException(com.iplanet.am.sdk.AMException) SSOException(com.iplanet.sso.SSOException) RemoteException(java.rmi.RemoteException) AMHashMap(com.iplanet.am.sdk.AMHashMap) Map(java.util.Map) AMEntryExistsException(com.iplanet.am.sdk.AMEntryExistsException) AMEventManagerException(com.iplanet.am.sdk.AMEventManagerException) RemoteException(java.rmi.RemoteException) AMException(com.iplanet.am.sdk.AMException) SSOException(com.iplanet.sso.SSOException)

Example 18 with AMHashMap

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

the class RemoteServicesImpl method getAttributes.

/**
     * Gets the specific attributes corresponding to the entryDN. This method
     * obtains the DC Tree node attributes and also performs compliance related
     * verification checks in compliance mode. Note: In compliance mode you can
     * skip the compliance checks by setting ignoreCompliance to "false".
     * 
     * @param token
     *            a valid SSOToken
     * @param entryDN
     *            the DN of the entry whose attributes need to retrieved
     * @param attrNames
     *            a Set of names of the attributes that need to be retrieved.
     *            The attrNames should not be null.
     * @param ignoreCompliance
     *            a boolean value specificying if compliance related entries
     *            need to ignored or not. Ignored if true.
     * @return a Map containing attribute names as keys and Set of values
     *         corresponding to each key.
     * @throws AMException
     *             if an error is encountered in fetching the attributes
     */
public Map getAttributes(SSOToken token, String entryDN, Set attrNames, boolean ignoreCompliance, boolean byteValues, int profileType) throws AMException, SSOException {
    try {
        String tokenID = token.getTokenID().toString();
        Object[] objs = { tokenID, entryDN, attrNames, Boolean.valueOf(ignoreCompliance), Boolean.valueOf(byteValues), new Integer(profileType) };
        Map map = (Map) client.send(client.encodeMessage("getAttributes4", objs), sessionCookies.getLBCookie(tokenID), null);
        AMHashMap res = new AMHashMap();
        res.copy(map);
        return res;
    } catch (AMRemoteException amrex) {
        if (getDebug().messageEnabled()) {
            getDebug().message("RemoteServicesImpl.getAttributes 4: entryDN=" + entryDN + ";  AMRemoteException caught exception=", amrex);
        }
        throw convertException(amrex);
    } catch (RemoteException rex) {
        getDebug().error("RemoteServicesImpl.getAttributes: caught exception=", rex);
        throw new AMException(AMSDKBundle.getString("1000"), "1000");
    } catch (SSOException ssoe) {
        getDebug().error("RemoteServicesImpl.getAttributes: caught SSOException=", ssoe);
        throw ssoe;
    } catch (Exception ex) {
        if (getDebug().messageEnabled()) {
            getDebug().message("RemoteServicesImpl.getAttributes4: entryDN=" + entryDN + ";  caught exception=", ex);
        }
        throw new AMException(AMSDKBundle.getString("1000"), "1000");
    }
}
Also used : AMHashMap(com.iplanet.am.sdk.AMHashMap) AMException(com.iplanet.am.sdk.AMException) SSOException(com.iplanet.sso.SSOException) RemoteException(java.rmi.RemoteException) AMHashMap(com.iplanet.am.sdk.AMHashMap) Map(java.util.Map) AMEntryExistsException(com.iplanet.am.sdk.AMEntryExistsException) AMEventManagerException(com.iplanet.am.sdk.AMEventManagerException) RemoteException(java.rmi.RemoteException) AMException(com.iplanet.am.sdk.AMException) SSOException(com.iplanet.sso.SSOException)

Example 19 with AMHashMap

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

the class AMIdentityRepository method combineAttrMaps.

private Map combineAttrMaps(Set setOfMaps, boolean isString) {
    // Map resultMap = new CaseInsensitiveHashMap();
    Map resultMap = new AMHashMap();
    Iterator it = setOfMaps.iterator();
    while (it.hasNext()) {
        Map currMap = (Map) it.next();
        if (currMap != null) {
            Iterator keyset = currMap.keySet().iterator();
            while (keyset.hasNext()) {
                String thisAttr = (String) keyset.next();
                if (isString) {
                    Set resultSet = (Set) resultMap.get(thisAttr);
                    Set thisSet = (Set) currMap.get(thisAttr);
                    if (resultSet != null) {
                        resultSet.addAll(thisSet);
                    } else {
                        /*
                             * create a new Set so that we do not alter the set
                             * that is referenced in setOfMaps
                             */
                        resultSet = new HashSet((Set) currMap.get(thisAttr));
                        resultMap.put(thisAttr, resultSet);
                    }
                } else {
                    // binary attributes
                    byte[][] resultSet = (byte[][]) resultMap.get(thisAttr);
                    byte[][] thisSet = (byte[][]) currMap.get(thisAttr);
                    int combinedSize = thisSet.length;
                    if (resultSet != null) {
                        combinedSize = resultSet.length + thisSet.length;
                        byte[][] tmpSet = new byte[combinedSize][];
                        for (int i = 0; i < resultSet.length; i++) {
                            tmpSet[i] = (byte[]) resultSet[i];
                        }
                        for (int i = 0; i < thisSet.length; i++) {
                            tmpSet[i] = (byte[]) thisSet[i];
                        }
                        resultSet = tmpSet;
                    } else {
                        resultSet = (byte[][]) thisSet.clone();
                    }
                    resultMap.put(thisAttr, resultSet);
                }
            }
        }
    }
    return resultMap;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) AMHashMap(com.iplanet.am.sdk.AMHashMap) Iterator(java.util.Iterator) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 20 with AMHashMap

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

the class CommonUtils method attrSetToMap.

/**
     * Method to convert a AttrSet object to Map.
     * 
     * @param attrSet
     *            the AttrSet to be converted to a Map
     * @param fetchByteValues
     *            if false stringValues are added, if true byteValues are added.
     * @return a Map containing attribute names as key's and a Set of attribute
     *         values or byte Values
     */
protected static Map attrSetToMap(AttrSet attrSet, boolean fetchByteValues) {
    Map attributesMap = new AMHashMap(fetchByteValues);
    if (attrSet == null) {
        return attributesMap;
    }
    int attrSetSize = attrSet.size();
    if (!fetchByteValues) {
        for (int i = 0; i < attrSetSize; i++) {
            Attr attr = attrSet.elementAt(i);
            String[] values = attr.getStringValues();
            attributesMap.put(attr.getName(), stringArrayToSet(values));
        }
    } else {
        for (int i = 0; i < attrSetSize; i++) {
            Attr attr = attrSet.elementAt(i);
            attributesMap.put(attr.getName(), attr.getByteValues());
        }
    }
    return attributesMap;
}
Also used : AMHashMap(com.iplanet.am.sdk.AMHashMap) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) Map(java.util.Map) Attr(com.iplanet.services.ldap.Attr)

Aggregations

AMHashMap (com.iplanet.am.sdk.AMHashMap)26 Map (java.util.Map)16 Set (java.util.Set)10 HashSet (java.util.HashSet)9 AMException (com.iplanet.am.sdk.AMException)6 SSOException (com.iplanet.sso.SSOException)6 HashMap (java.util.HashMap)6 RemoteException (java.rmi.RemoteException)5 Iterator (java.util.Iterator)5 AMEntryExistsException (com.iplanet.am.sdk.AMEntryExistsException)4 AMEventManagerException (com.iplanet.am.sdk.AMEventManagerException)4 CacheBlock (com.iplanet.am.sdk.common.CacheBlock)4 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)4 AMIdentity (com.sun.identity.idm.AMIdentity)4 IdCacheBlock (com.sun.identity.idm.common.IdCacheBlock)4 Attr (com.iplanet.services.ldap.Attr)3 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)3 IdRepoException (com.sun.identity.idm.IdRepoException)3 AttrSet (com.iplanet.services.ldap.AttrSet)2 Guid (com.iplanet.ums.Guid)2