Package org.apache.felix.utils.properties

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


        EasyMock.expect(bundleContext.getProperty("karaf.etc")).andReturn(propfile.getParentFile().getParent() + "/etc");
        EasyMock.replay(bundleContext);
        system.setBundleContext(bundleContext);
        system.setName(NEW_NAME);
        EasyMock.verify(bundleContext);
        Properties props = new Properties(propfile);
        String nameAfter = props.getProperty("karaf.name");
        Assert.assertEquals(NEW_NAME, nameAfter);
    }
View Full Code Here


    public void install(File artifact) throws Exception {
        if (usersFile == null) {
            usersFile = new File(usersFileName);
        }
        Properties userProperties = new Properties(usersFile);
        this.propertiesLoginModule.encryptedPassword(userProperties);
    }
View Full Code Here

    public void update(File artifact) throws Exception {
        if (usersFile == null) {
            usersFile = new File(usersFileName);
        }
        Properties userProperties = new Properties(usersFile);
        this.propertiesLoginModule.encryptedPassword(userProperties);
    }
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();
        if (user.startsWith(PropertiesBackingEngine.GROUP_PREFIX)) {
            // you can't log in under a group name
            throw new FailedLoginException("login failed");
        }

        // 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++) {
            if (infos[i].startsWith(PropertiesBackingEngine.GROUP_PREFIX)) {
                // it's a group reference
                principals.add(new GroupPrincipal(infos[i].substring(PropertiesBackingEngine.GROUP_PREFIX.length())));
                String groupInfo = (String) users.get(infos[i]);
                if (groupInfo != null) {
                    String[] roles = groupInfo.split(",");
                    for (int j = 1; j < roles.length; j++) {
                        principals.add(new RolePrincipal(roles[j]));
                    }
                }
            } else {
                // it's an user reference
                principals.add(new RolePrincipal(infos[i]));
            }
        }

        users.clear();

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

            System.err.println("Unable to register security provider: " + t);
        }
    }
   
    public List<BundleInfo> readBundlesFromStartupProperties(File startupPropsFile) {
        Properties startupProps = PropertiesLoader.loadPropertiesOrFail(startupPropsFile);
        List<BundleInfo> bundeList = new ArrayList<BundleInfo>();
        for (String key : startupProps.keySet()) {
            try {
                BundleInfo bi = new BundleInfo();
                bi.uri = new URI(key);
                String startlevelSt = startupProps.getProperty(key).trim();
                bi.startLevel = new Integer(startlevelSt);
                bundeList.add(bi);
            } catch (Exception e) {
                throw new RuntimeException("Error loading startup bundle list from " + startupPropsFile + " at " + key, e);
            }
View Full Code Here

        catch (MalformedURLException ex) {
            System.err.print("Main: " + ex);
            return null;
        }

        Properties configProps = loadPropertiesFile(configPropURL, false);
        copySystemProperties(configProps);
        configProps.substitute();

        // Perform variable substitution for system properties.
//        for (Enumeration<?> e = configProps.propertyNames(); e.hasMoreElements();) {
//            String name = (String) e.nextElement();
//            configProps.setProperty(name,
View Full Code Here

     *
     * @param karafBase the karaf base folder
     * @throws IOException
     */
    static void loadSystemProperties(File file) throws IOException {
        Properties props = new Properties(false);
        try {
            InputStream is = new FileInputStream(file);
            props.load(is);
            is.close();
        } 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));
      }
        }
    }
View Full Code Here

            throw new RuntimeException("Error loading properties from " + configFile, e);
        }
    }

    private static Properties loadPropertiesFile(URL configPropURL, boolean failIfNotFound) throws Exception {
        Properties configProps = new Properties(null, false);
        InputStream is = null;
        try {
            is = configPropURL.openConnection().getInputStream();
            configProps.load(is);
            is.close();
        } catch (FileNotFoundException ex) {
            if (failIfNotFound) {
                throw ex;
            } else {
View Full Code Here

                String location;
                do {
                    location = Utils.nextLocation(st);
                    if (location != null) {
                        URL url = new URL(configPropURL, location);
                        Properties props = loadPropertiesFile(url, mandatory);
                        configProps.putAll(props);
                    }
                }
                while (location != null);
            }
View Full Code Here

      throw new RuntimeException(e.getMessage(), e);
    }
  }

  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);
        }
View Full Code Here

TOP

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

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.