Search in sources :

Example 6 with AMHashMap

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

the class RemoteServicesImpl method getAttributes.

/**
     * Gets all 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 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, boolean ignoreCompliance, boolean byteValues, int profileType) throws AMException, SSOException {
    try {
        String tokenID = token.getTokenID().toString();
        Object[] objs = { tokenID, entryDN, Boolean.valueOf(ignoreCompliance), Boolean.valueOf(byteValues), new Integer(profileType) };
        Map map = (Map) client.send(client.encodeMessage("getAttributes3", objs), sessionCookies.getLBCookie(tokenID), null);
        AMHashMap res = new AMHashMap();
        res.copy(map);
        return res;
    } catch (AMRemoteException amrex) {
        if (getDebug().messageEnabled()) {
            getDebug().message("RemoteServicesImpl.getAttributes 3: 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.getAttributes3: 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 7 with AMHashMap

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

the class CachedRemoteServicesImpl method getPluginAttrsAndUpdateCache.

private AMHashMap getPluginAttrsAndUpdateCache(SSOToken token, String principalDN, String entryDN, CacheBlock cb, AMHashMap attributes, Set missAttrNames, boolean byteValues, int profileType) throws AMException {
    // Get all external attributes by calling plugin modules.
    // Note these attributes should not be cached.
    Map extAttributes = getExternalAttributes(token, entryDN, missAttrNames, profileType);
    if (extAttributes != null && !extAttributes.isEmpty()) {
        // Remove these external attributes from Cache
        Set extAttrNames = extAttributes.keySet();
        cb.removeAttributes(extAttrNames);
        if (getDebug().messageEnabled()) {
            getDebug().message("CachedRemoteServicesImpl." + "getPluginAttrsAndUpdateCache(): External " + "attributes present. Adding them with original" + " list. External Attributes: " + extAttrNames);
        }
        // Note the attributes stored in the cache are already copied
        // to a new map. Hence modifying this attributes is okay.
        attributes.putAll(extAttributes);
    }
    return attributes;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) AMHashMap(com.iplanet.am.sdk.AMHashMap) Map(java.util.Map)

Example 8 with AMHashMap

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

the class IdRepoUtils method getAttrMapWithoutPasswordAttrs.

/**
     * Returns an attribute map with all the password attributes being masked.
     * 
     * @param attrMap an attribute map
     * @param pwdAttrs a set of password attribute names
     *
     * @return an attribute map with all the password attributes being masked.
     */
public static Map<String, ?> getAttrMapWithoutPasswordAttrs(Map<String, ?> attrMap, Set<String> pwdAttrs) {
    if (attrMap == null || attrMap.isEmpty()) {
        return attrMap;
    }
    //the attrmap needs to be case-insensitive in order to detect password attributes correctly
    attrMap = new CaseInsensitiveHashMap(attrMap);
    Set<String> allPwdAttrs = new HashSet<String>(defaultPwdAttrs);
    if (pwdAttrs != null) {
        allPwdAttrs.addAll(pwdAttrs);
    }
    AMHashMap returnAttrMap = null;
    for (String pwdAttr : allPwdAttrs) {
        if (attrMap.containsKey(pwdAttr)) {
            if (returnAttrMap == null) {
                returnAttrMap = new AMHashMap();
                returnAttrMap.copy(attrMap);
            }
            returnAttrMap.put(pwdAttr, "xxx...");
        }
    }
    return (returnAttrMap == null ? attrMap : returnAttrMap);
}
Also used : AMHashMap(com.iplanet.am.sdk.AMHashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) HashSet(java.util.HashSet)

Example 9 with AMHashMap

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

the class IdServicesImpl method combineAttrMaps.

private Map combineAttrMaps(Set setOfMaps, boolean isString) {
    Map resultMap = new AMHashMap(!isString);
    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) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) AMHashMap(com.iplanet.am.sdk.AMHashMap) Iterator(java.util.Iterator) Map(java.util.Map) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet)

Example 10 with AMHashMap

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

the class IdRemoteCachedServicesImpl method getAttributes.

// @Override
public Map getAttributes(SSOToken token, IdType type, String name, Set attrNames, String amOrgName, String amsdkDN, boolean isStringValues) throws IdRepoException, SSOException {
    // Currently not needed as AMIdentity does not have getAllBinaryAttr..
    if ((attrNames == null) || attrNames.isEmpty()) {
        return (getAttributes(token, type, name, amOrgName, amsdkDN));
    }
    cacheStats.incrementGetRequestCount(getSize());
    if (SystemProperties.isServerMode() && MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
        long li = (long) getSize();
        monIdRepo.incGetRqts(li);
    }
    // Get the 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();
    if (DEBUG.messageEnabled()) {
        DEBUG.message("In IdRemoteCachedServicesImpl." + "getAttributes(SSOToken type, name, attrNames, " + "amOrgName, amsdkDN) (" + principalDN + ", " + dn + ", " + attrNames + " ," + amOrgName + " , " + amsdkDN + " method.");
    }
    // Attributes to be returned
    AMHashMap attributes;
    IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(dn);
    if (cb == null) {
        // Entry not present in cache
        if (DEBUG.messageEnabled()) {
            DEBUG.message("IdRemoteCachedServicesImpl." + "getAttributes(): NO entry found in Cachefor key = " + dn + ". 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.
        attributes = (AMHashMap) super.getAttributes(token, type, name, attrNames, amOrgName, amsdkDN, isStringValues);
        // 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 IdCacheBlock(dn, true);
        cb.putAttributes(principalDN, attributes, missAttrNames, false, !isStringValues);
        idRepoCache.put(dn, cb);
    } else {
        // Entry present in cache
        attributes = (AMHashMap) cb.getAttributes(principalDN, attrNames, !isStringValues);
        // 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()) {
            if (DEBUG.messageEnabled()) {
                DEBUG.message("IdRemoteCachedServicesImpl." + "getAttributes(): Trying to gett these missing " + "attributes from DS: " + missAttrNames);
            }
            AMHashMap dsAttributes = (AMHashMap) super.getAttributes(token, type, name, attrNames, amOrgName, amsdkDN, isStringValues);
            attributes.putAll(dsAttributes);
            // Add these attributes, just mark to hem as
            // invalid (Attribute level Negative caching)
            Set newMissAttrNames = dsAttributes.getMissingAndEmptyKeys(missAttrNames);
            cb.putAttributes(principalDN, dsAttributes, newMissAttrNames, false, !isStringValues);
        } else {
            // All attributes found in cache
            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.");
            }
        }
    }
    return attributes;
}
Also used : Set(java.util.Set) AMHashMap(com.iplanet.am.sdk.AMHashMap) AMIdentity(com.sun.identity.idm.AMIdentity) IdCacheBlock(com.sun.identity.idm.common.IdCacheBlock)

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