Example usage for org.apache.commons.collections15.keyvalue KeyedAccessUtils keyedAccessor

List of usage examples for org.apache.commons.collections15.keyvalue KeyedAccessUtils keyedAccessor

Introduction

In this page you can find the example usage for org.apache.commons.collections15.keyvalue KeyedAccessUtils keyedAccessor.

Prototype

public static final ExtendedEnumerableKeyedAccessor<String, String> keyedAccessor(final Properties props) 

Source Link

Usage

From source file:org.apache.sshd.server.PasswordAuthenticatorUtils.java

/**
 * @param usersMap The users map as a {@link Properties} object where
 * key=user name, value=expected password
 * @return A {@link PasswordAuthenticator} that authenticates using the
 * provided users map//from w w  w.  j a v a 2  s.c o  m
 */
public static final PasswordAuthenticator mappedUsersAuthenticator(final Properties usersMap) {
    return mappedUsersAuthenticator(KeyedAccessUtils.keyedAccessor(usersMap));
}

From source file:org.apache.sshd.server.PasswordAuthenticatorUtils.java

/**
 * @param usersMap The users map as a {@link Map} object where
 * key=user name, value=expected password
 * @return A {@link PasswordAuthenticator} that authenticates using the
 * provided users map/*  www .  j  a va  2  s . c o  m*/
 */
public static final PasswordAuthenticator mappedUsersAuthenticator(final Map<String, String> usersMap) {
    return mappedUsersAuthenticator(KeyedAccessUtils.keyedAccessor(usersMap));
}

From source file:org.apache.sshd.server.PasswordAuthenticatorUtilsTest.java

@Test
public void testMappedUsersAuthenticator() throws IOException {
    Properties props = new Properties();
    InputStream in = getClassResourceAsStream(getClass().getSimpleName() + ".properties");
    try {/*from  ww  w  . j a  v a 2s .c o m*/
        assertNotNull("Test file not found", in);
        props.load(in);
    } finally {
        in.close();
    }

    PasswordAuthenticator auth = PasswordAuthenticatorUtils.mappedUsersAuthenticator(props);
    ExtendedEnumerableKeyedAccessor<String, String> users = KeyedAccessUtils.keyedAccessor(props);
    for (String username : users.getKeys()) {
        String password = users.get(username);
        assertTrue("user=" + username + "/password=" + password,
                auth.authenticate(username, password, MOCK_SESSION));
        assertFalse("(shuffled) user=" + username + "/password=" + password,
                auth.authenticate(username + username, password, MOCK_SESSION));
        assertFalse("user=" + username + "/(shuffled) password=" + password,
                auth.authenticate(username, password + password, MOCK_SESSION));
    }
}