use of com.sun.identity.sm.ServiceNotFoundException in project OpenAM by OpenRock.
the class AMIdentity method serviceHasSubSchema.
/**
* Returns true if the service has the subSchema. False otherwise.
*
* @param token
* SSOToken a valid SSOToken
* @param serviceName
* the service name
* @param schemaType
* service schema type (Dynamic, Policy etc)
* @return true if the service has the subSchema.
*/
private boolean serviceHasSubSchema(SSOToken token, String serviceName, SchemaType schemaType) throws SMSException, SSOException {
boolean schemaTypeFlg = false;
try {
ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
Set types = ssm.getSchemaTypes();
if (debug.messageEnabled()) {
debug.message("AMServiceUtils.serviceHasSubSchema() " + "SchemaTypes types for " + serviceName + " are: " + types);
}
schemaTypeFlg = types.contains(schemaType);
} catch (ServiceNotFoundException ex) {
if (debug.warningEnabled()) {
debug.warning("AMServiceUtils.serviceHasSubSchema() " + "Service does not exist : " + serviceName);
}
}
return (schemaTypeFlg);
}
use of com.sun.identity.sm.ServiceNotFoundException in project OpenAM by OpenRock.
the class SMSFlatFileObjectBase method searchOrgs.
private Set<String> searchOrgs(SSOToken token, String objName, String filter, int numOfEntries, boolean sortResults, boolean ascendingOrder, boolean recursive, String serviceName, String attrName, Set values) throws SMSException, SSOException {
// Check the args
if ((objName == null) || (objName.length() == 0) || (filter == null) || (filter.length() == 0) || (numOfEntries < 0)) {
throw new IllegalArgumentException("SMSFlatFileObject.searchOrganizationNames(): " + "One or more arguments is null or empty: " + "objName [" + objName == null ? "null" : objName + "] filter ]" + filter == null ? "null" : filter + "]");
}
// For org search the filter prefix would be "o="
// However for root realm it would be "ou=" when search is performed
String fPrefix = "o=";
String sidFilter = null;
// construct the filename filter
if ((serviceName != null) && (attrName != null) && (values != null) && !values.isEmpty()) {
sidFilter = serviceName + "-" + attrName + "=" + values.iterator().next();
if (objName.equalsIgnoreCase(mRootDN)) {
fPrefix = "ou=";
}
}
Set<String> subentries = null;
if (sortResults) {
subentries = new CaseInsensitiveTreeSet(ascendingOrder);
} else {
subentries = new CaseInsensitiveHashSet();
}
try {
Set entries = getSubEntries(objName, fPrefix + filter, sidFilter, false, numOfEntries, sortResults, ascendingOrder);
// to make it a full DN
for (Iterator i = entries.iterator(); i.hasNext(); ) {
String suborg = (String) i.next();
subentries.add(fPrefix + suborg + "," + objName);
}
if (recursive) {
// Get the list if sub-orgs and search
Set<String> subOrgs = new HashSet();
if (!filter.equals("*") || (sidFilter != null)) {
Set ssubOrgs = getSubEntries(objName, fPrefix + "*", null, false, 0, sortResults, ascendingOrder);
for (Iterator i = ssubOrgs.iterator(); i.hasNext(); ) {
String suborg = (String) i.next();
subOrgs.add(fPrefix + suborg + "," + objName);
}
} else {
subOrgs.addAll(subentries);
}
for (String subOrgName : subOrgs) {
int reqEntries = (numOfEntries == 0) ? numOfEntries : numOfEntries - subentries.size();
if (numOfEntries < 0) {
break;
}
Set<String> subsubentries = searchOrgs(token, subOrgName, filter, reqEntries, sortResults, ascendingOrder, recursive, serviceName, attrName, values);
subentries.addAll(subsubentries);
}
}
} catch (ServiceNotFoundException e) {
// return empty set if object does not exist.
subentries = new CaseInsensitiveHashSet<>();
}
if (mDebug.messageEnabled()) {
mDebug.message("SMSFlatFileObject:searchOrgs " + "search " + filter + " for " + objName + " returned " + subentries.size() + " items");
}
return (subentries);
}
use of com.sun.identity.sm.ServiceNotFoundException in project OpenAM by OpenRock.
the class SMSEnhancedFlatFileObject method modify.
/**
* Modifies 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("SMSEnhancedFlatFileObject.modify: " + "One or more arguments is null or empty");
}
mRWLock.readRequest();
try {
if (!root.isExists(mRootDir, objName)) {
String errmsg = "SMSEnhancedFlatFileObject.modify: object " + objName + " not found.";
mDebug.error(errmsg);
throw new ServiceNotFoundException(errmsg);
}
} finally {
mRWLock.readDone();
}
mRWLock.writeRequest();
try {
SMSFlatFileTreeNode node = root.getChild(objName);
if (node == null) {
String errmsg = "SMSEnhancedFlatFileObject.modify: object " + objName + " not found.";
mDebug.error(errmsg);
throw new ServiceNotFoundException(errmsg);
}
String filepath = node.getAttributeFilename(mRootDir);
if (filepath == null) {
String errmsg = "SMSEnhancedFlatFileObject.modify: object " + objName + " not found.";
mDebug.error(errmsg);
throw new ServiceNotFoundException(errmsg);
}
File filehandle = new File(filepath);
if (!filehandle.isFile()) {
String errmsg = "SMSEnhancedFlatFileObject.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;
// 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);
String newSunXMLKeyValue = props.getProperty(SMSEntry.ATTR_XML_KEYVAL);
if (newSunXMLKeyValue != null) {
Set xmlKeyVals = toValSet(SMSEntry.ATTR_XML_KEYVAL, newSunXMLKeyValue);
if (!hasSunXmlKeyValue) {
deleteSunXmlKeyValFiles(node);
}
createSunXmlKeyValFiles(node, xmlKeyVals);
saveDirectoryTree();
}
} finally {
mRWLock.writeDone();
}
}
use of com.sun.identity.sm.ServiceNotFoundException in project OpenAM by OpenRock.
the class SMSFlatFileObject method getSubEntries.
/**
* Real routine to get sub entries, used by subEntries() and
* schemaSubEntries().
*
* @throws ServiceNotFoundException if the configuration object is
* not found.
* @throws SchemaException if a sub directory name is not in the
* expected "ou=..." format.
*/
protected Set getSubEntries(String objName, String filter, String sidFilter, boolean isSubConfig, int numOfEntries, boolean sortResults, boolean ascendingOrder) throws SMSException {
String objKey = objName.toLowerCase();
Set subentries = null;
// wait indefinitely for the read lock.
mRWLock.readRequest();
try {
// Check if object exists.
String filepath = mNameMap.getProperty(objKey);
if (filepath == null) {
String errmsg = "SMSFlatFileObjectBase.getSubEntries: " + objName + " : not found in objects map.";
mDebug.warning(errmsg);
throw new ServiceNotFoundException(errmsg);
}
File filehandle = new File(filepath);
File parentDir = filehandle.getParentFile();
if (!parentDir.isDirectory()) {
String errmsg = "SMSFlatFileObject.getSubEntries: " + objName + " : " + filehandle.getPath() + " does not exist or is not a directory.";
mDebug.error(errmsg);
throw new ServiceNotFoundException(errmsg);
}
// Create file filter for filter and sid filter.
FilenameFilter subentFileFilter = new FilenameFilter(filter);
FilenameFilter sidFileFilter = null;
if (sidFilter != null && sidFilter.length() > 0) {
// are encoded.
if (isSubConfig) {
sidFileFilter = new FilenameFilter(SMSEntry.ATTR_SERVICE_ID + "=" + sidFilter.toLowerCase());
} else {
sidFileFilter = new FilenameFilter(SMSEntry.ATTR_XML_KEYVAL + "=" + sidFilter.toLowerCase());
}
}
// Create set for return, use sorted set if sortResults is true.
if (sortResults) {
subentries = new CaseInsensitiveTreeSet(ascendingOrder);
} else {
subentries = new CaseInsensitiveHashSet();
}
// Set all entries that match filter, and that match
// sunserviceid/sunxmlkeyvalye if sidFilter was not null.
File[] subentriesFound = parentDir.listFiles(subentFileFilter);
int numEntriesAdded = 0;
boolean done = false;
for (int i = 0; (i < subentriesFound.length) && !done; i++) {
File[] sunserviceidFiles = null;
if (sidFileFilter == null || ((sunserviceidFiles = subentriesFound[i].listFiles(sidFileFilter)) != null && sunserviceidFiles.length > 0)) {
String filename = subentriesFound[i].getName();
int equalSign = filename.indexOf('=');
if (equalSign < 0 || equalSign == (filename.length() - 1)) {
String errmsg = "SMSFlatFileObject.getSubEntries: " + "Invalid sub entry name found: " + filename;
mDebug.error(errmsg);
throw new SchemaException(errmsg);
}
String subentryname = FileNameDecoder.decode(filename.substring(equalSign + 1));
subentries.add(subentryname);
numEntriesAdded++;
// stop if number of entries requested has been reached.
// if sort results, need to get the whole list first.
done = !sortResults && (numOfEntries > 0) && (numEntriesAdded == numOfEntries);
}
}
if (sortResults && (numOfEntries > 0)) {
// remove extra entries from the bottom.
while ((numEntriesAdded - numOfEntries) > 0) {
Object l = ((CaseInsensitiveTreeSet) subentries).last();
subentries.remove(l);
numEntriesAdded--;
}
}
} finally {
mRWLock.readDone();
}
return subentries;
}
use of com.sun.identity.sm.ServiceNotFoundException in project OpenAM by OpenRock.
the class ScriptingSchemaStep method initialize.
@Override
public void initialize() throws UpgradeException {
try {
captureScriptedAuthModuleConfiguration();
captureDeviceIdMatchConfiguration();
} catch (ServiceNotFoundException e) {
DEBUG.message("Scripted auth modules not found. Nothing to upgrade", e);
} catch (SMSException | SSOException e) {
DEBUG.error("An error occurred while trying to look for upgradable global Scripting settings", e);
throw new UpgradeException("Unable to retrieve global Scripting settings", e);
}
}
Aggregations