Search in sources :

Example 1 with CaseInsensitiveHashMap

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

the class AMIdentityRepository method reverseMapAttributeNames.

// TODO:
// FIXME: Move these utilities to a util class
private Map reverseMapAttributeNames(Map attrMap, Map configMap) {
    if (attrMap == null || attrMap.isEmpty()) {
        return attrMap;
    }
    Map resultMap;
    Map[] mapArray = getAttributeNameMap(configMap);
    if (mapArray == null) {
        resultMap = attrMap;
    } else {
        resultMap = new CaseInsensitiveHashMap();
        Map reverseMap = mapArray[1];
        Iterator it = attrMap.keySet().iterator();
        while (it.hasNext()) {
            String curr = (String) it.next();
            if (reverseMap.containsKey(curr)) {
                resultMap.put((String) reverseMap.get(curr), (Set) attrMap.get(curr));
            } else {
                resultMap.put(curr, (Set) attrMap.get(curr));
            }
        }
    }
    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 2 with CaseInsensitiveHashMap

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

the class AMIdentity method modifyService.

/**
     * Set attributes related to a specific service. The assumption is that the
     * service is already assigned to the identity. The attributes for the
     * service are validated against the service schema.
     *
     * This method is only valid for AMIdentity object of type User.
     *
     * @param serviceName
     *            Name of the service.
     * @param attrMap
     *            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 void modifyService(String serviceName, Map attrMap) throws IdRepoException, SSOException {
    IdServices idServices = IdServicesFactory.getDataStoreServices();
    Set OCs = getServiceOCs(token, serviceName);
    SchemaType stype;
    Map tMap = new HashMap();
    tMap.put(serviceName, OCs);
    Set assignedServices = idServices.getAssignedServices(token, type, name, tMap, orgName, univDN);
    if (!assignedServices.contains(serviceName)) {
        Object[] args = { serviceName };
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SERVICE_NOT_ASSIGNED, args);
    }
    // Check if attrMap has cos priority attribute
    // If present, remove it for validating the attributes
    boolean hasCosPriority = (new CaseInsensitiveHashSet(attrMap.keySet()).contains(COS_PRIORITY));
    Object values = null;
    if (hasCosPriority) {
        attrMap = new CaseInsensitiveHashMap(attrMap);
        values = attrMap.remove(COS_PRIORITY);
    }
    // Validate the attributes
    try {
        ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
        ServiceSchema ss = ssm.getSchema(type.getName());
        if (ss != null) {
            attrMap = ss.validateAndInheritDefaults(attrMap, false);
            stype = ss.getServiceType();
        } else if ((ss = ssm.getSchema(SchemaType.DYNAMIC)) != null) {
            attrMap = ss.validateAndInheritDefaults(attrMap, false);
            stype = SchemaType.DYNAMIC;
        } else {
            Object[] args = { serviceName };
            throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_GET_SERVICE_SCHEMA, args);
        }
    } catch (SMSException smse) {
        // debug.error
        Object[] args = { serviceName };
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.DATA_INVALID_FOR_SERVICE, args);
    }
    // Add COS priority if present
    if (hasCosPriority) {
        attrMap.put(COS_PRIORITY, values);
    }
    // modify service attrs
    if (debug.messageEnabled()) {
        debug.message("AMIdentity.modifyService befre idService " + "serviceName=" + serviceName + ";  attrMap=" + attrMap);
    }
    idServices.modifyService(token, type, name, serviceName, stype, attrMap, orgName, univDN);
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) Set(java.util.Set) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) SMSException(com.sun.identity.sm.SMSException) SchemaType(com.sun.identity.sm.SchemaType) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) ServiceSchema(com.sun.identity.sm.ServiceSchema) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

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

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