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