Search in sources :

Example 31 with CaseInsensitiveHashSet

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

the class DJLDAPv3Repo method getServiceAttributes.

/**
     * Returns the service attributes in binary or string format for the given identity.
     * In case of a USER this will retrieve first the service attributes from the user entry, and later it will also
     * query the service attributes of the current realm. When a user-specific setting is missing the realm-specific one
     * will be returned instead.
     * In case of a REALM it will return a defensive copy of the service attributes stored locally.
     *
     * @param type The type of the identity, this should be always USER or REALM.
     * @param name The name of the identity to query. Only used when identity type is USER.
     * @param serviceName The name of the service, which in case of USER may be null.
     * @param attrNames The name of the service attributes that needs to be queried. In case of USER this may NOT be
     * null. In case of REALM, when null this will return all attributes for the service.
     * @param extractor The attribute extractor to use.
     * @param converter The attribute filter to use.
     * @return The matching service attributes.
     * @throws IdRepoException If there was an error while retrieving the service attributes from the user, or if the
     * identity type was invalid.
     */
private <T> Map<String, T> getServiceAttributes(IdType type, String name, String serviceName, Set<String> attrNames, Function<Attribute, T, IdRepoException> extractor, Function<Map<String, Set<String>>, Map<String, T>, IdRepoException> converter) throws IdRepoException {
    if (type.equals(IdType.USER)) {
        Map<String, T> attrsFromUser = getAttributes(type, name, attrNames, extractor);
        if (serviceName == null || serviceName.isEmpty()) {
            return attrsFromUser;
        }
        Map<String, Set<String>> attrsFromRealm = serviceMap.get(serviceName);
        Map<String, Set<String>> filteredAttrsFromRealm = new HashMap<String, Set<String>>();
        if (attrsFromRealm == null || attrsFromRealm.isEmpty()) {
            return attrsFromUser;
        } else {
            attrNames = new CaseInsensitiveHashSet(attrNames);
            for (Map.Entry<String, Set<String>> entry : attrsFromRealm.entrySet()) {
                String attrName = entry.getKey();
                if (attrNames.contains(attrName)) {
                    filteredAttrsFromRealm.put(attrName, entry.getValue());
                }
            }
        }
        Map<String, T> filteredAttrsFromRealm2 = converter.apply(filteredAttrsFromRealm);
        Set<String> attrNameSet = new CaseInsensitiveHashSet(attrsFromUser.keySet());
        for (Map.Entry<String, T> entry : filteredAttrsFromRealm2.entrySet()) {
            String attrName = entry.getKey();
            if (!attrNameSet.contains(attrName)) {
                attrsFromUser.put(attrName, entry.getValue());
            }
        }
        return attrsFromUser;
    } else if (type.equals(IdType.REALM)) {
        Map<String, T> attrs = converter.apply(serviceMap.get(serviceName));
        Map<String, T> results = new HashMap<String, T>();
        if (attrs == null || attrs.isEmpty()) {
            return results;
        }
        if (attrNames == null || attrNames.isEmpty()) {
            results.putAll(attrs);
            return results;
        } else {
            Set<String> attributeNames = new CaseInsensitiveHashSet(attrs.keySet());
            for (String attrName : attrNames) {
                if (attributeNames.contains(attrName)) {
                    results.put(attrName, attrs.get(attrName));
                }
            }
            return results;
        }
    } else {
        throw new IdRepoUnsupportedOpException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SERVICES_NOT_SUPPORTED_FOR_AGENTS_AND_GROUPS, new Object[] { CLASS_NAME });
    }
}
Also used : 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) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) ByteString(org.forgerock.opendj.ldap.ByteString) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) IdRepoUnsupportedOpException(com.sun.identity.idm.IdRepoUnsupportedOpException) Map(java.util.Map) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

Example 32 with CaseInsensitiveHashSet

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

the class GenericRepoTest method setAttributesAddsNecessaryObjectClasses.

//Disabled, because this would require a bit more clever schema object in IdRepoTestBase.
@Test(enabled = false)
public void setAttributesAddsNecessaryObjectClasses() throws Exception {
    Map<String, Set<String>> attrs = idrepo.getAttributes(null, IdType.USER, DEMO, asSet("objectclass"));
    assertThat(attrs).hasSize(1);
    Set<String> attr = new CaseInsensitiveHashSet(attrs.entrySet().iterator().next().getValue());
    assertThat(attr.contains("pilotPerson")).isFalse();
    Map<String, Set<String>> changes = new HashMap<String, Set<String>>();
    changes.put("otherMailbox", asSet("DemoLand"));
    idrepo.setAttributes(null, IdType.USER, DEMO, changes, true);
    attrs = idrepo.getAttributes(null, IdType.USER, DEMO, asSet("objectclass"));
    assertThat(attrs).hasSize(1);
    attr = new CaseInsensitiveHashSet(attrs.entrySet().iterator().next().getValue());
    assertThat(attr.contains("pilotPerson")).isTrue();
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) CollectionUtils.asOrderedSet(org.forgerock.openam.utils.CollectionUtils.asOrderedSet) Set(java.util.Set) CollectionUtils.asSet(org.forgerock.openam.utils.CollectionUtils.asSet) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Test(org.testng.annotations.Test)

Example 33 with CaseInsensitiveHashSet

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

the class OpenSSOSubjectAttributesCollector method getAvailableSubjectAttributeNames.

public Set<String> getAvailableSubjectAttributeNames() throws EntitlementException {
    CaseInsensitiveHashSet result = new CaseInsensitiveHashSet();
    try {
        ServiceConfig sc = idRepoServiceConfigManager.getOrganizationConfig(realm, null);
        if (sc != null) {
            Set<String> subConfigNames = sc.getSubConfigNames();
            if (subConfigNames != null) {
                for (String idRepoName : subConfigNames) {
                    ServiceConfig reposc = sc.getSubConfig(idRepoName);
                    Map<String, Set<String>> attrMap = reposc.getAttributesForRead();
                    Set<String> userAttrs = attrMap.get(LDAPv3Config_USER_ATTR);
                    if ((userAttrs != null) && !userAttrs.isEmpty()) {
                        result.addAll(userAttrs);
                    }
                }
            }
        }
        return result;
    } catch (SMSException e) {
        throw new EntitlementException(602, e);
    } catch (SSOException e) {
        throw new EntitlementException(602, e);
    }
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) EntitlementException(com.sun.identity.entitlement.EntitlementException) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) Set(java.util.Set) HashSet(java.util.HashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Example 34 with CaseInsensitiveHashSet

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

the class ConfigureSocialAuthN method mergeAttributes.

/**
     * Carefully merge the values in two maps.  The existing ("base") attributes are added first, then values in
     * newAttrs.
     *
     * @param existingAttrs The "base" attributes.
     * @param newAttrs Coinciding attributes from here overwrite ones in existing attributes.
     * @return A map containing a combination of the two maps.
     */
Map<String, Set<String>> mergeAttributes(Map<String, Set<String>> existingAttrs, Map<String, Set<String>> newAttrs) {
    Map<String, Set<String>> mergedAttrs = new CaseInsensitiveHashMap(existingAttrs);
    for (Map.Entry<String, Set<String>> attr : newAttrs.entrySet()) {
        Set<String> values = attr.getValue();
        Set<String> existingValues = mergedAttrs.get(attr.getKey());
        if (existingValues == null) {
            existingValues = new CaseInsensitiveHashSet();
            mergedAttrs.put(attr.getKey(), existingValues);
        }
        existingValues.addAll(values);
    }
    return mergedAttrs;
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) 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 35 with CaseInsensitiveHashSet

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

the class IdServicesImpl method mapAttributeNames.

private Set mapAttributeNames(Set attrNames, Map configMap) {
    if (attrNames == null || attrNames.isEmpty()) {
        return attrNames;
    }
    Map[] mapArray = getAttributeNameMap(configMap);
    Set resultSet;
    if (mapArray == null) {
        resultSet = attrNames;
    } else {
        resultSet = new CaseInsensitiveHashSet();
        Map forwardMap = mapArray[0];
        Iterator it = attrNames.iterator();
        while (it.hasNext()) {
            String curr = (String) it.next();
            if (forwardMap.containsKey(curr)) {
                resultSet.add((String) forwardMap.get(curr));
            } else {
                resultSet.add(curr);
            }
        }
    }
    return resultSet;
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) Iterator(java.util.Iterator) Map(java.util.Map) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

Aggregations

CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)37 Set (java.util.Set)30 HashSet (java.util.HashSet)27 HashMap (java.util.HashMap)19 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)18 Map (java.util.Map)16 Iterator (java.util.Iterator)13 ByteString (org.forgerock.opendj.ldap.ByteString)9 SSOException (com.iplanet.sso.SSOException)6 IdRepoException (com.sun.identity.idm.IdRepoException)6 IdRepoUnsupportedOpException (com.sun.identity.idm.IdRepoUnsupportedOpException)6 SMSException (com.sun.identity.sm.SMSException)6 CollectionUtils.asSet (org.forgerock.openam.utils.CollectionUtils.asSet)6 LinkedHashSet (java.util.LinkedHashSet)5 CaseInsensitiveTreeSet (com.sun.identity.common.CaseInsensitiveTreeSet)4 PolicyException (com.sun.identity.policy.PolicyException)3 OrderedSet (com.sun.identity.shared.datastruct.OrderedSet)3 ServiceConfig (com.sun.identity.sm.ServiceConfig)3 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)3 File (java.io.File)3