Search in sources :

Example 11 with CaseInsensitiveHashMap

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

the class FilesRepo method create.

/*
     * (non-Javadoc)
     *
     * @see com.sun.identity.idm.IdRepo#create(com.iplanet.sso.SSOToken,
     *      com.sun.identity.idm.IdType, java.lang.String, java.util.Map)
     */
public String create(SSOToken token, IdType type, String name, Map attrMap) throws IdRepoException, SSOException {
    if (initializationException != null) {
        debug.error("FilesRepo: throwing initialization exception");
        throw (initializationException);
    }
    if (supportedOps.keySet().contains(type)) {
        // Check if identity exists
        File file = constructFile(directory, type, name);
        if (!file.exists()) {
            // If type is user, add the configured object classes
            CaseInsensitiveHashMap nAttrs = new CaseInsensitiveHashMap(attrMap);
            Set ocs = (Set) nAttrs.get(OC);
            if (ocs == null) {
                nAttrs.put(OC, userOCs);
            } else {
                CaseInsensitiveHashSet ocv = new CaseInsensitiveHashSet(ocs);
                ocv.addAll(userOCs);
            }
            // Create the identity
            attrMap = processAttributes(nAttrs, hashAttributes, encryptAttributes);
            writeFile(file, attrMap);
            // %%% Send notification (must be via a different thread)
            if (repoListener != null) {
                repoListener.objectChanged(name, type, AMEvent.OBJECT_ADDED, repoListener.getConfigMap());
            }
        } else {
            // throw exception
            throw IdRepoDuplicateObjectException.nameAlreadyExists(file.getAbsolutePath());
        }
    } else {
        Object[] args = { NAME, IdOperation.SERVICE.getName(), type.getName() };
        throw new IdRepoUnsupportedOpException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.PLUGIN_OPERATION_NOT_SUPPORTED, args);
    }
    return (name);
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) IdRepoUnsupportedOpException(com.sun.identity.idm.IdRepoUnsupportedOpException) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) Set(java.util.Set) File(java.io.File) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

Example 12 with CaseInsensitiveHashMap

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

the class AgentsRepo method getAttributes.

/*
     * (non-Javadoc)
     *
     * @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 (debug.messageEnabled()) {
        debug.message("AgentsRepo.getAttributes() with attrNames called: " + type + ": " + name);
    }
    if (initializationException != null) {
        debug.error("AgentsRepo.getAttributes: " + "Realm " + realmName + " does not exist.");
        throw (initializationException);
    }
    CaseInsensitiveHashMap allAtt = new CaseInsensitiveHashMap(getAttributes(token, type, name));
    Map resultMap = new HashMap();
    Iterator it = attrNames.iterator();
    while (it.hasNext()) {
        String attrName = (String) it.next();
        if (allAtt.containsKey(attrName)) {
            resultMap.put(attrName, allAtt.get(attrName));
        }
    }
    return resultMap;
}
Also used : HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

Example 13 with CaseInsensitiveHashMap

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

the class MapHelper method readMap.

/**
     * Read a stream into a map of strings to sets of strings.  Lines whose first non whitespace character
     * is a hash are ignored as comments, while lines which do not contain an assignment are just ignored.
     *
     * @param is A stream to read properties from.
     * @return A map of strings to sets of strings
     * @throws IOException if there is an IO problem when reading the file (like it doesn't exist, etc.)
     */
public static Map<String, Set<String>> readMap(InputStream is) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    try {
        Map<String, Set<String>> result = new CaseInsensitiveHashMap();
        String line;
        while ((line = br.readLine()) != null) {
            line = line.trim();
            // ignore blank lines and comments
            if (line.length() == 0 || line.startsWith("#")) {
                continue;
            }
            int idx = line.indexOf('=');
            if (idx != -1) {
                String key = line.substring(0, idx);
                String value = line.substring(idx + 1);
                if (!value.isEmpty()) {
                    Set<String> values = result.get(key);
                    if (values == null) {
                        values = new CaseInsensitiveHashSet(1);
                    }
                    values.add(value);
                    result.put(key, values);
                }
            }
        }
        return result;
    } finally {
        IOUtils.closeIfNotNull(br);
    }
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) Set(java.util.Set) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

Example 14 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 15 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)

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