Search in sources :

Example 1 with BasicUserNameMapper

use of org.apache.ignite.hadoop.util.BasicUserNameMapper in project ignite by apache.

the class BasicUserNameMapperSelfTest method testMappings.

/**
     * Test regular mappings.
     *
     * @throws Exception If failed.
     */
public void testMappings() throws Exception {
    Map<String, String> map = new HashMap<>();
    map.put("1", "101");
    BasicUserNameMapper mapper = create(map, false, null);
    assertNull(mapper.map(null));
    assertEquals("101", mapper.map("1"));
    assertEquals("2", mapper.map("2"));
    mapper = create(map, true, null);
    assertNull(mapper.map(null));
    assertEquals("101", mapper.map("1"));
    assertNull(mapper.map("2"));
    mapper = create(map, false, "A");
    assertNull(mapper.map(null));
    assertEquals("101", mapper.map("1"));
    assertEquals("2", mapper.map("2"));
    mapper = create(map, true, "A");
    assertEquals("A", mapper.map(null));
    assertEquals("101", mapper.map("1"));
    assertEquals("A", mapper.map("2"));
}
Also used : HashMap(java.util.HashMap) BasicUserNameMapper(org.apache.ignite.hadoop.util.BasicUserNameMapper)

Example 2 with BasicUserNameMapper

use of org.apache.ignite.hadoop.util.BasicUserNameMapper in project ignite by apache.

the class ChainedUserNameMapperSelfTest method testChaining.

/**
     * Test actual chaining logic.
     *
     * @throws Exception If failed.
     */
public void testChaining() throws Exception {
    BasicUserNameMapper mapper1 = new BasicUserNameMapper();
    mapper1.setMappings(Collections.singletonMap("1", "101"));
    KerberosUserNameMapper mapper2 = new KerberosUserNameMapper();
    mapper2.setInstance(INSTANCE);
    mapper2.setRealm(REALM);
    ChainedUserNameMapper mapper = create(mapper1, mapper2);
    assertEquals("101" + "/" + INSTANCE + "@" + REALM, mapper.map("1"));
    assertEquals("2" + "/" + INSTANCE + "@" + REALM, mapper.map("2"));
    assertEquals(IgfsUtils.fixUserName(null) + "/" + INSTANCE + "@" + REALM, mapper.map(null));
}
Also used : KerberosUserNameMapper(org.apache.ignite.hadoop.util.KerberosUserNameMapper) BasicUserNameMapper(org.apache.ignite.hadoop.util.BasicUserNameMapper) ChainedUserNameMapper(org.apache.ignite.hadoop.util.ChainedUserNameMapper)

Example 3 with BasicUserNameMapper

use of org.apache.ignite.hadoop.util.BasicUserNameMapper in project ignite by apache.

the class BasicUserNameMapperSelfTest method create.

/**
     * Create mapper.
     *
     * @param dictionary Dictionary.
     * @param useDfltUsrName Whether to use default user name.
     * @param dfltUsrName Default user name.
     * @return Mapper.
     */
private BasicUserNameMapper create(@Nullable Map<String, String> dictionary, boolean useDfltUsrName, @Nullable String dfltUsrName) {
    BasicUserNameMapper mapper = new BasicUserNameMapper();
    mapper.setMappings(dictionary);
    mapper.setUseDefaultUserName(useDfltUsrName);
    mapper.setDefaultUserName(dfltUsrName);
    return mapper;
}
Also used : BasicUserNameMapper(org.apache.ignite.hadoop.util.BasicUserNameMapper)

Example 4 with BasicUserNameMapper

use of org.apache.ignite.hadoop.util.BasicUserNameMapper in project ignite by apache.

the class BasicUserNameMapperSelfTest method checkNullOrEmptyMappings.

/**
     * Check null or empty mappings.
     *
     * @param map Mappings.
     * @throws Exception If failed.
     */
private void checkNullOrEmptyMappings(@Nullable Map<String, String> map) throws Exception {
    BasicUserNameMapper mapper = create(map, false, null);
    assertNull(mapper.map(null));
    assertEquals("1", mapper.map("1"));
    assertEquals("2", mapper.map("2"));
    mapper = create(map, true, null);
    assertNull(mapper.map(null));
    assertNull(mapper.map("1"));
    assertNull(mapper.map("2"));
    mapper = create(map, false, "A");
    assertNull(mapper.map(null));
    assertEquals("1", mapper.map("1"));
    assertEquals("2", mapper.map("2"));
    mapper = create(map, true, "A");
    assertEquals("A", mapper.map(null));
    assertEquals("A", mapper.map("1"));
    assertEquals("A", mapper.map("2"));
}
Also used : BasicUserNameMapper(org.apache.ignite.hadoop.util.BasicUserNameMapper)

Aggregations

BasicUserNameMapper (org.apache.ignite.hadoop.util.BasicUserNameMapper)4 HashMap (java.util.HashMap)1 ChainedUserNameMapper (org.apache.ignite.hadoop.util.ChainedUserNameMapper)1 KerberosUserNameMapper (org.apache.ignite.hadoop.util.KerberosUserNameMapper)1