Search in sources :

Example 46 with Properties

use of org.apache.felix.utils.properties.Properties in project karaf by apache.

the class BootstrapLogManagerTest method testGetLogManagerFromPaxLoggingConfig.

@Test
public void testGetLogManagerFromPaxLoggingConfig() {
    new File("target/test.log").delete();
    Properties configProps = getConfigProperties();
    BootstrapLogManager.setProperties(configProps, "src/test/resources/org.ops4j.pax.logging.cfg");
    Handler handler = BootstrapLogManager.getDefaultHandler();
    Assert.assertNotNull(handler);
    assertExists("target/test.log");
}
Also used : Handler(java.util.logging.Handler) Properties(org.apache.felix.utils.properties.Properties) File(java.io.File) Test(org.junit.Test)

Example 47 with Properties

use of org.apache.felix.utils.properties.Properties in project karaf by apache.

the class BootstrapLogManagerTest method getConfigProperties.

private Properties getConfigProperties() {
    Properties configProps = new Properties();
    configProps.put("karaf.data", "target");
    return configProps;
}
Also used : Properties(org.apache.felix.utils.properties.Properties)

Example 48 with Properties

use of org.apache.felix.utils.properties.Properties in project karaf by apache.

the class BaseJDBCLockTest method setUp.

@Before
public void setUp() throws Exception {
    connection = EasyMock.createNiceMock(Connection.class);
    metaData = EasyMock.createMock(DatabaseMetaData.class);
    resultSet = EasyMock.createMock(ResultSet.class);
    preparedStatement = EasyMock.createMock(PreparedStatement.class);
    statement = EasyMock.createMock(Statement.class);
    props = new Properties();
    props.put("karaf.lock.jdbc.url", url);
    props.put("karaf.lock.jdbc.driver", driver);
    props.put("karaf.lock.jdbc.user", user);
    props.put("karaf.lock.jdbc.password", password);
    props.put("karaf.lock.jdbc.table", tableName);
    props.put("karaf.lock.jdbc.clustername", clustername);
    props.put("karaf.lock.jdbc.timeout", Integer.toString(timeout));
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseMetaData(java.sql.DatabaseMetaData) Properties(org.apache.felix.utils.properties.Properties) Before(org.junit.Before)

Example 49 with Properties

use of org.apache.felix.utils.properties.Properties in project karaf by apache.

the class AutoEncryptionSupport method run.

@Override
public void run() {
    WatchService watchService = null;
    try {
        watchService = FileSystems.getDefault().newWatchService();
        Path dir = Paths.get(System.getProperty("karaf.etc"));
        dir.register(watchService, ENTRY_MODIFY);
        Path file = dir.resolve("users.properties");
        encryptedPassword(new Properties(file.toFile()));
        while (running) {
            try {
                WatchKey key = watchService.poll(1, TimeUnit.SECONDS);
                if (key == null) {
                    continue;
                }
                for (WatchEvent<?> event : key.pollEvents()) {
                    @SuppressWarnings("unchecked") WatchEvent<Path> ev = (WatchEvent<Path>) event;
                    // Context for directory entry event is the file name of entry
                    Path name = dir.resolve(ev.context());
                    if (file.equals(name)) {
                        encryptedPassword(new Properties(file.toFile()));
                    }
                }
                key.reset();
            } catch (IOException e) {
                LOGGER.warn(e.getMessage(), e);
            } catch (InterruptedException e) {
            // Ignore as this happens on shutdown
            }
        }
    } catch (IOException e) {
        LOGGER.warn(e.getMessage(), e);
    } finally {
        StreamUtils.close(watchService);
    }
}
Also used : Path(java.nio.file.Path) WatchKey(java.nio.file.WatchKey) WatchEvent(java.nio.file.WatchEvent) IOException(java.io.IOException) Properties(org.apache.felix.utils.properties.Properties) WatchService(java.nio.file.WatchService)

Example 50 with Properties

use of org.apache.felix.utils.properties.Properties in project karaf by apache.

the class PropertiesLoader method loadIncludes.

private static void loadIncludes(String propertyName, boolean mandatory, URL configPropURL, Properties configProps) throws Exception {
    String includes = configProps.get(propertyName);
    if (includes != null) {
        StringTokenizer st = new StringTokenizer(includes, "\" ", true);
        if (st.countTokens() > 0) {
            String location;
            do {
                location = nextLocation(st);
                if (location != null) {
                    URL url = new URL(configPropURL, location);
                    Properties props = loadPropertiesFile(url, mandatory);
                    configProps.putAll(props);
                }
            } while (location != null);
        }
    }
    configProps.remove(propertyName);
}
Also used : StringTokenizer(java.util.StringTokenizer) Properties(org.apache.felix.utils.properties.Properties) URL(java.net.URL)

Aggregations

Properties (org.apache.felix.utils.properties.Properties)95 IOException (java.io.IOException)35 File (java.io.File)33 Test (org.junit.Test)27 Subject (javax.security.auth.Subject)25 NamePasswordCallbackHandler (org.apache.karaf.jaas.modules.NamePasswordCallbackHandler)21 Path (java.nio.file.Path)13 HashMap (java.util.HashMap)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)9 FileInputStream (java.io.FileInputStream)8 URL (java.net.URL)8 MalformedURLException (java.net.MalformedURLException)7 HashSet (java.util.HashSet)6 Hashtable (java.util.Hashtable)6 LinkedHashMap (java.util.LinkedHashMap)6 TreeMap (java.util.TreeMap)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 FileNotFoundException (java.io.FileNotFoundException)5 LoginException (javax.security.auth.login.LoginException)5