Search in sources :

Example 16 with ServiceNotFoundException

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

Example 17 with ServiceNotFoundException

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
        }
    }
}
Also used : ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 18 with ServiceNotFoundException

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
            }
        }
    }
}
Also used : CaseInsensitiveProperties(com.sun.identity.common.CaseInsensitiveProperties) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) SystemProperties(com.iplanet.am.util.SystemProperties) CaseInsensitiveProperties(com.sun.identity.common.CaseInsensitiveProperties) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 19 with ServiceNotFoundException

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;
}
Also used : Enumeration(java.util.Enumeration) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) Properties(java.util.Properties) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) File(java.io.File) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

Example 20 with ServiceNotFoundException

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;
}
Also used : Enumeration(java.util.Enumeration) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) Properties(java.util.Properties) CaseInsensitiveProperties(com.sun.identity.common.CaseInsensitiveProperties) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) File(java.io.File) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

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