use of com.sun.identity.common.CaseInsensitiveHashMap in project OpenAM by OpenRock.
the class FilesRepo method create.
/*
* (non-Javadoc)
*
* @see com.sun.identity.idm.IdRepo#create(com.iplanet.sso.SSOToken,
* com.sun.identity.idm.IdType, java.lang.String, java.util.Map)
*/
public String create(SSOToken token, IdType type, String name, Map attrMap) throws IdRepoException, SSOException {
if (initializationException != null) {
debug.error("FilesRepo: throwing initialization exception");
throw (initializationException);
}
if (supportedOps.keySet().contains(type)) {
// Check if identity exists
File file = constructFile(directory, type, name);
if (!file.exists()) {
// If type is user, add the configured object classes
CaseInsensitiveHashMap nAttrs = new CaseInsensitiveHashMap(attrMap);
Set ocs = (Set) nAttrs.get(OC);
if (ocs == null) {
nAttrs.put(OC, userOCs);
} else {
CaseInsensitiveHashSet ocv = new CaseInsensitiveHashSet(ocs);
ocv.addAll(userOCs);
}
// Create the identity
attrMap = processAttributes(nAttrs, hashAttributes, encryptAttributes);
writeFile(file, attrMap);
// %%% Send notification (must be via a different thread)
if (repoListener != null) {
repoListener.objectChanged(name, type, AMEvent.OBJECT_ADDED, repoListener.getConfigMap());
}
} else {
// throw exception
throw IdRepoDuplicateObjectException.nameAlreadyExists(file.getAbsolutePath());
}
} else {
Object[] args = { NAME, IdOperation.SERVICE.getName(), type.getName() };
throw new IdRepoUnsupportedOpException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.PLUGIN_OPERATION_NOT_SUPPORTED, args);
}
return (name);
}
use of com.sun.identity.common.CaseInsensitiveHashMap in project OpenAM by OpenRock.
the class AgentsRepo 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 {
if (debug.messageEnabled()) {
debug.message("AgentsRepo.getAttributes() with attrNames called: " + type + ": " + name);
}
if (initializationException != null) {
debug.error("AgentsRepo.getAttributes: " + "Realm " + realmName + " does not exist.");
throw (initializationException);
}
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;
}
use of com.sun.identity.common.CaseInsensitiveHashMap in project OpenAM by OpenRock.
the class MapHelper method readMap.
/**
* Read a stream into a map of strings to sets of strings. Lines whose first non whitespace character
* is a hash are ignored as comments, while lines which do not contain an assignment are just ignored.
*
* @param is A stream to read properties from.
* @return A map of strings to sets of strings
* @throws IOException if there is an IO problem when reading the file (like it doesn't exist, etc.)
*/
public static Map<String, Set<String>> readMap(InputStream is) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(is));
try {
Map<String, Set<String>> result = new CaseInsensitiveHashMap();
String line;
while ((line = br.readLine()) != null) {
line = line.trim();
// ignore blank lines and comments
if (line.length() == 0 || line.startsWith("#")) {
continue;
}
int idx = line.indexOf('=');
if (idx != -1) {
String key = line.substring(0, idx);
String value = line.substring(idx + 1);
if (!value.isEmpty()) {
Set<String> values = result.get(key);
if (values == null) {
values = new CaseInsensitiveHashSet(1);
}
values.add(value);
result.put(key, values);
}
}
}
return result;
} finally {
IOUtils.closeIfNotNull(br);
}
}
use of com.sun.identity.common.CaseInsensitiveHashMap in project OpenAM by OpenRock.
the class AMIdentityRepository method reverseMapAttributeNames.
// TODO:
// FIXME: Move these utilities to a util class
private Map reverseMapAttributeNames(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 reverseMap = mapArray[1];
Iterator it = attrMap.keySet().iterator();
while (it.hasNext()) {
String curr = (String) it.next();
if (reverseMap.containsKey(curr)) {
resultMap.put((String) reverseMap.get(curr), (Set) attrMap.get(curr));
} else {
resultMap.put(curr, (Set) attrMap.get(curr));
}
}
}
return resultMap;
}
use of com.sun.identity.common.CaseInsensitiveHashMap in project OpenAM by OpenRock.
the class AMIdentity method modifyService.
/**
* Set attributes related to a specific service. The assumption is that the
* service is already assigned to the identity. The attributes for the
* service are validated against the service schema.
*
* This method is only valid for AMIdentity object of type User.
*
* @param serviceName
* Name of the service.
* @param attrMap
* Map of attribute-values.
* @throws IdRepoException
* If there are repository related error conditions.
* @throws SSOException
* If user's single sign on token is invalid.
* @supported.api
*/
public void modifyService(String serviceName, Map attrMap) throws IdRepoException, SSOException {
IdServices idServices = IdServicesFactory.getDataStoreServices();
Set OCs = getServiceOCs(token, serviceName);
SchemaType stype;
Map tMap = new HashMap();
tMap.put(serviceName, OCs);
Set assignedServices = idServices.getAssignedServices(token, type, name, tMap, orgName, univDN);
if (!assignedServices.contains(serviceName)) {
Object[] args = { serviceName };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SERVICE_NOT_ASSIGNED, args);
}
// Check if attrMap has cos priority attribute
// If present, remove it for validating the attributes
boolean hasCosPriority = (new CaseInsensitiveHashSet(attrMap.keySet()).contains(COS_PRIORITY));
Object values = null;
if (hasCosPriority) {
attrMap = new CaseInsensitiveHashMap(attrMap);
values = attrMap.remove(COS_PRIORITY);
}
// Validate the attributes
try {
ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
ServiceSchema ss = ssm.getSchema(type.getName());
if (ss != null) {
attrMap = ss.validateAndInheritDefaults(attrMap, false);
stype = ss.getServiceType();
} else if ((ss = ssm.getSchema(SchemaType.DYNAMIC)) != null) {
attrMap = ss.validateAndInheritDefaults(attrMap, false);
stype = SchemaType.DYNAMIC;
} else {
Object[] args = { serviceName };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_GET_SERVICE_SCHEMA, args);
}
} catch (SMSException smse) {
// debug.error
Object[] args = { serviceName };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.DATA_INVALID_FOR_SERVICE, args);
}
// Add COS priority if present
if (hasCosPriority) {
attrMap.put(COS_PRIORITY, values);
}
// modify service attrs
if (debug.messageEnabled()) {
debug.message("AMIdentity.modifyService befre idService " + "serviceName=" + serviceName + "; attrMap=" + attrMap);
}
idServices.modifyService(token, type, name, serviceName, stype, attrMap, orgName, univDN);
}
Aggregations