LdapGroupsMapping implements GroupMappingServiceProvider, Configurable { String extractPassword(String pwFile) { if (pwFile.isEmpty()) { return ""; } StringBuilder password = new StringBuilder(); try (Reader reader = new InputStreamReader( new FileInputStream(pwFile), Charsets.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 synchronized Configuration getConf(); @Override synchronized void setConf(Configuration conf); 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 BIND_USER_KEY; static final String BIND_USER_DEFAULT; static final String BIND_PASSWORD_KEY; static final String BIND_PASSWORD_DEFAULT; static final String BIND_PASSWORD_FILE_KEY; static final String BIND_PASSWORD_FILE_DEFAULT; static final String BASE_DN_KEY; static final String BASE_DN_DEFAULT; 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 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 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 int RECONNECT_RETRY_COUNT; }
@Test public void testExtractPassword() throws IOException { File testDir = new File(System.getProperty("test.build.data", "target/test-dir")); 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())); }