Search in sources :

Example 16 with CaseInsensitiveHashMap

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

the class AMIdentity method getAttributes.

/**
     * Returns requested attributes and values of this object.
     *
     * This method is only valid for AMIdentity object of type User, Agent,
     * Group, and Role.
     *
     * @param attrNames
     *            Set of attribute names to be read
     * @return Map of attribute-values.
     * @throws IdRepoException
     *             If there are repository related error conditions.
     * @throws SSOException
     *             If user's single sign on token is invalid.
     * @supported.api
     */
public Map getAttributes(Set attrNames) throws IdRepoException, SSOException {
    IdServices idServices = IdServicesFactory.getDataStoreServices();
    Map attrs = idServices.getAttributes(token, type, name, attrNames, orgName, univDN, true);
    CaseInsensitiveHashMap caseAttrs = new CaseInsensitiveHashMap(attrs);
    CaseInsensitiveHashMap resultMap = new CaseInsensitiveHashMap();
    Iterator it = attrNames.iterator();
    while (it.hasNext()) {
        String attrName = (String) it.next();
        if (caseAttrs.containsKey(attrName)) {
            resultMap.put(attrName, caseAttrs.get(attrName));
        }
    }
    if (debug.messageEnabled()) {
        debug.message("AMIdentity.getAttributes 6: attrNames=" + attrNames + ";  resultMap=" + resultMap + "; attrs=" + attrs);
    }
    return resultMap;
}
Also used : Iterator(java.util.Iterator) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

Example 17 with CaseInsensitiveHashMap

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

the class DatabaseRepo method getAttributes.

/*
     * Returns just --requested-- attributes and values of name object.
     * Allows user to provide a set of attributes that should be returned,
     * and this set of attributes to retrieve is provided in parameter
     * Set attrNames.
     *
     * @see com.sun.identity.idm.IdRepo#getAttributes(com.iplanet.sso.SSOToken,
     *      com.sun.identity.idm.IdType, java.lang.String, java.util.Set)
     */
public Map getAttributes(SSOToken token, IdType type, String name, Set attrNames) throws IdRepoException, SSOException {
    if (initializationException != null) {
        debug.error("DatabaseRepo.getAttributes: throwing initialization exception");
        throw (initializationException);
    }
    if (debug.messageEnabled()) {
        debug.message("DatabaseRepo.getAttributes called with: " + " token=" + token + " type=" + type + " name=" + name + "\n\treturn attributes=" + attrNames);
    }
    //throw exception if this type user not allowed to do this
    isValidType(type, "getAttributes");
    // Get all the attributes and return the subset
    //Map answer = (attrNames == null) ? null : new HashMap();
    Map answer = (attrNames == null) ? null : new CaseInsensitiveHashMap();
    //get all attributes and their corresponding values Sets
    Map map = getAttributes(token, type, name);
    if (attrNames == null) {
        answer = map;
    } else {
        //paramater Set attrNames,
        for (Iterator items = attrNames.iterator(); items.hasNext(); ) {
            Object key = items.next();
            Object value = map.get(key);
            if (value != null) {
                answer.put(key, value);
            }
        }
    }
    return (answer);
}
Also used : Iterator(java.util.Iterator) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

Example 18 with CaseInsensitiveHashMap

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

the class DatabaseRepo method getAttributes.

/*
     * Returns --all-- attributes and values of name object
     * so whole row of DB table for this user for example
     *
     * I think it makes a map where map contains the attribute/column name as
     * a String key and a Set as the value where Set can be the String values
     * for that attribute.  Does the case matter????
     * Should the values to a CaseSenstiveHashMap ???? or all lowercase?
     * should keys be lowercase ???
     * What should I put in the case of when an attribute has no values???
     *
     * @see com.sun.identity.idm.IdRepo#getAttributes(com.iplanet.sso.SSOToken,
     *      com.sun.identity.idm.IdType, java.lang.String)
     */
public Map getAttributes(SSOToken token, IdType type, String name) throws IdRepoException, SSOException {
    if (initializationException != null) {
        debug.error("DatabaseRepo.getAttributes: throwing" + " initialization exception");
        throw (initializationException);
    }
    if (debug.messageEnabled()) {
        debug.message("DatabaseRepo.getAttributes: get all attrs called: " + " token=" + token + " type=" + type.getName() + " name=" + name);
    }
    //throw exception if this type user not allowed to do this
    isValidType(type, "getAttributes");
    Map users = Collections.EMPTY_MAP;
    if (type.equals(IdType.USER)) {
        users = dao.getAttributes(name, userIDAttributeName, userAtttributesAllowed);
    } else if (type.equals(IdType.GROUP)) {
        //RFE: consider making the groups allowed to be fetched set a
        //config option in UI  as with userAtttributesAllowed
        Set<String> groupAttrsAllowed = new HashSet<String>();
        groupAttrsAllowed.add(membershipIdAttributeName);
        users = dao.getGroupAttributes(name, membershipIdAttributeName, groupAttrsAllowed);
    }
    //not sure this is how case insensitive map works???
    //are keys insensitive or set of values or ????
    Map answer = new CaseInsensitiveHashMap(users);
    return answer;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

Example 19 with CaseInsensitiveHashMap

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

the class AMIdentityRepository method combineSearchResults.

private IdSearchResults combineSearchResults(SSOToken token, Object[][] arrayOfResult, int sizeOfArray, IdType type, String orgName, boolean amsdkIncluded, Object[][] amsdkResults) {
    Map amsdkDNs = new CaseInsensitiveHashMap();
    Map resultsMap = new CaseInsensitiveHashMap();
    int errorCode = IdSearchResults.SUCCESS;
    if (amsdkIncluded) {
        RepoSearchResults amsdkRepoRes = (RepoSearchResults) amsdkResults[0][0];
        Set results = amsdkRepoRes.getSearchResults();
        Map attrResults = amsdkRepoRes.getResultAttributes();
        for (String dn : (Set<String>) results) {
            String name = LDAPUtils.rdnValueFromDn(dn);
            amsdkDNs.put(name, dn);
            Set attrMaps = new HashSet();
            attrMaps.add((Map) attrResults.get(dn));
            resultsMap.put(name, attrMaps);
        }
        errorCode = amsdkRepoRes.getErrorCode();
    }
    for (int i = 0; i < sizeOfArray; i++) {
        RepoSearchResults current = (RepoSearchResults) arrayOfResult[i][0];
        Map configMap = (Map) arrayOfResult[i][1];
        Map allAttrMaps = current.getResultAttributes();
        for (String m : (Set<String>) current.getSearchResults()) {
            String mname = DNUtils.DNtoName(m);
            Map attrMap = (Map) allAttrMaps.get(m);
            attrMap = reverseMapAttributeNames(attrMap, configMap);
            Set attrMaps = (Set) resultsMap.get(mname);
            if (attrMaps == null) {
                attrMaps = new HashSet();
            }
            attrMaps.add(attrMap);
            resultsMap.put(mname, attrMaps);
        }
    }
    IdSearchResults results = new IdSearchResults(type, orgName);
    for (String mname : (Set<String>) resultsMap.keySet()) {
        Map combinedMap = combineAttrMaps((Set) resultsMap.get(mname), true);
        AMIdentity id = new AMIdentity(token, mname, type, orgName, (String) amsdkDNs.get(mname));
        results.addResult(id, combinedMap);
    }
    results.setErrorCode(errorCode);
    return results;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) HashSet(java.util.HashSet)

Example 20 with CaseInsensitiveHashMap

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

the class DJLDAPv3Repo method isActive.

/**
     * Tells whether the given identity is considered as "active" or not. In case the user status attribute is not
     * configured, this method will always return <code>true</code>. In case of Active Directory the returned
     * userAccountControl attribute will be masked with 0x2 to detect whether the given account is disabled or not.
     *
     * @param token Not used.
     * @param type The type of the identity, this should be always USER.
     * @param name The name of the identity.
     * @return <code>true</code> if user status attribute is not configured, or decision based on the status
     * attribute value. If there was any error while retrieving the status attribute this method will return
     * <code>false</code>.
     * @throws IdRepoException If the identity type is invalid.
     */
@Override
public boolean isActive(SSOToken token, IdType type, String name) throws IdRepoException {
    if (DEBUG.messageEnabled()) {
        DEBUG.message("isActive invoked");
    }
    if (!type.equals(IdType.USER)) {
        throw new IdRepoUnsupportedOpException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.PLUGIN_OPERATION_NOT_SUPPORTED, new Object[] { CLASS_NAME, IdOperation.READ.getName(), type.getName() });
    }
    if (alwaysActive) {
        try {
            return isExists(token, type, name);
        } catch (IdRepoException ide) {
            return false;
        }
    }
    Map<String, Set<String>> attrMap;
    try {
        attrMap = getAttributes(token, type, name, asSet(userStatusAttr));
        attrMap = new CaseInsensitiveHashMap(attrMap);
    } catch (IdRepoException ire) {
        return false;
    }
    String status = CollectionHelper.getMapAttr(attrMap, userStatusAttr);
    if (status != null) {
        return helper.isActive(status, inactiveValue);
    } else {
        return true;
    }
}
Also used : IdRepoUnsupportedOpException(com.sun.identity.idm.IdRepoUnsupportedOpException) Set(java.util.Set) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) CollectionUtils.asSet(org.forgerock.openam.utils.CollectionUtils.asSet) IdRepoException(com.sun.identity.idm.IdRepoException) ByteString(org.forgerock.opendj.ldap.ByteString) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

Aggregations

CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)52 HashMap (java.util.HashMap)40 Map (java.util.Map)38 Set (java.util.Set)35 HashSet (java.util.HashSet)34 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)23 Iterator (java.util.Iterator)22 AMHashMap (com.iplanet.am.sdk.AMHashMap)13 CollectionUtils.asSet (org.forgerock.openam.utils.CollectionUtils.asSet)8 LinkedHashSet (java.util.LinkedHashSet)6 SSOException (com.iplanet.sso.SSOException)5 AMIdentity (com.sun.identity.idm.AMIdentity)5 IdRepoUnsupportedOpException (com.sun.identity.idm.IdRepoUnsupportedOpException)5 OrderedSet (com.sun.identity.shared.datastruct.OrderedSet)5 IdRepoException (com.sun.identity.idm.IdRepoException)4 ByteString (org.forgerock.opendj.ldap.ByteString)4 SMSException (com.sun.identity.sm.SMSException)3 File (java.io.File)3 CollectionUtils.asOrderedSet (org.forgerock.openam.utils.CollectionUtils.asOrderedSet)3 Test (org.testng.annotations.Test)3