use of org.apache.felix.utils.properties.Properties in project karaf by apache.
the class ConfigRepositoryImpl method updateStorage.
protected void updateStorage(String pid, Dictionary<String, Object> props) throws IOException {
if (storage != null) {
Configuration cfg = configAdmin.getConfiguration(pid, null);
// Initialize cfgFile with default location. Value gets overwritten when the existing configuration references a correct location.
File cfgFile = new File(storage, pid + ".cfg");
if (cfg != null) {
Dictionary<String, Object> oldProps = cfg.getProperties();
if (oldProps != null && oldProps.get(FILEINSTALL_FILE_NAME) != null) {
try {
cfgFile = getCfgFileFromProperties(oldProps);
if (cfgFile == null) {
throw new IOException("The configuration value '" + oldProps.get(FILEINSTALL_FILE_NAME) + "' for '" + FILEINSTALL_FILE_NAME + "' does not represent a valid file location.");
}
} catch (URISyntaxException | MalformedURLException e) {
throw new IOException(e);
}
}
}
LOGGER.trace("Update {}", cfgFile.getName());
// update the cfg file
Properties properties = new Properties(cfgFile);
for (Enumeration<String> keys = props.keys(); keys.hasMoreElements(); ) {
String key = keys.nextElement();
if (!Constants.SERVICE_PID.equals(key) && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key) && !FILEINSTALL_FILE_NAME.equals(key)) {
if (props.get(key) != null) {
properties.put(key, props.get(key).toString());
}
}
}
// remove "removed" properties from the cfg file
ArrayList<String> propertiesToRemove = new ArrayList<>();
for (String key : properties.keySet()) {
if (props.get(key) == null && !Constants.SERVICE_PID.equals(key) && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key) && !FILEINSTALL_FILE_NAME.equals(key)) {
propertiesToRemove.add(key);
}
}
for (String key : propertiesToRemove) {
properties.remove(key);
}
// save the cfg file
storage.mkdirs();
properties.save();
}
}
use of org.apache.felix.utils.properties.Properties in project karaf by apache.
the class PropertiesLoginModuleTest method testCannotLoginAsGroupDirectly.
private void testCannotLoginAsGroupDirectly(final String name) throws IOException, LoginException {
File f = File.createTempFile(getClass().getName(), ".tmp");
try {
Properties p = new Properties(f);
PropertiesBackingEngine pbe = new PropertiesBackingEngine(p);
pbe.addUser("abc", "xyz");
pbe.addRole("abc", "myrole");
pbe.addUser("pqr", "abc");
pbe.addGroup("pqr", "group1");
pbe.addGroupRole("group1", "r1");
PropertiesLoginModule module = new PropertiesLoginModule();
Map<String, String> options = new HashMap<>();
options.put(PropertiesLoginModule.USER_FILE, f.getAbsolutePath());
module.initialize(new Subject(), new NamePasswordCallbackHandler(name, "group"), null, options);
try {
module.login();
Assert.fail("The login should have failed as you cannot log in under a group name directly");
} catch (FailedLoginException fle) {
// good
}
} finally {
if (!f.delete()) {
Assert.fail("Could not delete temporary file: " + f);
}
}
}
use of org.apache.felix.utils.properties.Properties in project karaf by apache.
the class ConfigProperties method performInit.
public void performInit() throws Exception {
File cleanAllIndicatorFile = new File(karafData, "clean_all");
File cleanCacheIndicatorFile = new File(karafData, "clean_cache");
if (Boolean.getBoolean("karaf.clean.all") || cleanAllIndicatorFile.exists()) {
if (cleanAllIndicatorFile.exists()) {
cleanAllIndicatorFile.delete();
}
Utils.deleteDirectory(this.karafData);
this.karafData = Utils.getKarafDirectory(PROP_KARAF_DATA, ENV_KARAF_DATA, new File(karafBase, "data"), true, true);
} else {
if (Boolean.getBoolean("karaf.clean.cache") || cleanCacheIndicatorFile.exists()) {
if (cleanCacheIndicatorFile.exists()) {
cleanCacheIndicatorFile.delete();
}
File karafCache = Utils.validateDirectoryExists(new File(karafData, "cache").getPath(), "Invalid cache directory", true, true);
Utils.deleteDirectory(karafCache);
}
}
String frameworkStoragePath = props.getProperty(Constants.FRAMEWORK_STORAGE);
if (frameworkStoragePath == null) {
File storage = new File(karafData.getPath(), "cache");
try {
storage.mkdirs();
} catch (SecurityException se) {
throw new Exception(se.getMessage());
}
props.setProperty(Constants.FRAMEWORK_STORAGE, storage.getAbsolutePath());
}
if (shutdownCommand == null || shutdownCommand.isEmpty()) {
try {
shutdownCommand = UUID.randomUUID().toString();
Properties temp = new Properties(new File(karafEtc, CONFIG_PROPERTIES_FILE_NAME));
temp.put(KARAF_SHUTDOWN_COMMAND, Arrays.asList("", "#", "# Generated command shutdown", "#"), shutdownCommand);
temp.save();
} catch (IOException ioException) {
System.err.println("WARN: can't update etc/config.properties with the generated command shutdown. We advise to manually add the karaf.shutdown.command property.");
}
}
if (threadMonitoring) {
ThreadMXBean threadsBean = ManagementFactory.getThreadMXBean();
if (threadsBean.isThreadCpuTimeSupported()) {
threadsBean.setThreadCpuTimeEnabled(true);
}
if (threadsBean.isThreadContentionMonitoringSupported()) {
threadsBean.setThreadContentionMonitoringEnabled(true);
}
}
}
use of org.apache.felix.utils.properties.Properties in project karaf by apache.
the class BootstrapLogManager method getLogFilePath.
String getLogFilePath() {
String filename = configProps == null ? null : configProps.getProperty(KARAF_BOOTSTRAP_LOG);
if (filename != null) {
return filename;
}
Properties props = loadPaxLoggingConfig();
// Make a best effort to log to the default file appender configured for log4j
return props.getProperty(LOG4J_APPENDER_FILE, "${karaf.data}/log/karaf.log");
}
use of org.apache.felix.utils.properties.Properties in project karaf by apache.
the class BootstrapLogManager method loadPaxLoggingConfig.
private Properties loadPaxLoggingConfig() {
Properties props = new Properties();
FileInputStream fis = null;
try {
fis = new FileInputStream(log4jConfigPath);
props.load(fis);
} catch (Exception e) {
// Ignore
} finally {
close(fis);
}
return props;
}
Aggregations