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 });
}
}
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);
}
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);
}
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();
}
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;
}
Aggregations