use of com.sun.identity.common.CaseInsensitiveHashMap in project OpenAM by OpenRock.
the class FilesRepo method readFile.
Map readFile(File file) throws IdRepoException {
Map answer = Collections.EMPTY_MAP;
String fileName = file.getAbsolutePath();
// Check in cache & if time is curent
Long lastModified = (Long) identityTimeCache.get(fileName);
if ((lastModified != null) && (lastModified.longValue() == file.lastModified()) && ((answer = (Map) identityCache.get(fileName)) != null)) {
return (answer);
}
for (Iterator it = identityCache.keySet().iterator(); it.hasNext(); ) {
String origFileName = (String) it.next();
// object in flatfile repository is saved as mixed case filenames.
if (!fileName.equals(origFileName)) {
if (fileName.equalsIgnoreCase(origFileName)) {
fileName = origFileName;
break;
}
} else {
break;
}
}
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(fileName));
StringBuilder encodedMapBuffer = new StringBuilder(200);
String line;
while ((line = br.readLine()) != null) {
encodedMapBuffer.append(line);
}
String encodedMap = encodedMapBuffer.toString();
SOAPClient client = new SOAPClient();
Map map = client.decodeMap(encodedMap);
// Convert HashMap to CaseInsensitiveHashMap
answer = new CaseInsensitiveHashMap();
for (Iterator items = map.keySet().iterator(); items.hasNext(); ) {
Object key = items.next();
Set ovalue = (Set) map.get(key);
Set nvalue = new CaseInsensitiveHashSet();
nvalue.addAll(ovalue);
answer.put(key, nvalue);
}
// Add to cache
identityTimeCache.put(fileName, new Long(file.lastModified()));
identityCache.put(fileName, answer);
} catch (FileNotFoundException fn) {
if (debug.messageEnabled()) {
debug.message("FilesRepo.readFile: file not found: " + fileName);
}
String[] args = { NAME, fileName };
throw new FilesRepoEntryNotFoundException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_FIND_ENTRY, args);
} catch (IOException e) {
if (debug.messageEnabled()) {
debug.message("FilesRepo.readFile: error reading file: " + fileName, e);
}
String[] args = { NAME, fileName };
throw (new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_FIND_ENTRY, args));
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
if (debug.warningEnabled()) {
debug.warning("FilesRepo.redFile: read error: " + fileName, e);
}
}
}
}
return (answer);
}
use of com.sun.identity.common.CaseInsensitiveHashMap in project OpenAM by OpenRock.
the class FilesRepo method processAttributes.
static Map processAttributes(Map attrs, Set hashAttrs, Set encAttrs) {
// Convert to CaseInsensitiveHashMap
Map answer = new CaseInsensitiveHashMap();
for (Iterator items = attrs.keySet().iterator(); items.hasNext(); ) {
Object key = items.next();
Set ovalue = (Set) attrs.get(key);
Set nvalue = new CaseInsensitiveHashSet();
if (hashAttrs.contains(key)) {
for (Iterator i = ovalue.iterator(); i.hasNext(); ) {
nvalue.add(Hash.hash((String) i.next()));
}
} else if (encAttrs.contains(key)) {
try {
for (Iterator i = ovalue.iterator(); i.hasNext(); ) {
nvalue.add((String) AccessController.doPrivileged(new EncodeAction((String) i.next())));
}
} catch (Throwable e) {
// Printing the attribute value could be security issue
debug.error("FilesRepo.processAttributes: unable to encode", e);
}
} else {
nvalue.addAll(ovalue);
}
answer.put(key, nvalue);
}
return (answer);
}
use of com.sun.identity.common.CaseInsensitiveHashMap in project OpenAM by OpenRock.
the class SMSEntry method addAttribute.
/**
* Adds the attribute value to the given attribute name. It is stored
* locally and is not written to the directory.
*/
public void addAttribute(String attrName, String value) throws SMSException {
Set attrValues = null;
if (attrSet == null) {
attrSet = new CaseInsensitiveHashMap();
} else if (attrSet.containsKey(attrName)) {
attrValues = (Set) attrSet.get(attrName);
if (attrValues.contains(value)) {
// Value is already present
if (debug.messageEnabled()) {
debug.message("SMSEntry: Duplicate value for addition");
}
throw (new SMSException(LdapException.newLdapException(ResultCode.ATTRIBUTE_OR_VALUE_EXISTS, getBundleString(IUMSConstants.SMS_ATTR_OR_VAL_EXISTS)), "sms-ATTR_OR_VAL_EXISTS"));
}
}
// Add the attribute to attrset
if (attrValues == null) {
attrValues = new HashSet();
}
attrValues.add(value);
attrSet.put(attrName, attrValues);
// Check if the modification set exists, and add the attribute
if (modSet == null) {
modSet = new HashSet();
}
modSet.add(new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute(attrName, value)));
}
use of com.sun.identity.common.CaseInsensitiveHashMap in project OpenAM by OpenRock.
the class OrgConfigViaAMSDK method getAttributeMapping.
/**
* Returns the SMS attribute name to AMSDK attribute name mappings for the
* organization
*/
private Map getAttributeMapping() throws SMSException {
if (!ServiceManager.isConfigMigratedTo70()) {
return (notMigratedAttributeMappings);
}
// Check the cache
Map answer = (Map) attributeMappings.get(parentOrgName);
if (answer != null)
return (answer);
// Construct the attribute mappings
Map attrs = serviceConfig.getAttributes();
if (attrs != null && !attrs.isEmpty()) {
Set mapAttrs = (Set) attrs.get(MAPPING_ATTR_NAME);
if (mapAttrs != null && !mapAttrs.isEmpty()) {
for (Iterator items = mapAttrs.iterator(); items.hasNext(); ) {
String attrMapping = (String) items.next();
String[] maps = DNMapper.splitString(attrMapping);
if (answer == null) {
answer = new CaseInsensitiveHashMap();
}
answer.put(maps[0], maps[1]);
}
}
}
if (answer == null) {
answer = Collections.EMPTY_MAP;
}
// Add to cache
attributeMappings.put(parentOrgName, answer);
return (answer);
}
use of com.sun.identity.common.CaseInsensitiveHashMap in project OpenAM by OpenRock.
the class OrgConfigViaAMSDK method getReverseAttributeMapping.
/**
* Returns the AMSDK attribute name to SMS attribute name mappings for the
* organization
*/
private Map getReverseAttributeMapping() throws SMSException {
if (!ServiceManager.isConfigMigratedTo70()) {
return (notMigratedReverseAttributeMappings);
}
// Check the cache
Map answer = (Map) reverseAttributeMappings.get(parentOrgName);
if (answer != null)
return (answer);
// Get the attribute mapping and reverse it
Map attrMaps = getAttributeMapping();
for (Iterator items = attrMaps.entrySet().iterator(); items.hasNext(); ) {
Map.Entry entry = (Map.Entry) items.next();
if (answer == null) {
answer = new CaseInsensitiveHashMap();
}
answer.put(entry.getValue(), entry.getKey().toString());
}
if (answer == null) {
answer = Collections.EMPTY_MAP;
}
reverseAttributeMappings.put(parentOrgName, answer);
return (answer);
}
Aggregations