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