Search in sources :

Example 1 with MyConfigurationException

use of edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException in project OA4MP by ncsa.

the class CopyTool method getEnv.

protected ServiceEnvironmentImpl getEnv(String cfgFileOption, String cfgNameOption) {
    if (getCommandLine().getOptionValue(SOURCE_CONFIG_NAME_OPTION).equals(getCommandLine().getOptionValue(TARGET_CONFIG_NAME_OPTION))) {
        throw new MyConfigurationException("Error! You have specified that source and target as the same.");
    }
    String fileName = getCommandLine().getOptionValue(cfgFileOption);
    if (fileName == null) {
        fileName = getCommandLine().getOptionValue(SOURCE_CONFIG_FILE_OPTION);
    }
    String configName = getCommandLine().getOptionValue(cfgNameOption);
    sayv("loading configuration \"" + (configName == null ? "(none)" : configName) + "\" from file " + fileName);
    ConfigurationNode node = ConfigUtil.findConfiguration(fileName, getCommandLine().getOptionValue(cfgNameOption), OA4MPConfigTags.COMPONENT);
    // override the logging in the configuration file, since that might be remote.
    ConfigurationLoader loader = null;
    setConfigurationNode(node);
    try {
        loader = getLoader();
    } catch (Exception e) {
        throw new GeneralException("Error: Could not get loader", e);
    }
    // new CILogonConfigurationLoader(node, getMyLogger());
    ServiceEnvironmentImpl env = (ServiceEnvironmentImpl) loader.load();
    return env;
}
Also used : MyConfigurationException(edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException) GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) ConfigurationNode(org.apache.commons.configuration.tree.ConfigurationNode) ConfigurationLoader(edu.uiuc.ncsa.security.core.util.ConfigurationLoader) OA4MPConfigurationLoader(edu.uiuc.ncsa.myproxy.oa4mp.loader.OA4MPConfigurationLoader) MyConfigurationException(edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException) GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException)

Example 2 with MyConfigurationException

use of edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException in project OA4MP by ncsa.

the class AbstractClientBootstrapper method getConfigurationLoader.

@Override
public ConfigurationLoader getConfigurationLoader(ServletContext servletContext) throws Exception {
    MyLoggingFacade logger = new MyLoggingFacade(getClass().getSimpleName());
    logger.info("Starting to load configuration");
    try {
        ConfigurationLoader x = getConfigurationLoader(ServletConfigUtil.findConfigurationNode(servletContext, getOa4mpConfigFileKey(), getOa4mpConfigNameKey(), ClientXMLTags.COMPONENT));
        logger.info("Loaded configuration named " + servletContext.getInitParameter(getOa4mpConfigNameKey()) + " from file " + servletContext.getInitParameter(getOa4mpConfigFileKey()));
        return x;
    } catch (MyConfigurationException ce) {
        logger.info("Did not find a configuration via the servlet context:" + ce.getMessage());
    }
    logger.info("No configuration found in servlet context. Trying default locations");
    // That didn't work, so try to look for it in a few other places.
    String configName = servletContext.getInitParameter(getOa4mpConfigNameKey());
    ConfigurationLoader loader = loadFromDefaultLocations(logger, configName);
    if (loader != null) {
        return loader;
    }
    MyConfigurationException cx = new MyConfigurationException("Error: No configuration found anyplace. OA4MP client startup aborted!");
    logger.error(cx);
    throw cx;
}
Also used : MyLoggingFacade(edu.uiuc.ncsa.security.core.util.MyLoggingFacade) MyConfigurationException(edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException) ConfigurationLoader(edu.uiuc.ncsa.security.core.util.ConfigurationLoader)

Example 3 with MyConfigurationException

use of edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException in project OA4MP by ncsa.

the class ClientLoader method checkPublicKey.

protected PublicKey checkPublicKey() throws IOException {
    String publicKeyFileName = getCfgValue(ClientXMLTags.PUBLIC_KEY);
    if (trivial(publicKeyFileName)) {
        throw new MyConfigurationException("Error: There is no public key specified.");
    }
    File publicKeyFile = new File(publicKeyFileName);
    if (!publicKeyFile.exists()) {
        throw new MyConfigurationException("Error: The specified public key file \"" + publicKeyFileName + "\" does not exist");
    }
    if (!publicKeyFile.isFile()) {
        throw new MyConfigurationException("Error: The specified public key file \"" + publicKeyFileName + "\" is not actually a file");
    }
    if (!publicKeyFile.canRead()) {
        throw new MyConfigurationException("Error: The specified public key file \"" + publicKeyFileName + "\" is not readable. Check the permissions.");
    }
    return KeyUtil.fromX509PEM(new FileReader(publicKeyFile));
}
Also used : MyConfigurationException(edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException) FileReader(java.io.FileReader) File(java.io.File)

Example 4 with MyConfigurationException

use of edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException in project OA4MP by ncsa.

the class FSCAStoreTest method testPermissions.

public void testPermissions() throws Exception {
    File storeDirectory = File.createTempFile("fs-store", "-tmp");
    File indexDirectory = File.createTempFile("fs-index", "-tmp");
    storeDirectory.setWritable(false);
    indexDirectory.setWritable(false);
    assert !storeDirectory.canWrite();
    FSClientApprovalStore x = null;
    final ClientApprovalProvider caProvider = new ClientApprovalProvider();
    try {
        // Make sure that if someone creates a bad one, it blows up in the constructor.
        x = new FSClientApprovalStore(null, null, null, null) {

            @Override
            public Object put(Object key, Object value) {
                return null;
            }
        };
        assert false : "Could make a new object without being properly configured";
    } catch (MyConfigurationException xx) {
        assert true;
    }
    x = new DSFSClientApprovalStore(storeDirectory, indexDirectory, caProvider, new ClientApproverConverter(caProvider));
    try {
        // should bomb here.
        x.create();
        assert false;
    } catch (FilePermissionsException xx) {
        assert true;
    }
    // so make a new entry and then have retrieving it fail.
    storeDirectory.setWritable(true);
    indexDirectory.setWritable(true);
    ClientApproval ca = (ClientApproval) x.create();
    // fail for store directory un readable
    storeDirectory.setReadable(false);
    try {
        x.get(ca.getIdentifier());
        assert false;
    } catch (FilePermissionsException xx) {
        assert true;
    }
}
Also used : MyConfigurationException(edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException) DSFSClientApprovalStore(edu.uiuc.ncsa.myproxy.oa4mp.server.storage.filestore.DSFSClientApprovalStore) FSClientApprovalStore(edu.uiuc.ncsa.security.delegation.server.storage.impl.FSClientApprovalStore) ClientApproval(edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval) FilePermissionsException(edu.uiuc.ncsa.security.core.exceptions.FilePermissionsException) DSFSClientApprovalStore(edu.uiuc.ncsa.myproxy.oa4mp.server.storage.filestore.DSFSClientApprovalStore) ClientApproverConverter(edu.uiuc.ncsa.myproxy.oa4mp.server.util.ClientApproverConverter) ClientApprovalProvider(edu.uiuc.ncsa.myproxy.oa4mp.server.ClientApprovalProvider) File(java.io.File)

Example 5 with MyConfigurationException

use of edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException in project OA4MP by ncsa.

the class TestUtils method findConfigNode.

/**
 * Loads a given configuration from a specified (on the command line) file.
 * Generally you should stick all of your configurations for a test run in a single
 * file then use this to pull off the ones you need, by name. If you do not specify a name
 * this will try to get a configuration with the name specified at the command line.
 *
 * @param configName
 * @return
 */
public static ConfigurationNode findConfigNode(String configName) {
    try {
        String fileName = System.getProperty(getBootstrapper().getOa4mpConfigFileKey());
        if (fileName == null) {
            throw new MyConfigurationException("Error: No configuration file specified");
        }
        XMLConfiguration cfg = null;
        if (fileName.length() != 0) {
            // A properties file is supplied. Use that.
            try {
                cfg = Configurations.getConfiguration(new File(fileName));
            } catch (MyConfigurationException cx) {
                cx.printStackTrace();
                // plan B, maybe it's in the deployment itself? try to get as a resource
                URL url = TestUtils.class.getResource(fileName);
                if (url == null) {
                    throw new MyConfigurationException("Error:No configuration found. for \"" + fileName + "\"");
                }
                cfg = Configurations.getConfiguration(url);
            }
        } else {
            throw new MyConfigurationException("Error:No configuration file found.");
        }
        ConfigurationNode cn = null;
        if (configName == null) {
            // try to find a specified configuration.
            String cfgName = System.getProperty(getBootstrapper().getOa4mpConfigNameKey());
            if (cfgName == null) {
                System.out.println("no name for a configuration given");
                cn = cfg.configurationAt(COMPONENT).getRootNode();
            } else {
                System.out.println("getting named configuration \"" + cfgName + "\"");
                cn = Configurations.getConfig(cfg, COMPONENT, cfgName);
            }
        } else {
            cn = Configurations.getConfig(cfg, COMPONENT, configName);
        }
        return cn;
    } catch (Exception x) {
        throw new MyConfigurationException("Error loading configuration", x);
    }
}
Also used : MyConfigurationException(edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) ConfigurationNode(org.apache.commons.configuration.tree.ConfigurationNode) File(java.io.File) URL(java.net.URL) MyConfigurationException(edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException)

Aggregations

MyConfigurationException (edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException)8 File (java.io.File)5 ClientApprovalProvider (edu.uiuc.ncsa.myproxy.oa4mp.server.ClientApprovalProvider)2 DSFSClientApprovalStore (edu.uiuc.ncsa.myproxy.oa4mp.server.storage.filestore.DSFSClientApprovalStore)2 ClientApproverConverter (edu.uiuc.ncsa.myproxy.oa4mp.server.util.ClientApproverConverter)2 FilePermissionsException (edu.uiuc.ncsa.security.core.exceptions.FilePermissionsException)2 ConfigurationLoader (edu.uiuc.ncsa.security.core.util.ConfigurationLoader)2 ClientApproval (edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval)2 FSClientApprovalStore (edu.uiuc.ncsa.security.delegation.server.storage.impl.FSClientApprovalStore)2 FileReader (java.io.FileReader)2 ConfigurationNode (org.apache.commons.configuration.tree.ConfigurationNode)2 ClientEnvironment (edu.uiuc.ncsa.myproxy.oa4mp.client.ClientEnvironment)1 OA4MPConfigurationLoader (edu.uiuc.ncsa.myproxy.oa4mp.loader.OA4MPConfigurationLoader)1 GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)1 MyLoggingFacade (edu.uiuc.ncsa.security.core.util.MyLoggingFacade)1 IOException (java.io.IOException)1 URL (java.net.URL)1 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)1