Package org.apache.felix.utils.properties

Examples of org.apache.felix.utils.properties.Properties


        }
    }

    public boolean login() throws LoginException {
        File f = new File(usersFile);
        Properties users;
        try {
            users = new Properties(f);
        } catch (IOException ioe) {
            throw new LoginException("Unable to load user properties file " + f);
        }

        Callback[] callbacks = new Callback[2];
        callbacks[0] = new NameCallback("Username: ");
        callbacks[1] = new PublickeyCallback();
        try {
            callbackHandler.handle(callbacks);
        } catch (IOException ioe) {
            throw new LoginException(ioe.getMessage());
        } catch (UnsupportedCallbackException uce) {
            throw new LoginException(uce.getMessage() + " not available to obtain information from user");
        }
        String user = ((NameCallback) callbacks[0]).getName();
        if (user == null) {
            throw new FailedLoginException("Unable to retrieve user name");
        }
        PublicKey key = ((PublickeyCallback) callbacks[1]).getPublicKey();
        if (key == null) {
            throw new FailedLoginException("Unable to retrieve public key");
        }

        // user infos container read from the users properties file
        String userInfos = null;

        try {
            userInfos = (String) users.get(user);
        } catch (NullPointerException e) {
            //error handled in the next statement
        }
        if (userInfos == null) {
            if (!this.detailedLoginExcepion) {
                throw new FailedLoginException("login failed");
            } else {
                throw new FailedLoginException("User " + user + " does not exist");
            }
        }

        // the password is in the first position
        String[] infos = userInfos.split(",");
        String storedKey = infos[0];

        // check the provided password
        if (!getString(key).equals(storedKey)) {
            if (!this.detailedLoginExcepion) {
                throw new FailedLoginException("login failed");
            } else {
                throw new FailedLoginException("Public key for " + user + " does not match");
            }
        }

        principals = new HashSet<Principal>();
        principals.add(new UserPrincipal(user));
        for (int i = 1; i < infos.length; i++) {
            principals.add(new RolePrincipal(infos[i]));
        }

        users.clear();

        if (debug) {
            LOG.debug("Successfully logged in " + user);
        }
        return true;
View Full Code Here


        }
        File f = new File(usersFile);
        if (!f.exists()) {
            throw new LoginException("Users file not found at " + f);
        }
        Properties users;
        try {
            users = new Properties(f);
        } catch (IOException ioe) {
            throw new LoginException("Unable to load user properties file " + f);
        }
        //encrypt all password if necessary
        EncryptedPassword(users);

        Callback[] callbacks = new Callback[2];

        callbacks[0] = new NameCallback("Username: ");
        callbacks[1] = new PasswordCallback("Password: ", false);
        try {
            callbackHandler.handle(callbacks);
        } catch (IOException ioe) {
            throw new LoginException(ioe.getMessage());
        } catch (UnsupportedCallbackException uce) {
            throw new LoginException(uce.getMessage() + " not available to obtain information from user");
        }
        // user callback get value
        if (((NameCallback) callbacks[0]).getName() == null) {
            throw new LoginException("Username can not be null");
        }
        user = ((NameCallback) callbacks[0]).getName();
        // password callback get value
        if (((PasswordCallback) callbacks[1]).getPassword() == null) {
            throw new LoginException("Password can not be null");
        }
        String password = new String(((PasswordCallback) callbacks[1]).getPassword());

        // user infos container read from the users properties file
        String userInfos = null;

        try {
            userInfos = (String) users.get(user);
        } catch (NullPointerException e) {
            //error handled in the next statement
        }
        if (userInfos == null) {
          if (!this.detailedLoginExcepion) {
            throw new FailedLoginException("login failed");
          } else {
            throw new FailedLoginException("User " + user + " does not exist");
          }
        }
       
        // the password is in the first position
        String[] infos = userInfos.split(",");
        String storedPassword = infos[0];
       
        // check the provided password
        if (!checkPassword(password, storedPassword)) {
          if (!this.detailedLoginExcepion) {
            throw new FailedLoginException("login failed");
          } else {
            throw new FailedLoginException("Password for " + user + " does not match");
          }
        }

        principals = new HashSet<Principal>();
        principals.add(new UserPrincipal(user));
        for (int i = 1; i < infos.length; i++) {
            principals.add(new RolePrincipal(infos[i]));
        }

        users.clear();

        if (debug) {
            LOG.debug("Successfully logged in " + user);
        }
        return true;
View Full Code Here

    public static void execute(File file, final RunnableWithProperties callback) throws IOException {
        execute(file, new Runnable() {
            public void run(RandomAccessFile file) throws IOException {
                byte[] buffer = new byte[(int) file.length()];
                file.readFully(buffer);
                Properties props = new Properties();
                props.load(new ByteArrayInputStream(buffer));
                callback.run(props);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                props.store(baos, null);
                file.setLength(0);
                file.write(baos.toByteArray());
            }
        });
    }
View Full Code Here

    public static <T> T execute(File file, final CallableWithProperties<T> callback) throws IOException {
        return execute(file, new Callable<T>() {
            public T call(RandomAccessFile file) throws IOException {
                byte[] buffer = new byte[(int) file.length()];
                file.readFully(buffer);
                Properties props = new Properties();
                props.load(new ByteArrayInputStream(buffer));
                T result = callback.call(props);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                props.store(baos, null);
                file.setLength(0);
                file.write(baos.toByteArray());
                return result;
            }
        });
View Full Code Here

        try {
            String karafBase = bundleContext.getProperty("karaf.base");
            File etcDir = new File(karafBase, "etc");
            File syspropsFile = new File(etcDir, "system.properties");
            FileInputStream fis = new FileInputStream(syspropsFile);
            Properties props = new Properties();
            props.load(fis);
            fis.close();
            props.setProperty("karaf.name", name);
            FileOutputStream fos = new FileOutputStream(syspropsFile);
            props.store(fos, "");
            fos.close();
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
View Full Code Here

    public void reboot(String time, boolean cleanup) throws Exception {
        reboot(timeToSleep(time), cleanup);
    }

    public void setFrameworkDebug(boolean debug) throws Exception {
        Properties properties = new Properties(new File(System.getProperty("karaf.base"), "etc/config.properties"));
        if (debug) {
            properties.put("felix.log.level", "4");
            properties.put("osgi.debug", "etc/equinox-debug.properties");
            // TODO populate the equinox-debug.properties file with the one provided in shell/dev module
        } else {
            properties.remove("felix.log.level");
            properties.remove("osgi.debug");
        }
        properties.save();
    }
View Full Code Here

            return "equinox";
        }
    }

    public void setFramework(String framework) throws Exception {
        Properties properties = new Properties(new File(System.getProperty("karaf.base"), "etc/config.properties"));
        if (!framework.equals("felix") || !framework.equals("equinox"))
            throw new IllegalArgumentException("Framework name is not supported. Only felix or equinox are supported.");
        properties.put("karaf.framework", framework);
        properties.save();
    }
View Full Code Here

            }
            } catch (Exception e) {
                throw (IOException) new IOException(e.getMessage()).initCause(e);
            }
        }
        Properties p = new Properties(storageFile);
        for (Enumeration keys = props.keys(); keys.hasMoreElements(); ) {
            Object key = keys.nextElement();
            if (!Constants.SERVICE_PID.equals(key)
                    && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
                    && !FILEINSTALL_FILE_NAME.equals(key)) {
                p.put((String) key, (String) props.get(key));
            }
        }
        // remove "removed" properties from the file
        ArrayList<String> propertiesToRemove = new ArrayList<String>();
        for (Object key : p.keySet()) {
            if (props.get(key) == null
                    && !Constants.SERVICE_PID.equals(key)
                    && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
                    && !FILEINSTALL_FILE_NAME.equals(key)) {
                propertiesToRemove.add(key.toString());
            }
        }
        for (String key : propertiesToRemove) {
            p.remove(key);
        }
        // save the cfg file
        storage.mkdirs();
        p.save();
        updateFileInstall(storageFile);
    }
View Full Code Here

                    }
                } catch (Exception e) {
                    throw (IOException) new IOException(e.getMessage()).initCause(e);
                }
            }
            Properties p = new Properties(storageFile);
            p.clear();
            for (Enumeration keys = properties.keys(); keys.hasMoreElements(); ) {
                Object key = keys.nextElement();
                if (!Constants.SERVICE_PID.equals(key)
                        && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
                        && !FELIX_FILEINSTALL_FILENAME.equals(key)) {
                    p.put((String) key, (String) properties.get(key));
                }
            }
            // remove "removed" properties from the file
            ArrayList<String> propertiesToRemove = new ArrayList<String>();
            for (Object key : p.keySet()) {
                if (properties.get(key) == null
                        && !Constants.SERVICE_PID.equals(key)
                        && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
                        && !FELIX_FILEINSTALL_FILENAME.equals(key)) {
                    propertiesToRemove.add(key.toString());
                }
            }
            for (String key : propertiesToRemove) {
                p.remove(key);
            }
            // save the cfg file
            storage.mkdirs();
            p.save();
            updateFileInstall(storageFile);
        } else {
            Configuration cfg = configurationAdmin.getConfiguration(pid, null);
            if (cfg.getProperties() == null) {
                String[] pids = parsePid(pid);
View Full Code Here

            }
            if (Felix.NAME.equalsIgnoreCase(framework))
                frwk = new Felix(new File(KARAF_BASE));
            else
                frwk = new Equinox(new File(KARAF_BASE));
            Properties props = new Properties(new File(System.getProperty("karaf.base"), "etc/config.properties"));
            props.put("karaf.framework", framework.toLowerCase());
            props.save();
        }
        if (debug) {
            if (frwk == null)
                frwk = getFramework();
            System.out.printf("Enabling debug for OSGi framework (%s)%n", frwk.getName());
View Full Code Here

TOP

Related Classes of org.apache.felix.utils.properties.Properties

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.