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;
}
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;
}
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();
}
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)));
}
}
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)));
}
}
Aggregations