LdapGroupsMapping implements GroupMappingServiceProvider, Configurable { @Deprecated String getPassword(Configuration conf, String alias, String defaultPass) { String password = defaultPass; try { char[] passchars = conf.getPassword(alias); if (passchars != null) { password = new String(passchars); } } catch (IOException ioe) { LOG.warn("Exception while trying to get password for alias {}:", alias, ioe); } return password; }  @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 testConfGetPassword() throws Exception { File testDir = GenericTestUtils.getTestDir(); Configuration conf = getBaseConf(); final Path jksPath = new Path(testDir.toString(), "test.jks"); final String ourUrl = JavaKeyStoreProvider.SCHEME_NAME + ": File file = new File(testDir, "test.jks"); file.delete(); conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, ourUrl); CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0); char[] bindpass = {'b', 'i', 'n', 'd', 'p', 'a', 's', 's'}; char[] storepass = {'s', 't', 'o', 'r', 'e', 'p', 'a', 's', 's'}; assertNull(provider.getCredentialEntry( LdapGroupsMapping.BIND_PASSWORD_KEY)); assertNull(provider.getCredentialEntry( LdapGroupsMapping.LDAP_KEYSTORE_PASSWORD_KEY)); try { provider.createCredentialEntry( LdapGroupsMapping.BIND_PASSWORD_KEY, bindpass); provider.createCredentialEntry( LdapGroupsMapping.LDAP_KEYSTORE_PASSWORD_KEY, storepass); provider.flush(); } catch (Exception e) { e.printStackTrace(); throw e; } assertArrayEquals(bindpass, provider.getCredentialEntry( LdapGroupsMapping.BIND_PASSWORD_KEY).getCredential()); assertArrayEquals(storepass, provider.getCredentialEntry( LdapGroupsMapping.LDAP_KEYSTORE_PASSWORD_KEY).getCredential()); LdapGroupsMapping mapping = new LdapGroupsMapping(); Assert.assertEquals("bindpass", mapping.getPassword(conf, LdapGroupsMapping.BIND_PASSWORD_KEY, "")); Assert.assertEquals("storepass", mapping.getPassword(conf, LdapGroupsMapping.LDAP_KEYSTORE_PASSWORD_KEY, "")); Assert.assertEquals("", mapping.getPassword(conf,"invalid-alias", "")); }