LdapGroupsMapping implements GroupMappingServiceProvider, Configurable { String extractPassword(String pwFile) { if (pwFile.isEmpty()) { return ""; } StringBuilder password = new StringBuilder(); try (Reader reader = new InputStreamReader( Files.newInputStream(Paths.get(pwFile)), StandardCharsets.UTF_8)) { int c = reader.read(); while (c > -1) { password.append((char)c); c = reader.read(); } return password.toString().trim(); } catch (IOException ioe) { throw new RuntimeException("Could not read password file: " + pwFile, ioe); } }  @Override synchronized List<String> getGroups(String user); @Override void cacheGroupsRefresh(); @Override void cacheGroupsAdd(List<String> groups); @Override Set<String> getGroupsSet(String user); @Override synchronized Configuration getConf(); @Override synchronized void setConf(Configuration conf); Iterator<String> getLdapUrls(); static final String LDAP_CONFIG_PREFIX; static final String LDAP_URL_KEY; static final String LDAP_URL_DEFAULT; static final String LDAP_USE_SSL_KEY; static final Boolean LDAP_USE_SSL_DEFAULT; static final String LDAP_KEYSTORE_KEY; static final String LDAP_KEYSTORE_DEFAULT; static final String LDAP_KEYSTORE_PASSWORD_KEY; static final String LDAP_KEYSTORE_PASSWORD_DEFAULT; static final String LDAP_KEYSTORE_PASSWORD_FILE_KEY; static final String LDAP_KEYSTORE_PASSWORD_FILE_DEFAULT; static final String LDAP_TRUSTSTORE_KEY; static final String LDAP_TRUSTSTORE_PASSWORD_KEY; static final String LDAP_TRUSTSTORE_PASSWORD_FILE_KEY; static final String BIND_USERS_KEY; static final String BIND_USER_SUFFIX; static final String BIND_USER_KEY; static final String BIND_USER_DEFAULT; static final String BIND_PASSWORD_SUFFIX; static final String BIND_PASSWORD_KEY; static final String BIND_PASSWORD_DEFAULT; static final String BIND_PASSWORD_FILE_SUFFIX; static final String BIND_PASSWORD_FILE_KEY; static final String BIND_PASSWORD_FILE_DEFAULT; static final String BIND_PASSWORD_ALIAS_SUFFIX; static final String BIND_PASSWORD_ALIAS_KEY; static final String BIND_PASSWORD_ALIAS_DEFAULT; static final String BASE_DN_KEY; static final String BASE_DN_DEFAULT; static final String USER_BASE_DN_KEY; static final String GROUP_BASE_DN_KEY; static final String USER_SEARCH_FILTER_KEY; static final String USER_SEARCH_FILTER_DEFAULT; static final String GROUP_SEARCH_FILTER_KEY; static final String GROUP_SEARCH_FILTER_DEFAULT; static final String MEMBEROF_ATTR_KEY; static final String MEMBEROF_ATTR_DEFAULT; static final String GROUP_MEMBERSHIP_ATTR_KEY; static final String GROUP_MEMBERSHIP_ATTR_DEFAULT; static final String GROUP_NAME_ATTR_KEY; static final String GROUP_NAME_ATTR_DEFAULT; static final String GROUP_HIERARCHY_LEVELS_KEY; static final int GROUP_HIERARCHY_LEVELS_DEFAULT; static final String POSIX_UID_ATTR_KEY; static final String POSIX_UID_ATTR_DEFAULT; static final String POSIX_GID_ATTR_KEY; static final String POSIX_GID_ATTR_DEFAULT; static final String POSIX_GROUP; static final String POSIX_ACCOUNT; static final String DIRECTORY_SEARCH_TIMEOUT; static final int DIRECTORY_SEARCH_TIMEOUT_DEFAULT; static final String CONNECTION_TIMEOUT; static final int CONNECTION_TIMEOUT_DEFAULT; static final String READ_TIMEOUT; static final int READ_TIMEOUT_DEFAULT; static final String LDAP_NUM_ATTEMPTS_KEY; static final int LDAP_NUM_ATTEMPTS_DEFAULT; static final String LDAP_NUM_ATTEMPTS_BEFORE_FAILOVER_KEY; static final int LDAP_NUM_ATTEMPTS_BEFORE_FAILOVER_DEFAULT; static final String LDAP_CTX_FACTORY_CLASS_KEY; static final String LDAP_CTX_FACTORY_CLASS_DEFAULT; }
@Test public void testExtractPassword() throws IOException { File testDir = GenericTestUtils.getTestDir(); testDir.mkdirs(); File secretFile = new File(testDir, "secret.txt"); Writer writer = new FileWriter(secretFile); writer.write("hadoop"); writer.close(); LdapGroupsMapping mapping = new LdapGroupsMapping(); Assert.assertEquals("hadoop", mapping.extractPassword(secretFile.getPath())); }