Search in sources :

Example 1 with AMHashMap

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

the class OpenAMScopeValidator method getUpdatedAt.

private String getUpdatedAt(String username, String realm, OAuth2Request request) throws NotFoundException {
    try {
        final OAuth2ProviderSettings providerSettings = providerSettingsFactory.get(request);
        String modifyTimestampAttributeName;
        String createdTimestampAttributeName;
        try {
            modifyTimestampAttributeName = providerSettings.getModifiedTimestampAttributeName();
            createdTimestampAttributeName = providerSettings.getCreatedTimestampAttributeName();
        } catch (ServerException e) {
            logger.error("Unable to read last modified attribute from datastore", e);
            return DEFAULT_TIMESTAMP;
        }
        if (modifyTimestampAttributeName == null && createdTimestampAttributeName == null) {
            return null;
        }
        final AMHashMap timestamps = getTimestamps(username, realm, modifyTimestampAttributeName, createdTimestampAttributeName);
        final String modifyTimestamp = CollectionHelper.getMapAttr(timestamps, modifyTimestampAttributeName);
        if (modifyTimestamp != null) {
            synchronized (TIMESTAMP_DATE_FORMAT) {
                return Long.toString(TIMESTAMP_DATE_FORMAT.parse(modifyTimestamp).getTime() / 1000);
            }
        } else {
            final String createTimestamp = CollectionHelper.getMapAttr(timestamps, createdTimestampAttributeName);
            if (createTimestamp != null) {
                synchronized (TIMESTAMP_DATE_FORMAT) {
                    return Long.toString(TIMESTAMP_DATE_FORMAT.parse(createTimestamp).getTime() / 1000);
                }
            } else {
                return DEFAULT_TIMESTAMP;
            }
        }
    } catch (IdRepoException e) {
        if (logger.errorEnabled()) {
            logger.error("ScopeValidatorImpl" + ".getUpdatedAt: " + "error searching Identities with username : " + username, e);
        }
    } catch (SSOException e) {
        logger.warning("Error getting updatedAt attribute", e);
    } catch (ParseException e) {
        logger.warning("Error getting updatedAt attribute", e);
    }
    return null;
}
Also used : ServerException(org.forgerock.oauth2.core.exceptions.ServerException) AMHashMap(com.iplanet.am.sdk.AMHashMap) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) OAuth2ProviderSettings(org.forgerock.oauth2.core.OAuth2ProviderSettings) ParseException(java.text.ParseException)

Example 2 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 3 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 4 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)

Example 5 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)

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