List of usage examples for org.apache.commons.configuration2.builder.fluent Configurations Configurations
public Configurations()
From source file:org.apache.activemq.artemis.cli.commands.user.FileBasedSecStoreConfig.java
FileBasedSecStoreConfig(File userFile, File roleFile) throws Exception { Configurations configs = new Configurations(); userBuilder = configs.propertiesBuilder(userFile); roleBuilder = configs.propertiesBuilder(roleFile); userConfig = userBuilder.getConfiguration(); roleConfig = roleBuilder.getConfiguration(); String roleHeader = roleConfig.getLayout().getHeaderComment(); String userHeader = userConfig.getLayout().getHeaderComment(); if (userHeader == null) { if (userConfig.isEmpty()) { //clean and reset header userConfig.clear();/*from ww w . ja va 2 s. com*/ userConfig.setHeader(LICENSE_HEADER); } } if (roleHeader == null) { if (roleConfig.isEmpty()) { //clean and reset header roleConfig.clear(); roleConfig.setHeader(LICENSE_HEADER); } } }
From source file:org.apache.activemq.artemis.spi.core.security.jaas.PropertiesLoginModuleConfigurator.java
public PropertiesLoginModuleConfigurator(String entryName, String brokerEtc) throws Exception { if (entryName == null || entryName.length() == 0) { entryName = "activemq"; }//from w w w .j a va 2 s . c o m Configuration securityConfig = Configuration.getConfiguration(); AppConfigurationEntry[] entries = securityConfig.getAppConfigurationEntry(entryName); if (entries == null || entries.length == 0) { throw ActiveMQMessageBundle.BUNDLE.failedToLoadSecurityConfig(); } int entriesInspected = 0; for (AppConfigurationEntry entry : entries) { entriesInspected++; if (entry.getLoginModuleName().equals(PropertiesLoginModule.class.getName())) { String userFileName = (String) entry.getOptions().get(USER_FILE_PROP_NAME); String roleFileName = (String) entry.getOptions().get(ROLE_FILE_PROP_NAME); File etcDir = new File(brokerEtc); File userFile = new File(etcDir, userFileName); File roleFile = new File(etcDir, roleFileName); if (!userFile.exists()) { throw ActiveMQMessageBundle.BUNDLE.failedToLoadUserFile(brokerEtc + userFileName); } if (!roleFile.exists()) { throw ActiveMQMessageBundle.BUNDLE.failedToLoadRoleFile(brokerEtc + roleFileName); } Configurations configs = new Configurations(); userBuilder = configs.propertiesBuilder(userFile); roleBuilder = configs.propertiesBuilder(roleFile); userConfig = userBuilder.getConfiguration(); roleConfig = roleBuilder.getConfiguration(); String roleHeader = roleConfig.getLayout().getHeaderComment(); String userHeader = userConfig.getLayout().getHeaderComment(); if (userHeader == null) { if (userConfig.isEmpty()) { //clean and reset header userConfig.clear(); userConfig.setHeader(LICENSE_HEADER); } } if (roleHeader == null) { if (roleConfig.isEmpty()) { //clean and reset header roleConfig.clear(); roleConfig.setHeader(LICENSE_HEADER); } } return; } } if (entriesInspected == entries.length) { throw ActiveMQMessageBundle.BUNDLE.failedToFindLoginModuleEntry(entryName); } }
From source file:org.apache.activemq.artemis.util.FileBasedSecStoreConfig.java
public FileBasedSecStoreConfig(File userFile, File roleFile) throws Exception { Configurations configs = new Configurations(); userBuilder = configs.propertiesBuilder(userFile); roleBuilder = configs.propertiesBuilder(roleFile); userConfig = userBuilder.getConfiguration(); roleConfig = roleBuilder.getConfiguration(); String roleHeader = roleConfig.getLayout().getHeaderComment(); String userHeader = userConfig.getLayout().getHeaderComment(); if (userHeader == null) { if (userConfig.isEmpty()) { //clean and reset header userConfig.clear();/*w w w . ja va2s . c o m*/ userConfig.setHeader(LICENSE_HEADER); } } if (roleHeader == null) { if (roleConfig.isEmpty()) { //clean and reset header roleConfig.clear(); roleConfig.setHeader(LICENSE_HEADER); } } }
From source file:org.apache.activemq.cli.test.ArtemisTest.java
private void checkRole(String user, File roleFile, String... roles) throws Exception { Configurations configs = new Configurations(); FileBasedConfigurationBuilder<PropertiesConfiguration> roleBuilder = configs.propertiesBuilder(roleFile); PropertiesConfiguration roleConfig = roleBuilder.getConfiguration(); for (String r : roles) { String storedUsers = (String) roleConfig.getProperty(r); System.out.println("users in role: " + r + " ; " + storedUsers); List<String> userList = StringUtil.splitStringList(storedUsers, ","); assertTrue(userList.contains(user)); }/*from w w w .j av a2 s . c om*/ }
From source file:org.apache.activemq.cli.test.ArtemisTest.java
private boolean checkPassword(String user, String password, File userFile) throws Exception { Configurations configs = new Configurations(); FileBasedConfigurationBuilder<PropertiesConfiguration> userBuilder = configs.propertiesBuilder(userFile); PropertiesConfiguration userConfig = userBuilder.getConfiguration(); String storedPassword = (String) userConfig.getProperty(user); HashProcessor processor = PasswordMaskingUtil.getHashProcessor(storedPassword); return processor.compare(password.toCharArray(), storedPassword); }
From source file:org.dspace.servicemanager.config.DSpaceConfigurationServiceTest.java
/** * Tests the ability of our ConfigurationService to automatically reload properties after a set period * of time./*w w w .j a v a2 s. c o m*/ */ @Test public void testAutomaticReload() throws ConfigurationException, InterruptedException { // Initialize new config service DSpaceConfigurationService dscs = new DSpaceConfigurationService(); // Assert a property exists with a specific initial value assertNotNull(dscs.getProperty("prop.to.auto.reload")); assertEquals("D-space", dscs.getProperty("prop.to.auto.reload")); // Now, change the value of that Property in the file itself (using a separate builder instance) FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new Configurations() .propertiesBuilder(propertyFilePath); PropertiesConfiguration config = builder.getConfiguration(); // Clear out current value. Add in a new value config.clearProperty("prop.to.auto.reload"); config.addProperty("prop.to.auto.reload", "DSpace"); // Save updates to file builder.save(); // Check immediately. Property should be unchanged // NOTE: If this fails, then somehow the configuration reloaded *immediately* assertEquals("D-space", dscs.getProperty("prop.to.auto.reload")); // Wait now for 3 seconds Thread.sleep(3_000); // Check again. Property should have reloaded // NOTE: reload time is set in config-definition.xml to reload every 2 seconds assertEquals("DSpace", dscs.getProperty("prop.to.auto.reload")); }
From source file:org.eclipse.winery.repository.configuration.Environment.java
/** * Overwrite configuration parameters by using the given file * * @param path a path pointing to a file where the configuration should be read from *//*from ww w . j av a2 s .c o m*/ public static void copyConfiguration(Path path) throws Exception { Configurations configs = new Configurations(); Configuration configuration = configs.properties(path.toFile()); copyConfiguration(configuration); }
From source file:org.eclipse.winery.repository.configuration.Environment.java
/** * Overwrite configuration parameters by using the given URL * * @param url a URL pointing to a file where the configuration should be read from *//*from w ww . j a va2 s .c o m*/ public static void copyConfiguration(URL url) throws Exception { Configurations configs = new Configurations(); Configuration configuration = configs.properties(url); copyConfiguration(configuration); }
From source file:org.mitre.mpf.wfm.util.TestPropertiesUtil.java
@Test public void testBuilderSave() throws ConfigurationException, IOException { ImmutableConfiguration mpfPropertiesconfig = mpfPropertiesConfigurationBuilder.getCompleteConfiguration(); List<PropertyModel> newCustomPropertyModels = new ArrayList<>(); newCustomPropertyModels.add(new PropertyModel(FRAME_INTERVAL_KEY, "4", false)); newCustomPropertyModels.add(new PropertyModel(MODELS_DIR_KEY, "${" + SHARE_PATH_KEY + "}/new/dir/", false)); newCustomPropertyModels.add(new PropertyModel(TIMEOUT_KEY, "60", false)); ImmutableConfiguration newMpfPropertiesConfig = mpfPropertiesConfigurationBuilder .setAndSaveCustomProperties(newCustomPropertyModels); String mpfHome = System.getenv(MPF_HOME_ENV_VAR); Assert.assertNotNull(mpfHome);//from w w w . j ava 2 s. c o m // ensure that current config isn't modified Assert.assertEquals(1, mpfPropertiesconfig.getInt(FRAME_INTERVAL_KEY)); Assert.assertEquals(mpfHome + "/share/models/", mpfPropertiesconfig.getString(MODELS_DIR_KEY)); Assert.assertEquals(30, mpfPropertiesconfig.getInt(TIMEOUT_KEY)); // get updated config mpfPropertiesconfig = newMpfPropertiesConfig; // mpfPropertiesConfigurationBuilder.getConfiguration(); // ensure detection value sticks Assert.assertEquals(4, mpfPropertiesconfig.getInt(FRAME_INTERVAL_KEY)); // ensure that interpolation is performed on recently-set values Assert.assertEquals(mpfHome + "/share/new/dir/", mpfPropertiesconfig.getString(MODELS_DIR_KEY)); // ensure non-detection value doesn't stick Assert.assertEquals(30, mpfPropertiesconfig.getInt(TIMEOUT_KEY)); // ensure all values written to disk Configurations configs = new Configurations(); FileBasedConfigurationBuilder<PropertiesConfiguration> mpfCustomPropertiesConfigBuilder = configs .propertiesBuilder(customPropFile.getURL()); Configuration mpfCustomPropertiesConfig = mpfCustomPropertiesConfigBuilder.getConfiguration(); Assert.assertEquals(4, mpfCustomPropertiesConfig.getInt(FRAME_INTERVAL_KEY)); Assert.assertEquals("${" + SHARE_PATH_KEY + "}/new/dir/", mpfCustomPropertiesConfig.getString(MODELS_DIR_KEY)); Assert.assertEquals(60, mpfCustomPropertiesConfig.getInt(TIMEOUT_KEY)); // reset mpfCustomPropertiesConfig.clear(); mpfCustomPropertiesConfigBuilder.save(); }
From source file:org.mobicents.media.server.bootstrap.configuration.XmlConfigurationLoader.java
public XmlConfigurationLoader() { this.configurations = new Configurations(); }