Search in sources :

Example 36 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 37 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 38 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)

Example 39 with Properties

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

the class PropertiesLoader method loadSystemProperties.

/**
     * <p>
     * Loads the properties in the system property file associated with the
     * framework installation into <tt>System.setProperty()</tt>. These properties
     * are not directly used by the framework in anyway. By default, the system
     * property file is located in the <tt>conf/</tt> directory of the Felix
     * installation directory and is called "<tt>system.properties</tt>". The
     * installation directory of Felix is assumed to be the parent directory of
     * the <tt>felix.jar</tt> file as found on the system class path property.
     * The precise file from which to load system properties can be set by
     * initializing the "<tt>felix.system.properties</tt>" system property to an
     * arbitrary URL.
     * </p>
     *
     * @param file the Karaf base folder.
     * @throws IOException if the system file can't be loaded.
     */
public static void loadSystemProperties(File file) throws IOException {
    Properties props = new Properties(false);
    try {
        props.load(file);
    } catch (Exception e1) {
    // Ignore
    }
    for (Enumeration<?> e = props.propertyNames(); e.hasMoreElements(); ) {
        String name = (String) e.nextElement();
        if (name.startsWith(OVERRIDE_PREFIX)) {
            String overrideName = name.substring(OVERRIDE_PREFIX.length());
            String value = props.getProperty(name);
            System.setProperty(overrideName, substVars(value, name, null, props));
        } else {
            String value = System.getProperty(name, props.getProperty(name));
            System.setProperty(name, substVars(value, name, null, props));
        }
    }
}
Also used : Properties(org.apache.felix.utils.properties.Properties) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 40 with Properties

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

the class PropertiesLoader method loadConfigProperties.

/**
     * <p>
     * Loads the configuration properties in the configuration property file
     * associated with the framework installation; these properties
     * are accessible to the framework and to bundles and are intended
     * for configuration purposes. By default, the configuration property
     * file is located in the <tt>conf/</tt> directory of the Felix
     * installation directory and is called "<tt>config.properties</tt>".
     * The installation directory of Felix is assumed to be the parent
     * directory of the <tt>felix.jar</tt> file as found on the system class
     * path property. The precise file from which to load configuration
     * properties can be set by initializing the "<code>felix.config.properties</code>"
     * system property to an arbitrary URL.
     * </p>
     *
     * @param file the config file where to load the properties.
     * @return A <code>Properties</code> instance or <code>null</code> if there was an error.
     * @throws Exception if something wrong occurs.
     */
public static Properties loadConfigProperties(File file) throws Exception {
    // See if the property URL was specified as a property.
    URL configPropURL;
    try {
        configPropURL = file.toURI().toURL();
    } catch (MalformedURLException ex) {
        System.err.print("Main: " + ex);
        return null;
    }
    Properties configProps = loadPropertiesFile(configPropURL, false);
    copySystemProperties(configProps);
    configProps.substitute();
    return configProps;
}
Also used : MalformedURLException(java.net.MalformedURLException) Properties(org.apache.felix.utils.properties.Properties) URL(java.net.URL)

Aggregations

Properties (org.apache.felix.utils.properties.Properties)64 File (java.io.File)26 Test (org.junit.Test)22 IOException (java.io.IOException)21 Subject (javax.security.auth.Subject)21 NamePasswordCallbackHandler (org.apache.karaf.jaas.modules.NamePasswordCallbackHandler)21 RolePrincipal (org.apache.karaf.jaas.boot.principal.RolePrincipal)16 UserPrincipal (org.apache.karaf.jaas.boot.principal.UserPrincipal)16 Principal (java.security.Principal)12 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 GroupPrincipal (org.apache.karaf.jaas.boot.principal.GroupPrincipal)6 Map (java.util.Map)5 AbstractKerberosITest (org.apache.directory.server.kerberos.kdc.AbstractKerberosITest)5 FileInputStream (java.io.FileInputStream)4 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)4 LinkedHashMap (java.util.LinkedHashMap)4 TreeMap (java.util.TreeMap)4 FailedLoginException (javax.security.auth.login.FailedLoginException)4