Search in sources :

Example 1 with ServiceNotFoundException

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);
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) Set(java.util.Set) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 2 with ServiceNotFoundException

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);
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) CaseInsensitiveTreeSet(com.sun.identity.common.CaseInsensitiveTreeSet) Set(java.util.Set) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) Iterator(java.util.Iterator) CaseInsensitiveTreeSet(com.sun.identity.common.CaseInsensitiveTreeSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet)

Example 3 with ServiceNotFoundException

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();
    }
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) CaseInsensitiveTreeSet(com.sun.identity.common.CaseInsensitiveTreeSet) Set(java.util.Set) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) Properties(java.util.Properties) File(java.io.File)

Example 4 with ServiceNotFoundException

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;
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) SchemaException(com.sun.identity.sm.SchemaException) CaseInsensitiveTreeSet(com.sun.identity.common.CaseInsensitiveTreeSet) Set(java.util.Set) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) CaseInsensitiveTreeSet(com.sun.identity.common.CaseInsensitiveTreeSet) File(java.io.File)

Example 5 with ServiceNotFoundException

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);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) SMSException(com.sun.identity.sm.SMSException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) SSOException(com.iplanet.sso.SSOException)

Aggregations

ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)24 Set (java.util.Set)10 SMSException (com.sun.identity.sm.SMSException)8 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)8 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)6 ServiceConfig (com.sun.identity.sm.ServiceConfig)6 HashSet (java.util.HashSet)6 CaseInsensitiveTreeSet (com.sun.identity.common.CaseInsensitiveTreeSet)5 File (java.io.File)5 Properties (java.util.Properties)5 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)4 ResourceException (org.forgerock.json.resource.ResourceException)4 SSOException (com.iplanet.sso.SSOException)3 SSOToken (com.iplanet.sso.SSOToken)3 CaseInsensitiveProperties (com.sun.identity.common.CaseInsensitiveProperties)3 JsonValue (org.forgerock.json.JsonValue)3 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)3