Search in sources :

Example 11 with ConfigurationNode

use of org.apache.commons.configuration.tree.ConfigurationNode 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)

Example 12 with ConfigurationNode

use of org.apache.commons.configuration.tree.ConfigurationNode in project OA4MP by ncsa.

the class Monitor method initialize.

@Override
public void initialize() throws Exception {
    super.initialize();
    // Allow for over-riding the log file from the command line.
    if (getLogfileName().equals(DEFAULT_LOG_FILE)) {
        setMyLogger(getEnvironment().getMyLogger());
    } else {
        File f = new File(getLogfileName());
        info("Setting up environment, log file = " + f.getAbsolutePath());
    }
    String cfgName = null;
    if (hasOption(CONFIG_NAME_OPTION, CONFIG_NAME_LONG_OPTION)) {
        cfgName = getCommandLine().getOptionValue(CONFIG_NAME_OPTION);
    }
    if (cfgName == null) {
        info("no named for a configuration given");
    } else {
        info("getting named configuration \"" + cfgName + "\"");
    }
    try {
        List list = getConfigurationNode().getChildren("mail");
        if (list.size() != 0) {
            mup = new MailUtilProvider((ConfigurationNode) list.get(0));
        }
    } catch (Throwable t) {
        info("Did not initialize a mail notification environment:" + t.getMessage());
    }
    serviceClient = ((AbstractClientLoader) getLoader()).createServiceClient(getClientEnvironment().getAccessTokenUri());
    info("Done with bootstrap.");
}
Also used : MailUtilProvider(edu.uiuc.ncsa.security.util.mail.MailUtilProvider) ConfigurationNode(org.apache.commons.configuration.tree.ConfigurationNode) List(java.util.List) File(java.io.File)

Example 13 with ConfigurationNode

use of org.apache.commons.configuration.tree.ConfigurationNode in project OA4MP by ncsa.

the class XsedeConfigurationLoader method getClaimSource.

@Override
public ClaimSource getClaimSource() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
    if (0 < cn.getChildrenCount("xsedeApi".toString())) {
        ConfigurationNode node = Configurations.getFirstNode(cn, "xsedeApi".toString());
        ConfigurationNode username = Configurations.getFirstNode(node, "username".toString());
        ConfigurationNode password = Configurations.getFirstNode(node, "password".toString());
        ConfigurationNode apikey = Configurations.getFirstNode(node, "api-key".toString());
        ConfigurationNode apihash = Configurations.getFirstNode(node, "api-hash".toString());
        ConfigurationNode apiurl = Configurations.getFirstNode(node, "api-url".toString());
        ConfigurationNode apiresource = Configurations.getFirstNode(node, "api-resource".toString());
        if (apikey != null && apihash != null && apiurl != null && apiresource != null) {
            claimSource = new XsedeClaimsSource(loggerProvider.get(), apikey.getValue().toString(), apihash.getValue().toString(), apiurl.getValue().toString(), apiresource.getValue().toString());
        } else if (username != null && password != null) {
            claimSource = new XsedeClaimsSource(username.getValue().toString(), password.getValue().toString(), loggerProvider.get());
        } else
            throw new InstantiationException("Couldn't find XUP API authentication credentials");
        // scopeHandler.setScopes(Arrays.asList("xsede"));
        // this is a complete list of scopes from the configuration file.
        claimSource.setScopes(getScopes());
        return claimSource;
    } else
        throw new InstantiationException("Couldn't find an XUP API authentication credential");
}
Also used : ConfigurationNode(org.apache.commons.configuration.tree.ConfigurationNode)

Aggregations

ConfigurationNode (org.apache.commons.configuration.tree.ConfigurationNode)13 ConfigTest (edu.uiuc.ncsa.security.core.configuration.ConfigTest)4 List (java.util.List)4 Test (org.junit.Test)4 File (java.io.File)3 GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)2 MyConfigurationException (edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException)2 MyLoggingFacade (edu.uiuc.ncsa.security.core.util.MyLoggingFacade)2 MySQLConnectionPoolProvider (edu.uiuc.ncsa.security.storage.sql.mysql.MySQLConnectionPoolProvider)2 PGConnectionPoolProvider (edu.uiuc.ncsa.security.storage.sql.postgres.PGConnectionPoolProvider)2 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)2 MyProxyServiceFacade (edu.uiuc.ncsa.myproxy.MyProxyServiceFacade)1 ServiceFacadeConfiguration (edu.uiuc.ncsa.myproxy.ServiceFacadeConfiguration)1 OA4MPConfigurationLoader (edu.uiuc.ncsa.myproxy.oa4mp.loader.OA4MPConfigurationLoader)1 ClientApprovalProvider (edu.uiuc.ncsa.myproxy.oa4mp.server.ClientApprovalProvider)1 MyProxyFacadeProvider (edu.uiuc.ncsa.myproxy.oa4mp.server.MyProxyFacadeProvider)1 OA4MPIdentifierProvider (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.transactions.OA4MPIdentifierProvider)1 MultiDSClientApprovalStoreProvider (edu.uiuc.ncsa.myproxy.oa4mp.server.storage.MultiDSClientApprovalStoreProvider)1 MultiDSClientStoreProvider (edu.uiuc.ncsa.myproxy.oa4mp.server.storage.MultiDSClientStoreProvider)1 DSFSClientApprovalStoreProvider (edu.uiuc.ncsa.myproxy.oa4mp.server.storage.filestore.DSFSClientApprovalStoreProvider)1