use of com.sun.identity.sm.ServiceNotFoundException in project OpenAM by OpenRock.
the class SMSFlatFileObject method modify.
/**
* Modify the attributes for the given configuration object.
*
* @param token Ignored argument. Access check is assumed to have
* occurred before reaching this method.
* @param objName Name of the configuration object to modify. Name is
* expected to be a dn.
* @param mods Array of attributes to modify.
*
* @throws IllegalArgumentException if objName or mods argument is null or
* empty, or if an error was encountered getting attributes from the
* mods argument.
* @throws ServiceNotFoundException if the attributes properties file
* for the configuration object is not found.
* @throws SchemaException if a format error occurred while reading in the
* existing attributes properties file.
* @throws SMSException if an IO error occurred while reading or writing
* to the attributes properties file.
*/
public void modify(SSOToken token, String objName, ModificationItem[] mods) throws SMSException, SSOException {
if ((objName == null) || (objName.length() == 0) || (mods == null) || (mods.length == 0)) {
throw new IllegalArgumentException("SMSFlatFileObject.modify: " + "One or more arguments is null or empty");
}
String objKey = objName.toLowerCase();
String filepath = null;
mRWLock.readRequest();
try {
// Check if object exists.
filepath = mNameMap.getProperty(objKey);
if (filepath == null) {
String errmsg = "SMSFlatFileObject.modify: object " + objName + " not found.";
mDebug.error(errmsg);
throw new ServiceNotFoundException(errmsg);
}
} finally {
mRWLock.readDone();
}
// Now do the modification.
mRWLock.writeRequest();
try {
// recheck
filepath = mNameMap.getProperty(objKey);
if (filepath == null) {
String errmsg = "SMSFlatFileObject.modify: object " + objName + " not found.";
mDebug.error(errmsg);
throw new ServiceNotFoundException(errmsg);
}
File filehandle = new File(filepath);
if (!filehandle.isFile()) {
String errmsg = "SMSFlatFileObject.modify: Attributes file for object " + objName + " not found.";
mDebug.error(errmsg);
throw new ServiceNotFoundException(errmsg);
}
// Read in attributes in existing file first.
Properties props = loadProperties(filehandle, objName);
boolean hasSunXmlKeyValue = (props.getProperty(SMSEntry.ATTR_XML_KEYVAL) == null) ? false : true;
// Replace modification items in attributes properties
for (int i = 0; i < mods.length; i++) {
modifyValues(objName, mods[i], props);
}
/*
* save attributes properties file
* sunserviceid's are never modified so don't worry about
* renaming them in modify().
**/
saveProperties(props, filehandle, objName);
// Check for sunxmlkeyvalues
if (!hasSunXmlKeyValue) {
hasSunXmlKeyValue = (props.getProperty(SMSEntry.ATTR_XML_KEYVAL) == null) ? false : true;
}
if (hasSunXmlKeyValue) {
// Delete the lookup files and recreate them
deleteSunXmlKeyValFiles(filehandle.getParentFile());
Set xmlKeyVals = toValSet(SMSEntry.ATTR_XML_KEYVAL, props.getProperty(SMSEntry.ATTR_XML_KEYVAL));
createSunXmlKeyValFiles(filehandle.getParentFile(), xmlKeyVals);
}
} finally {
mRWLock.writeDone();
}
}
use of com.sun.identity.sm.ServiceNotFoundException in project OpenAM by OpenRock.
the class SMSFlatFileObjectBase method saveProperties.
/**
* Saves properties to the attributes file handle, with given objName
* in the file header.
*/
protected void saveProperties(Properties props, File filehandle, String header) throws SMSException {
FileOutputStream fileostr = null;
try {
fileostr = new FileOutputStream(filehandle);
props.store(fileostr, header);
} catch (FileNotFoundException e) {
String errmsg = "SMSFlatFileObjectBase.saveProperties: " + (header == null ? "" : header + ": ") + " File, " + filehandle.getPath() + ". Exception: " + e.getMessage();
mDebug.error("SMSFlatFileObjectBase.saveProperties", e);
throw new ServiceNotFoundException(errmsg);
} catch (IOException e) {
String errmsg = "SMSFlatFileObjectBase.saveProperties: " + (header == null ? "" : header + ": ") + " File, " + filehandle.getPath() + ". Exception: " + e.getMessage();
mDebug.error("SMSFlatFileObjectBase.saveProperties", e);
throw new ServiceNotFoundException(errmsg);
} finally {
try {
fileostr.close();
} catch (IOException e) {
// ignored
}
}
}
use of com.sun.identity.sm.ServiceNotFoundException in project OpenAM by OpenRock.
the class SMSFlatFileObjectBase method loadProperties.
/**
* Loads properties from the attribute file handle.
* @return Properties object of the configuration object.
* @throws ServiceNotFoundException if the attributes file is not found.
* @throws SMSException if an IO error occurred while reading the
* attributes properties file.
* @throws SchemaException if a format error occurred while reading the
* attributes properties file.
*/
protected Properties loadProperties(File filehandle, String objName) throws SMSException {
// read file contents into properties and
// form the attributes map to be returned from the properties.
FileInputStream fileistr = null;
try {
fileistr = new FileInputStream(filehandle);
Properties props = new CaseInsensitiveProperties();
props.load(fileistr);
return props;
} catch (FileNotFoundException e) {
String errmsg = "SMSFlatFileObject.loadProperties: " + objName + " File, " + filehandle.getPath() + e.getMessage();
mDebug.error("SMSFlatFileObject.loadProperties", e);
throw new ServiceNotFoundException(errmsg);
} catch (IOException e) {
String errmsg = "SMSFlatFileObject.loadProperties: " + objName + " File, " + filehandle.getPath() + e.getMessage();
mDebug.error("SMSFlatFileObject.loadProperties", e);
throw new ServiceNotFoundException(errmsg);
} catch (IllegalArgumentException e) {
String errmsg = "SMSFlatFileObject.loadProperties: " + objName + " File, " + filehandle.getPath() + e.getMessage();
mDebug.error("SMSFlatFileObject.loadProperties", e);
throw new ServiceNotFoundException(errmsg);
} finally {
if (fileistr != null) {
try {
fileistr.close();
} catch (IOException e) {
// ignored
}
}
}
}
use of com.sun.identity.sm.ServiceNotFoundException in project OpenAM by OpenRock.
the class SMSEnhancedFlatFileObject method read.
/**
* Reads in attributes of a configuration object.
*
* @return A Map with the coniguration object's attributes or null if the
* configuration object does not exist or no attributes are found.
*
* @param token Ignored argument. Access check is assumed to have
* occurred before reaching this method.
* @param objName Name of the configuration object, expected to be a dn.
*
* @throws SMSException if an IO error occurred during the read.
* @throws SchemaException if a format error occurred while reading the
* attributes properties file.
* @throws IllegalArgumentException if objName argument is null or empty.
*/
public Map read(SSOToken token, String objName) throws SMSException, SSOException {
// check args
if (objName == null || objName.length() == 0) {
throw new IllegalArgumentException("SMSEnhancedFlatFileObject.read: object name is null or empty.");
}
Map attrMap = null;
mRWLock.readRequest();
try {
// check if object exists.
String filepath = root.getAttributeFilename(objName, mRootDir);
if (filepath == null) {
if (mDebug.messageEnabled()) {
mDebug.message("SMSEnhancedFlatFileObject.read: object " + objName + " not found.");
}
} else {
attrMap = Collections.EMPTY_MAP;
// Read in file as properties.
File filehandle = new File(filepath);
Properties props = null;
if (filehandle.exists()) {
try {
props = loadProperties(filehandle, objName);
} catch (ServiceNotFoundException e) {
// props will be null if object does not exist and
// this func subsequently returns null
}
}
// convert each value string to a Set.
if (props != null) {
attrMap = new CaseInsensitiveHashMap();
Enumeration keys = props.propertyNames();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
String vals = props.getProperty(key);
if ((vals != null) && (vals.length() > 0)) {
attrMap.put(key, toValSet(key, vals));
}
}
}
}
} finally {
mRWLock.readDone();
}
return attrMap;
}
use of com.sun.identity.sm.ServiceNotFoundException in project OpenAM by OpenRock.
the class SMSFlatFileObject method read.
/**
* Reads in attributes of a configuration object.
*
* @return A Map with the coniguration object's attributes or null if the
* configuration object does not exist or no attributes are found.
*
* @param token Ignored argument. Access check is assumed to have
* occurred before reaching this method.
* @param objName Name of the configuration object, expected to be a dn.
*
* @throws SMSException if an IO error occurred during the read.
* @throws SchemaException if a format error occurred while reading the
* attributes properties file.
* @throws IllegalArgumentException if objName argument is null or empty.
*/
public Map read(SSOToken token, String objName) throws SMSException, SSOException {
// check args
if (objName == null || objName.length() == 0) {
throw new IllegalArgumentException("SMSFlatFileObject.read: object name is null or empty.");
}
String objKey = objName.toLowerCase();
Map attrMap = null;
mRWLock.readRequest();
try {
// check if object exists.
String filepath = mNameMap.getProperty(objKey);
if (filepath == null) {
if (mDebug.messageEnabled()) {
mDebug.message("SMSFlatFileObject.read: object " + objName + " not found.");
}
} else {
// Read in file as properties.
File filehandle = new File(filepath);
Properties props = null;
try {
props = loadProperties(filehandle, objName);
} catch (ServiceNotFoundException e) {
// props will be null if object does not exist and
// this func subsequently returns null
}
// convert each value string to a Set.
if (props != null) {
attrMap = new CaseInsensitiveHashMap();
Enumeration keys = props.propertyNames();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
String vals = props.getProperty(key);
if ((vals != null) && (vals.length() > 0)) {
attrMap.put(key, toValSet(key, vals));
}
}
}
}
} finally {
mRWLock.readDone();
}
return attrMap;
}
Aggregations