use of org.apache.commons.configuration2.PropertiesConfiguration in project xwiki-platform by xwiki.
the class XWikiPropertiesConfigurationSource method loadConfiguration.
private Configuration loadConfiguration() {
// Looking for /etc/xwiki/xwiki.properties first
File file = new File("/etc/xwiki/" + XWIKI_PROPERTIES_FILE);
if (file.exists()) {
try {
return new Configurations().properties(file);
} catch (Exception e) {
// Note: if we cannot read the configuration file for any reason we log a warning but continue since
// XWiki will use default values for all configurable elements.
this.logger.warn("Failed to load configuration file [{}]", file, e.getMessage());
}
}
// Register the Commons Properties Configuration, looking for a xwiki.properties file
// in the XWiki path somewhere.
URL xwikiPropertiesUrl = null;
try {
xwikiPropertiesUrl = this.environment.getResource(XWIKI_PROPERTIES_WARPATH);
if (xwikiPropertiesUrl != null) {
FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class).configure(new Parameters().properties().setListDelimiterHandler(new DefaultListDelimiterHandler(',')).setURL(xwikiPropertiesUrl));
return builder.getConfiguration();
} else {
// We use a debug logging level here since we consider it's ok that there's no XWIKI_PROPERTIES_FILE
// available, in which case default values are used.
this.logger.debug("No configuration file [{}] found. Using default configuration values.", XWIKI_PROPERTIES_WARPATH);
}
} catch (Exception e) {
// Note: if we cannot read the configuration file for any reason we log a warning but continue since XWiki
// will use default values for all configurable elements.
this.logger.warn("Failed to load configuration file [{}]. Using default configuration values. " + "Internal error [{}]", XWIKI_PROPERTIES_WARPATH, e.getMessage());
}
// implementation.
return new BaseConfiguration();
}
use of org.apache.commons.configuration2.PropertiesConfiguration in project activemq-artemis by apache.
the class ArtemisTest method checkRole.
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));
}
}
use of org.apache.commons.configuration2.PropertiesConfiguration in project activemq-artemis by apache.
the class ArtemisTest method checkPassword.
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);
}
use of org.apache.commons.configuration2.PropertiesConfiguration in project gocd by gocd.
the class AgentAutoRegistrationPropertiesImpl method scrubRegistrationProperties.
@Override
public void scrubRegistrationProperties() {
if (!exist()) {
return;
}
try {
PropertiesConfiguration config = new PropertiesConfiguration();
config.setIOFactory(new FilteringOutputWriterFactory());
PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout();
layout.setLineSeparator("\n");
layout.load(config, reader());
try (FileWriter out = new FileWriter(this.configFile)) {
layout.save(config, out);
}
loadProperties();
} catch (ConfigurationException | IOException e) {
LOG.warn("[Agent Auto Registration] Unable to scrub registration key.", e);
}
}
use of org.apache.commons.configuration2.PropertiesConfiguration in project vcell by virtualcell.
the class VCellConfiguration method getConfiguration.
private static synchronized Configuration getConfiguration() throws ConfigurationException {
if (configurationBuilder == null) {
Parameters params = new Parameters();
File propertiesFile = new File(ResourceUtil.getVcellHome(), "vcellconfig.properties");
if (!propertiesFile.exists()) {
try {
propertiesFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
FileBasedBuilderParameters thing = params.fileBased().setFile(propertiesFile);
configurationBuilder = new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class).configure(thing);
configurationBuilder.setAutoSave(true);
try {
propertiesConfiguration = configurationBuilder.getConfiguration();
propertiesConfiguration.setSynchronizer(new ReadWriteSynchronizer());
} catch (org.apache.commons.configuration2.ex.ConfigurationException e) {
e.printStackTrace();
throw new ConfigurationException("failed to create configuration from file " + propertiesFile + ": " + e.getMessage());
}
}
return propertiesConfiguration;
}
Aggregations