Search in sources :

Example 26 with CaseInsensitiveHashMap

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

the class FilesRepo method readFile.

Map readFile(File file) throws IdRepoException {
    Map answer = Collections.EMPTY_MAP;
    String fileName = file.getAbsolutePath();
    // Check in cache & if time is curent
    Long lastModified = (Long) identityTimeCache.get(fileName);
    if ((lastModified != null) && (lastModified.longValue() == file.lastModified()) && ((answer = (Map) identityCache.get(fileName)) != null)) {
        return (answer);
    }
    for (Iterator it = identityCache.keySet().iterator(); it.hasNext(); ) {
        String origFileName = (String) it.next();
        // object in flatfile repository is saved as mixed case filenames.
        if (!fileName.equals(origFileName)) {
            if (fileName.equalsIgnoreCase(origFileName)) {
                fileName = origFileName;
                break;
            }
        } else {
            break;
        }
    }
    BufferedReader br = null;
    try {
        br = new BufferedReader(new FileReader(fileName));
        StringBuilder encodedMapBuffer = new StringBuilder(200);
        String line;
        while ((line = br.readLine()) != null) {
            encodedMapBuffer.append(line);
        }
        String encodedMap = encodedMapBuffer.toString();
        SOAPClient client = new SOAPClient();
        Map map = client.decodeMap(encodedMap);
        // Convert HashMap to CaseInsensitiveHashMap
        answer = new CaseInsensitiveHashMap();
        for (Iterator items = map.keySet().iterator(); items.hasNext(); ) {
            Object key = items.next();
            Set ovalue = (Set) map.get(key);
            Set nvalue = new CaseInsensitiveHashSet();
            nvalue.addAll(ovalue);
            answer.put(key, nvalue);
        }
        // Add to cache
        identityTimeCache.put(fileName, new Long(file.lastModified()));
        identityCache.put(fileName, answer);
    } catch (FileNotFoundException fn) {
        if (debug.messageEnabled()) {
            debug.message("FilesRepo.readFile: file not found: " + fileName);
        }
        String[] args = { NAME, fileName };
        throw new FilesRepoEntryNotFoundException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_FIND_ENTRY, args);
    } catch (IOException e) {
        if (debug.messageEnabled()) {
            debug.message("FilesRepo.readFile: error reading file: " + fileName, e);
        }
        String[] args = { NAME, fileName };
        throw (new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_FIND_ENTRY, args));
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                if (debug.warningEnabled()) {
                    debug.warning("FilesRepo.redFile: read error: " + fileName, e);
                }
            }
        }
    }
    return (answer);
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) Set(java.util.Set) FileNotFoundException(java.io.FileNotFoundException) IdRepoException(com.sun.identity.idm.IdRepoException) IOException(java.io.IOException) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) SOAPClient(com.sun.identity.shared.jaxrpc.SOAPClient) Iterator(java.util.Iterator) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map)

Example 27 with CaseInsensitiveHashMap

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

the class FilesRepo method processAttributes.

static Map processAttributes(Map attrs, Set hashAttrs, Set encAttrs) {
    // Convert to CaseInsensitiveHashMap
    Map answer = new CaseInsensitiveHashMap();
    for (Iterator items = attrs.keySet().iterator(); items.hasNext(); ) {
        Object key = items.next();
        Set ovalue = (Set) attrs.get(key);
        Set nvalue = new CaseInsensitiveHashSet();
        if (hashAttrs.contains(key)) {
            for (Iterator i = ovalue.iterator(); i.hasNext(); ) {
                nvalue.add(Hash.hash((String) i.next()));
            }
        } else if (encAttrs.contains(key)) {
            try {
                for (Iterator i = ovalue.iterator(); i.hasNext(); ) {
                    nvalue.add((String) AccessController.doPrivileged(new EncodeAction((String) i.next())));
                }
            } catch (Throwable e) {
                // Printing the attribute value could be security issue
                debug.error("FilesRepo.processAttributes: unable to encode", e);
            }
        } else {
            nvalue.addAll(ovalue);
        }
        answer.put(key, nvalue);
    }
    return (answer);
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) Set(java.util.Set) EncodeAction(com.sun.identity.security.EncodeAction) 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 28 with CaseInsensitiveHashMap

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

the class SMSEntry method addAttribute.

/**
     * Adds the attribute value to the given attribute name. It is stored
     * locally and is not written to the directory.
     */
public void addAttribute(String attrName, String value) throws SMSException {
    Set attrValues = null;
    if (attrSet == null) {
        attrSet = new CaseInsensitiveHashMap();
    } else if (attrSet.containsKey(attrName)) {
        attrValues = (Set) attrSet.get(attrName);
        if (attrValues.contains(value)) {
            // Value is already present
            if (debug.messageEnabled()) {
                debug.message("SMSEntry: Duplicate value for addition");
            }
            throw (new SMSException(LdapException.newLdapException(ResultCode.ATTRIBUTE_OR_VALUE_EXISTS, getBundleString(IUMSConstants.SMS_ATTR_OR_VAL_EXISTS)), "sms-ATTR_OR_VAL_EXISTS"));
        }
    }
    // Add the attribute to attrset
    if (attrValues == null) {
        attrValues = new HashSet();
    }
    attrValues.add(value);
    attrSet.put(attrName, attrValues);
    // Check if the modification set exists, and add the attribute
    if (modSet == null) {
        modSet = new HashSet();
    }
    modSet.add(new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute(attrName, value)));
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) ModificationItem(javax.naming.directory.ModificationItem) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 29 with CaseInsensitiveHashMap

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

the class OrgConfigViaAMSDK method getAttributeMapping.

/**
     * Returns the SMS attribute name to AMSDK attribute name mappings for the
     * organization
     */
private Map getAttributeMapping() throws SMSException {
    if (!ServiceManager.isConfigMigratedTo70()) {
        return (notMigratedAttributeMappings);
    }
    // Check the cache
    Map answer = (Map) attributeMappings.get(parentOrgName);
    if (answer != null)
        return (answer);
    // Construct the attribute mappings
    Map attrs = serviceConfig.getAttributes();
    if (attrs != null && !attrs.isEmpty()) {
        Set mapAttrs = (Set) attrs.get(MAPPING_ATTR_NAME);
        if (mapAttrs != null && !mapAttrs.isEmpty()) {
            for (Iterator items = mapAttrs.iterator(); items.hasNext(); ) {
                String attrMapping = (String) items.next();
                String[] maps = DNMapper.splitString(attrMapping);
                if (answer == null) {
                    answer = new CaseInsensitiveHashMap();
                }
                answer.put(maps[0], maps[1]);
            }
        }
    }
    if (answer == null) {
        answer = Collections.EMPTY_MAP;
    }
    // Add to cache
    attributeMappings.put(parentOrgName, answer);
    return (answer);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) 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 30 with CaseInsensitiveHashMap

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

the class OrgConfigViaAMSDK method getReverseAttributeMapping.

/**
     * Returns the AMSDK attribute name to SMS attribute name mappings for the
     * organization
     */
private Map getReverseAttributeMapping() throws SMSException {
    if (!ServiceManager.isConfigMigratedTo70()) {
        return (notMigratedReverseAttributeMappings);
    }
    // Check the cache
    Map answer = (Map) reverseAttributeMappings.get(parentOrgName);
    if (answer != null)
        return (answer);
    // Get the attribute mapping and reverse it
    Map attrMaps = getAttributeMapping();
    for (Iterator items = attrMaps.entrySet().iterator(); items.hasNext(); ) {
        Map.Entry entry = (Map.Entry) items.next();
        if (answer == null) {
            answer = new CaseInsensitiveHashMap();
        }
        answer.put(entry.getValue(), entry.getKey().toString());
    }
    if (answer == null) {
        answer = Collections.EMPTY_MAP;
    }
    reverseAttributeMappings.put(parentOrgName, answer);
    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)

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