Search in sources :

Example 46 with CaseInsensitiveHashMap

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

the class AMSDKRepo method assignService.

public void assignService(SSOToken token, IdType type, String name, String serviceName, SchemaType sType, Map attrMap) throws IdRepoException, SSOException {
    if (type.equals(IdType.AGENT) || type.equals(IdType.GROUP)) {
        Object[] args = { this.getClass().getName() };
        throw new IdRepoUnsupportedOpException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SERVICES_NOT_SUPPORTED_FOR_AGENTS_AND_GROUPS, args);
    }
    // Use adminToken if present
    if (adminToken != null) {
        token = adminToken;
    }
    attrMap = new CaseInsensitiveHashMap(attrMap);
    if (type.equals(IdType.USER)) {
        Set OCs = (Set) attrMap.get("objectclass");
        Set attrName = new HashSet(1);
        attrName.add("objectclass");
        Map tmpMap = getAttributes(token, type, name, attrName);
        Set oldOCs = (Set) tmpMap.get("objectclass");
        // Set oldOCs = getAttribute("objectclass");
        OCs = AMCommonUtils.combineOCs(OCs, oldOCs);
        attrMap.put("objectclass", OCs);
        if (sType.equals(SchemaType.USER)) {
            setMixAttributes(token, type, name, attrMap, false);
        } else if (sType.equals(SchemaType.DYNAMIC)) {
            // Map tmpMap = new HashMap();
            // tmpMap.put("objectclass", (Set) attrMap.get("objectclass"));
            setMixAttributes(token, type, name, attrMap, false);
        }
    } else if (type.equals(IdType.ROLE) || type.equals(IdType.FILTEREDROLE) || type.equals(IdType.REALM)) {
        IDirectoryServices dsServices = AMDirectoryAccessFactory.getDirectoryServices();
        try {
            AMStoreConnection amsc = (sc == null) ? new AMStoreConnection(token) : sc;
            AMOrganization amOrg = amsc.getOrganization(orgDN);
            // Check if service is already assigned
            Set assndSvcs = amOrg.getRegisteredServiceNames();
            if (!assndSvcs.contains(serviceName)) {
                amOrg.registerService(serviceName, false, false);
            }
        } catch (AMException ame) {
            if (ame.getErrorCode().equals("464")) {
            // do nothing. Definition already exists. That's OK.
            } else {
                throw IdUtils.convertAMException(ame);
            }
        }
        String dn = getDN(type, name);
        try {
            // Remove OCs. Those are needed only when setting service
            // for users, not roles.
            attrMap.remove("objectclass");
            int priority = type.equals(IdType.REALM) ? 3 : 0;
            Set values = (Set) attrMap.remove("cospriority");
            if ((values != null) && (!values.isEmpty())) {
                try {
                    priority = Integer.parseInt((String) values.iterator().next());
                } catch (NumberFormatException ex) {
                    if (debug.warningEnabled()) {
                        debug.warning("AMSDKRepo.assignService:", ex);
                    }
                }
            }
            dsServices.createAMTemplate(token, dn, getProfileType(type), serviceName, attrMap, priority);
        } catch (AMException ame) {
            debug.error("AMSDKRepo.assignService: Caught AMException", ame);
            throw IdUtils.convertAMException(ame);
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) IDirectoryServices(com.iplanet.am.sdk.common.IDirectoryServices) IdRepoUnsupportedOpException(com.sun.identity.idm.IdRepoUnsupportedOpException) Map(java.util.Map) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) HashSet(java.util.HashSet)

Example 47 with CaseInsensitiveHashMap

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

the class AMIdentityRepository method getAttributeNameMap.

private Map[] getAttributeNameMap(Map configMap) {
    Set attributeMap = (Set) configMap.get(IdConstants.ATTR_MAP);
    if (attributeMap == null || attributeMap.isEmpty()) {
        return null;
    } else {
        Map[] returnArray = new Map[2];
        int size = attributeMap.size();
        returnArray[0] = new CaseInsensitiveHashMap(size);
        returnArray[1] = new CaseInsensitiveHashMap(size);
        Iterator it = attributeMap.iterator();
        while (it.hasNext()) {
            String mapString = (String) it.next();
            int eqIndex = mapString.indexOf('=');
            if (eqIndex > -1) {
                String first = mapString.substring(0, eqIndex);
                String second = mapString.substring(eqIndex + 1);
                returnArray[0].put(first, second);
                returnArray[1].put(second, first);
            } else {
                returnArray[0].put(mapString, mapString);
                returnArray[1].put(mapString, mapString);
            }
        }
        return returnArray;
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) 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 48 with CaseInsensitiveHashMap

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

the class AMIdentityRepository method combineAttrMaps.

private Map combineAttrMaps(Set setOfMaps, boolean isString) {
    // Map resultMap = new CaseInsensitiveHashMap();
    Map resultMap = new AMHashMap();
    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) HashSet(java.util.HashSet) AMHashMap(com.iplanet.am.sdk.AMHashMap) Iterator(java.util.Iterator) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 49 with CaseInsensitiveHashMap

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

the class IdServicesImpl 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();
        Iterator it = results.iterator();
        while (it.hasNext()) {
            String dn = (String) it.next();
            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];
        Iterator it = current.getSearchResults().iterator();
        Map allAttrMaps = current.getResultAttributes();
        while (it.hasNext()) {
            String m = (String) it.next();
            String mname = DNUtils.DNtoName(m, false);
            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);
    Iterator it = resultsMap.keySet().iterator();
    while (it.hasNext()) {
        String mname = (String) it.next();
        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) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) IdSearchResults(com.sun.identity.idm.IdSearchResults) AMIdentity(com.sun.identity.idm.AMIdentity) Iterator(java.util.Iterator) RepoSearchResults(com.sun.identity.idm.RepoSearchResults) Map(java.util.Map) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet)

Example 50 with CaseInsensitiveHashMap

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

the class IdServicesImpl method mapAttributeNames.

private Map mapAttributeNames(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 forwardMap = mapArray[0];
        Iterator it = attrMap.keySet().iterator();
        while (it.hasNext()) {
            String curr = (String) it.next();
            if (forwardMap.containsKey(curr)) {
                resultMap.put((String) forwardMap.get(curr), (Set) attrMap.get(curr));
            } else {
                resultMap.put(curr, (Set) attrMap.get(curr));
            }
        }
    }
    return resultMap;
}
Also used : Iterator(java.util.Iterator) Map(java.util.Map) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) 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