Search in sources :

Example 21 with CaseInsensitiveHashMap

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

the class DJLDAPv3Repo method unassignService.

/**
     * Unassigns a service from the provided identity.
     * In case of a USER this will traverse through all the existing user attributes and will remove those that are
     * currently present in the entry. This will also remove the objectclass corresponding to the service.
     * In case of a REALM this will remove the service from the locally cached serviceMap, and will notify the
     * registered {@link IdRepoListener}.
     *
     * @param token Not used.
     * @param type The type of the identity, this should be always USER or REALM.
     * @param name The name of the identity. Only used when identity type is USER.
     * @param serviceName The name of the service to remove from the identity.
     * @param attrMap Holds the objectclasses relevant for this service removal.
     * @throws IdRepoException If the identity type was invalid or if there was an error while removing the service.
     */
@Override
@SuppressWarnings("rawtypes")
public void unassignService(SSOToken token, IdType type, String name, String serviceName, Map<String, Set<String>> attrMap) throws IdRepoException {
    if (DEBUG.messageEnabled()) {
        DEBUG.message("unassignService invoked");
    }
    if (type.equals(IdType.USER)) {
        Set<String> removeOCs = attrMap.get(OBJECT_CLASS_ATTR);
        if (removeOCs != null) {
            Schema dirSchema = getSchema();
            Map attrs = new CaseInsensitiveHashMap();
            for (String oc : removeOCs) {
                try {
                    ObjectClass oc2 = dirSchema.getObjectClass(oc);
                    for (AttributeType optional : oc2.getOptionalAttributes()) {
                        attrs.put(optional.getNameOrOID(), Collections.EMPTY_SET);
                    }
                    for (AttributeType required : oc2.getRequiredAttributes()) {
                        attrs.put(required.getNameOrOID(), Collections.EMPTY_SET);
                    }
                } catch (UnknownSchemaElementException usee) {
                    DEBUG.error("Unable to unassign " + serviceName + " service from identity: " + name, usee);
                    throw newIdRepoException(IdRepoErrorCode.UNABLE_GET_SERVICE_SCHEMA, serviceName);
                }
            }
            Set<String> requestedAttrs = new CaseInsensitiveHashSet(attrs.keySet());
            //if the service objectclass is auxiliary (which it should be), then the objectclass attribute may not
            //be present if top is not defined as superior class.
            requestedAttrs.add(OBJECT_CLASS_ATTR);
            Map<String, Set<String>> attributes = new CaseInsensitiveHashMap(getAttributes(token, type, name, requestedAttrs));
            Set<String> OCValues = new CaseInsensitiveHashSet(attributes.get(OBJECT_CLASS_ATTR));
            OCValues.removeAll(removeOCs);
            attrs.put(OBJECT_CLASS_ATTR, OCValues);
            //implementing retainAll here for CaseInsensitiveHashMap's keySet
            for (String string : (Set<String>) attrs.keySet()) {
                if (!attributes.containsKey(string)) {
                    attrs.remove(string);
                }
            }
            setAttributes(token, type, name, attrs, false, true, false);
        }
    } else if (type.equals(IdType.REALM)) {
        if (serviceName != null && !serviceName.isEmpty()) {
            serviceMap.remove(serviceName);
        }
        if (idRepoListener != null) {
            idRepoListener.setServiceAttributes(serviceName, serviceMap);
        }
    } else {
        throw new IdRepoUnsupportedOpException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SERVICES_NOT_SUPPORTED_FOR_AGENTS_AND_GROUPS, new Object[] { CLASS_NAME });
    }
}
Also used : ObjectClass(org.forgerock.opendj.ldap.schema.ObjectClass) 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) UnknownSchemaElementException(org.forgerock.opendj.ldap.schema.UnknownSchemaElementException) Schema(org.forgerock.opendj.ldap.schema.Schema) ByteString(org.forgerock.opendj.ldap.ByteString) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) IdRepoUnsupportedOpException(com.sun.identity.idm.IdRepoUnsupportedOpException) AttributeType(org.forgerock.opendj.ldap.schema.AttributeType) Map(java.util.Map) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

Example 22 with CaseInsensitiveHashMap

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

the class GenericRepoTest method removeAttributesSuccessful.

@Test
public void removeAttributesSuccessful() throws Exception {
    Map<String, Set<String>> attrs = new CaseInsensitiveHashMap(idrepo.getAttributes(null, IdType.USER, DEMO, asSet("givenName")));
    assertThat(attrs.get("givenName")).containsOnly(DEMO);
    idrepo.removeAttributes(null, IdType.USER, DEMO, asSet("givenName"));
    attrs = new CaseInsensitiveHashMap(idrepo.getAttributes(null, IdType.USER, DEMO, asSet("givenName")));
    assertThat(attrs.get("givenName")).isNull();
    Map<String, Set<String>> changes = new HashMap<String, Set<String>>();
    changes.put("givenName", asSet(DEMO));
    idrepo.setAttributes(null, IdType.USER, DEMO, changes, true);
    attrs = new CaseInsensitiveHashMap(idrepo.getAttributes(null, IdType.USER, DEMO, asSet("givenName")));
    assertThat(attrs.get("givenName")).containsOnly(DEMO);
}
Also used : 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) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Test(org.testng.annotations.Test)

Example 23 with CaseInsensitiveHashMap

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

the class GenericRepoTest method settingBinarryAttributesIsSuccessful.

@Test
public void settingBinarryAttributesIsSuccessful() throws Exception {
    Map<String, Set<String>> attrs = new CaseInsensitiveHashMap(idrepo.getAttributes(null, IdType.USER, DEMO));
    assertThat(attrs.get("sn")).contains(DEMO);
    Map<String, byte[][]> changes = new HashMap<String, byte[][]>();
    byte[][] values = new byte[1][];
    values[0] = "testsn".getBytes("UTF-8");
    changes.put("sn", values);
    idrepo.setBinaryAttributes(null, IdType.USER, DEMO, changes, true);
    attrs = new CaseInsensitiveHashMap(idrepo.getAttributes(null, IdType.USER, DEMO));
    assertThat(attrs.get("sn")).containsOnly(DEMO, "testsn");
    values[0] = DEMO.getBytes("UTF-8");
    changes.put("sn", values);
    idrepo.setBinaryAttributes(null, IdType.USER, DEMO, changes, false);
    attrs = new CaseInsensitiveHashMap(idrepo.getAttributes(null, IdType.USER, DEMO));
    assertThat(attrs.get("sn")).containsOnly(DEMO);
}
Also used : 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) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Test(org.testng.annotations.Test)

Example 24 with CaseInsensitiveHashMap

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

the class GenericRepoTest method settingNonExistentAttributeWithEmptyValueDoesNotFail.

@Test(description = "OPENAM-3237")
public void settingNonExistentAttributeWithEmptyValueDoesNotFail() throws Exception {
    Map<String, Set<String>> attrs = new CaseInsensitiveHashMap(idrepo.getAttributes(null, IdType.USER, DEMO));
    assertThat(attrs.get("cn")).isNull();
    Map<String, Set<String>> changes = new HashMap<String, Set<String>>();
    changes.put("cn", new HashSet<String>(0));
    idrepo.setAttributes(null, IdType.USER, DEMO, changes, true);
    attrs = new CaseInsensitiveHashMap(idrepo.getAttributes(null, IdType.USER, DEMO));
    assertThat(attrs.get("cn")).isNull();
}
Also used : 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) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Test(org.testng.annotations.Test)

Example 25 with CaseInsensitiveHashMap

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

the class SpecialRepo 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 {
    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)

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