Package org.apache.felix.utils.properties

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


        assertTrue(module.logout());
        assertEquals("Principals should be gone as the user has logged out", 0, subject.getPrincipals().size());       
    }

    protected Properties ldapLoginModuleOptions() throws IOException {
        return new Properties(new File("src/test/resources/org/apache/karaf/jaas/modules/ldap/ldap.properties"));
    }
View Full Code Here


        return new Properties(new File("src/test/resources/org/apache/karaf/jaas/modules/ldap/ldap.properties"));
    }
   
    @Test
    public void testNonAdminLogin() throws Exception {
        Properties options = ldapLoginModuleOptions();
        LDAPLoginModule module = new LDAPLoginModule();
        CallbackHandler cb = new CallbackHandler() {
            public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                for (Callback cb : callbacks) {
                    if (cb instanceof NameCallback) {
View Full Code Here

        assertEquals("Principals should be gone as the user has logged out", 0, subject.getPrincipals().size());       
    }
   
    @Test
    public void testBadPassword() throws Exception {
        Properties options = ldapLoginModuleOptions();
        LDAPLoginModule module = new LDAPLoginModule();
        CallbackHandler cb = new CallbackHandler() {
            public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                for (Callback cb : callbacks) {
                    if (cb instanceof NameCallback) {
View Full Code Here

        assertFalse(module.login());
    }
   
    @Test
    public void testUserNotFound() throws Exception {
        Properties options = ldapLoginModuleOptions();
        LDAPLoginModule module = new LDAPLoginModule();
        CallbackHandler cb = new CallbackHandler() {
            public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                for (Callback cb : callbacks) {
                    if (cb instanceof NameCallback) {
View Full Code Here

public class LdapSpecialCharsInPasswordTest extends LdapLoginModuleTest {
   
    private static final String NEW_CONNECTION_PASSWORD = "#a&b{>c=<12~d%";

    protected Properties ldapLoginModuleOptions() throws IOException {
        return new Properties(new File("src/test/resources/org/apache/karaf/jaas/modules/ldap/ldap_special_char_in_password.properties"));
    }
View Full Code Here

        }
    }

    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 if the stored password is flagged as encrypted
        String encryptedKey = getEncryptedPassword(storedKey);
        if (!storedKey.equals(encryptedKey)) {
            if (debug) {
                LOG.debug("The key isn't flagged as encrypted, encrypt it.");
            }
            if (debug) {
                LOG.debug("Rebuild the user informations string.");
            }
            userInfos = encryptedKey + ",";
            for (int i = 2; i < infos.length; i++) {
                if (i == (infos.length - 1)) {
                    userInfos = userInfos + infos[i];
                } else {
                    userInfos = userInfos + infos[i] + ",";
                }
            }
            if (debug) {
                LOG.debug("Push back the user informations in the users properties.");
            }
            users.put(user, userInfos);
            try {
                if (debug) {
                    LOG.debug("Store the users properties file.");
                }
                users.save();
            } catch (IOException ioe) {
                LOG.warn("Unable to write user properties file " + f, ioe);
            }
            storedKey = encryptedKey;
        }

        // check the provided password
        if (!checkPassword(getString(key), 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

     * @param propertyName the property name.
     * @param propertyValue the property value.
     * @throws Exception if a failure occurs.
     */
    private void changeConfiguration(File configurationFile, String propertyName, String propertyValue) throws Exception {
        Properties props = new Properties();
        InputStream is = new FileInputStream(configurationFile);
        try {
            props.load(is);
        } finally {
            is.close();
        }
        props.put(propertyName, propertyValue);
        OutputStream os = new FileOutputStream(configurationFile);
        try {
            props.save(os);
        } finally {
            os.close();
        }
    }
View Full Code Here

     * @param propertyName the property name to look for.
     * @return the property value.
     * @throws Exception in case of read failure.
     */
    private String getConfiguration(File configurationFile, String propertyName) throws Exception {
        Properties props = loadPropertiesFile(configurationFile.toURI().toURL());
        return props.getProperty(propertyName);
    }
View Full Code Here

    protected void cleanShutdown() {
        try {
            File file = new File(new File(location, "etc"), CONFIG_PROPERTIES_FILE_NAME);
            URL configPropURL = file.toURI().toURL();
            Properties props = loadPropertiesFile(configPropURL);

            String host = props.getProperty(KARAF_SHUTDOWN_HOST, "localhost");
           
            String shutdown = props.getProperty(KARAF_SHUTDOWN_COMMAND, DEFAULT_SHUTDOWN_COMMAND);
           
            int port = getShutDownPort(props);

            // We found the port, try to send the command
            if (port > 0) {
View Full Code Here

        return result;
    }

    protected Properties loadPropertiesFile(URL configPropURL) throws Exception {
        // Read the properties file.
        Properties configProps = new Properties();
        InputStream is = null;
        try {
            configProps.put("karaf.base", new File(location).getCanonicalPath());
            configProps.put("karaf.home", System.getProperty("karaf.home"));
            configProps.put("karaf.data", new File(new File(location), "data").getCanonicalPath());
            is = configPropURL.openConnection().getInputStream();
            configProps.load(is);
            return configProps;
        } catch (Exception ex) {
          throw new RuntimeException("Error loading config properties from " + configPropURL, ex);
        } finally {
          try {
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.