Search in sources :

Example 1 with MapConfiguration

use of org.apache.commons.configuration.MapConfiguration in project OpenAttestation by OpenAttestation.

the class TAConfig method gatherConfiguration.

private Configuration gatherConfiguration(String propertiesFilename, Properties defaults) {
    CompositeConfiguration composite = new CompositeConfiguration();
    // first priority are properties defined on the current JVM (-D switch or through web container)
    SystemConfiguration system = new SystemConfiguration();
    dumpConfiguration(system, "system");
    composite.addConfiguration(system);
    // second priority are properties defined on the classpath (like user's home directory)        
    try {
        // user's home directory (assuming it's on the classpath!)
        readPropertiesFile("/" + propertiesFilename, composite);
    } catch (IOException ex) {
        log.info("Did not find " + propertiesFilename + " on classpath", ex);
    }
    // third priority are properties defined in standard install location
    System.out.println("TAConfig os.name=" + System.getProperty("os.name"));
    ArrayList<File> files = new ArrayList<File>();
    // windows-specific location
    if (System.getProperty("os.name", "").toLowerCase().equals("win")) {
        System.out.println("TAConfig user.home=" + System.getProperty("user.home"));
        files.add(new File("C:" + File.separator + "Intel" + File.separator + "CloudSecurity" + File.separator + propertiesFilename));
        files.add(new File(System.getProperty("user.home") + File.separator + propertiesFilename));
    }
    // linux-specific location
    if (System.getProperty("os.name", "").toLowerCase().equals("linux") || System.getProperty("os.name", "").toLowerCase().equals("unix")) {
        files.add(new File("./config/" + propertiesFilename));
        files.add(new File("/etc/oat-client/" + propertiesFilename));
    }
    // this line specific to TA for backwards compatibility, not needed in AS/AH
    files.add(new File(System.getProperty("app.path") + File.separator + propertiesFilename));
    // add all the files we found
    for (File f : files) {
        try {
            if (f.exists() && f.canRead()) {
                PropertiesConfiguration standard = new PropertiesConfiguration(f);
                dumpConfiguration(standard, "file:" + f.getAbsolutePath());
                composite.addConfiguration(standard);
            }
        } catch (ConfigurationException ex) {
            log.error(null, ex);
        }
    }
    // last priority are the defaults that were passed in, we use them if no better source was found
    if (defaults != null) {
        MapConfiguration defaultconfig = new MapConfiguration(defaults);
        dumpConfiguration(defaultconfig, "default");
        composite.addConfiguration(defaultconfig);
    }
    dumpConfiguration(composite, "composite");
    return composite;
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) MapConfiguration(org.apache.commons.configuration.MapConfiguration) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) File(java.io.File) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 2 with MapConfiguration

use of org.apache.commons.configuration.MapConfiguration in project OpenAttestation by OpenAttestation.

the class CheckLoginController method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse res) throws Exception {
    logger.info("CheckLoginController >>");
    //Creating ModelAndView Object with Login page to return to user if Login is not successful.
    ModelAndView view = new ModelAndView("Login");
    //RsaCredential credential = null;
    File keystoreFile = null;
    SimpleKeystore keystore = null;
    String username = "admin";
    URL baseURL = new URL(WLMPConfig.getConfiguration().getString("mtwilson.api.baseurl"));
    final String keystoreFilename = WLMPConfig.getConfiguration().getString("mtwilson.wlmp.keystore.dir") + File.separator + "portal.jks";
    final String keystorePassword = WLMPConfig.getConfiguration().getString("mtwilson.wlmp.keystore.password");
    try {
        //this line will throw exception if file with username is not present in specific dir.
        keystoreFile = new File(keystoreFilename);
    } catch (Exception e) {
        logger.severe("File Not found on server >> " + keystoreFilename);
        view.addObject("message", "Key store is not configured/saved correctly in " + keystoreFilename + ".");
        return view;
    }
    try {
        keystore = new SimpleKeystore(keystoreFile, keystorePassword);
    //credential = keystore.getRsaCredentialX509(username, keystorePassword);
    } catch (Exception e) {
        view.addObject("result", false);
        view.addObject("message", "Username or Password does not match. Please try again.");
        return view;
    }
    try {
        Properties p = new Properties();
        // must be secure out of the box!
        p.setProperty("mtwilson.api.ssl.policy", WLMPConfig.getConfiguration().getString("mtwilson.api.ssl.policy", "TRUST_CA_VERIFY_HOSTNAME"));
        // must be secure out of the box!
        p.setProperty("mtwilson.api.ssl.requireTrustedCertificate", WLMPConfig.getConfiguration().getString("mtwilson.api.ssl.requireTrustedCertificate", "true"));
        // must be secure out of the box!
        p.setProperty("mtwilson.api.ssl.verifyHostname", WLMPConfig.getConfiguration().getString("mtwilson.api.ssl.verifyHostname", "true"));
        // Instantiate the API Client object and store it in the session. Otherwise either we need
        // to store the password in the session or the decrypted RSA key
        ApiClient rsaApiClient = new ApiClient(baseURL, keystore, new MapConfiguration(p));
        //Storing variable into a session object used while calling into RESt Services.
        HttpSession session = req.getSession();
        session.setAttribute("logged-in", true);
        session.setAttribute("username", username);
        session.setAttribute("apiClientObject", rsaApiClient);
        session.setMaxInactiveInterval(WLMPConfig.getConfiguration().getInt("mtwilson.wlmp.sessionTimeOut"));
        X509Certificate[] trustedCertificates = keystore.getTrustedCertificates(SimpleKeystore.SAML);
        session.setAttribute("trustedCertificates", trustedCertificates);
        //Redirecting user to a home page after successful login.
        res.sendRedirect("home.html");
    } catch (Exception e) {
        view.addObject("message", "The username or password you entered is incorrect.");
        return view;
    }
    return null;
}
Also used : SimpleKeystore(com.intel.mtwilson.util.crypto.SimpleKeystore) HttpSession(javax.servlet.http.HttpSession) MapConfiguration(org.apache.commons.configuration.MapConfiguration) ModelAndView(org.springframework.web.servlet.ModelAndView) Properties(java.util.Properties) ApiClient(com.intel.mtwilson.ApiClient) File(java.io.File) URL(java.net.URL) X509Certificate(java.security.cert.X509Certificate)

Example 3 with MapConfiguration

use of org.apache.commons.configuration.MapConfiguration in project chassis by Kixeye.

the class DynamicZookeeperConfigurationSourceTest method beforeClass.

@Before
public void beforeClass() throws Exception {
    zookeeper = new TestingServer(SocketUtils.findAvailableTcpPort());
    curatorFramework = CuratorFrameworkFactory.newClient(zookeeper.getConnectString(), new RetryOneTime(1000));
    curatorFramework.start();
    curatorFramework.create().forPath(CONFIG_BASE_PATH);
    Map<String, Object> defaults = new HashMap<>();
    defaults.put(DEF_KEY1, DEF_VAL1);
    defaults.put(DEF_KEY2, DEF_VAL2);
    defaultConfiguration = new MapConfiguration(defaults);
    node = UUID.randomUUID().toString();
    config = new ConcurrentCompositeConfiguration();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) RetryOneTime(org.apache.curator.retry.RetryOneTime) HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration.MapConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) Before(org.junit.Before)

Example 4 with MapConfiguration

use of org.apache.commons.configuration.MapConfiguration in project chassis by Kixeye.

the class ZookeeperConfigurationWriterTest method noBasePathExists.

@Test
public void noBasePathExists() throws Exception {
    Assert.assertNull(curatorFramework.checkExists().forPath(base));
    try (CuratorFramework zkCurator = createCuratorFramework()) {
        ZookeeperConfigurationWriter writer = new ZookeeperConfigurationWriter(applicationName, environmentName, version, zkCurator, false);
        writer.write(new MapConfiguration(props), new DefaultPropertyFilter());
        Assert.assertEquals(val1, new String(curatorFramework.getData().forPath(base + "/" + key1)));
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) MapConfiguration(org.apache.commons.configuration.MapConfiguration) DefaultPropertyFilter(com.kixeye.chassis.bootstrap.configuration.DefaultPropertyFilter) ZookeeperConfigurationWriter(com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationWriter) Test(org.junit.Test)

Example 5 with MapConfiguration

use of org.apache.commons.configuration.MapConfiguration in project chassis by Kixeye.

the class ZookeeperConfigurationWriterTest method partialBasePathExists.

@Test
public void partialBasePathExists() throws Exception {
    Assert.assertNull(curatorFramework.checkExists().forPath(base));
    curatorFramework.create().forPath("/" + environmentName);
    Assert.assertNotNull(curatorFramework.checkExists().forPath("/" + environmentName));
    try (CuratorFramework zkCurator = createCuratorFramework()) {
        ZookeeperConfigurationWriter writer = new ZookeeperConfigurationWriter(applicationName, environmentName, version, zkCurator, false);
        writer.write(new MapConfiguration(props), new DefaultPropertyFilter());
        Assert.assertEquals(val1, new String(curatorFramework.getData().forPath(base + "/" + key1)));
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) MapConfiguration(org.apache.commons.configuration.MapConfiguration) DefaultPropertyFilter(com.kixeye.chassis.bootstrap.configuration.DefaultPropertyFilter) ZookeeperConfigurationWriter(com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationWriter) Test(org.junit.Test)

Aggregations

MapConfiguration (org.apache.commons.configuration.MapConfiguration)12 CuratorFramework (org.apache.curator.framework.CuratorFramework)5 Test (org.junit.Test)5 DefaultPropertyFilter (com.kixeye.chassis.bootstrap.configuration.DefaultPropertyFilter)4 ZookeeperConfigurationWriter (com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationWriter)4 Properties (java.util.Properties)4 HashMap (java.util.HashMap)3 File (java.io.File)2 ApiClient (com.intel.mtwilson.ApiClient)1 SimpleKeystore (com.intel.mtwilson.util.crypto.SimpleKeystore)1 CuratorFrameworkBuilder (com.kixeye.chassis.bootstrap.configuration.zookeeper.CuratorFrameworkBuilder)1 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)1 MetricName (com.yammer.metrics.core.MetricName)1 MetricsRegistry (com.yammer.metrics.core.MetricsRegistry)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 X509Certificate (java.security.cert.X509Certificate)1 ArrayList (java.util.ArrayList)1 HttpSession (javax.servlet.http.HttpSession)1