DFSUtil { static String getPassword(Configuration conf, String alias) { String password = null; try { char[] passchars = conf.getPassword(alias); if (passchars != null) { password = new String(passchars); } } catch (IOException ioe) { LOG.warn("Setting password to null since IOException is caught" + " when getting password", ioe); password = null; } return password; } private  DFSUtil(); static SecureRandom getSecureRandom(); static boolean isValidName(String src); static boolean isValidNameForComponent(String component); static boolean isReservedPathComponent(String component); static String bytes2String(byte[] bytes); static String bytes2String(byte[] bytes, int offset, int length); static byte[] string2Bytes(String str); static String byteArray2PathString(final byte[][] components,
      final int offset, final int length); static String byteArray2PathString(byte[][] pathComponents); static String strings2PathString(String[] components); static String path2String(final Object path); static byte[][] getPathComponents(String path); static byte[][] bytes2byteArray(byte[] bytes, byte separator); static byte[][] bytes2byteArray(byte[] bytes, int len,
      byte separator); static String addKeySuffixes(String key, String... suffixes); static Map<String, InetSocketAddress> getRpcAddressesForNameserviceId(
      Configuration conf, String nsId, String defaultValue); static Set<String> getAllNnPrincipals(Configuration conf); static Set<String> getJournalNodeAddresses(
      Configuration conf); static Map<String, Map<String, InetSocketAddress>> getBackupNodeAddresses(
      Configuration conf); static Map<String, Map<String, InetSocketAddress>> getSecondaryNameNodeAddresses(
      Configuration conf); static Map<String, Map<String, InetSocketAddress>> getNNServiceRpcAddresses(
      Configuration conf); static Map<String, Map<String, InetSocketAddress>> getNNServiceRpcAddressesForCluster(Configuration conf); static Map<String, Map<String, InetSocketAddress>> getNNLifelineRpcAddressesForCluster(Configuration conf); static String getNamenodeLifelineAddr(final Configuration conf,
      String nsId, String nnId); static List<ConfiguredNNAddress> flattenAddressMap(
      Map<String, Map<String, InetSocketAddress>> map); static String addressMapToString(
      Map<String, Map<String, InetSocketAddress>> map); static String nnAddressesAsString(Configuration conf); static Collection<URI> getInternalNsRpcUris(Configuration conf); static String getNameServiceIdFromAddress(final Configuration conf, 
      final InetSocketAddress address, String... keys); static URI getInfoServer(InetSocketAddress namenodeAddr,
      Configuration conf, String scheme); static URI getInfoServerWithDefaultHost(String defaultHost,
      Configuration conf, final String scheme); static String getHttpClientScheme(Configuration conf); static void setGenericConf(Configuration conf,
      String nameserviceId, String nnId, String... keys); static int roundBytesToGB(long bytes); static String getNamenodeNameServiceId(Configuration conf); static String getBackupNameServiceId(Configuration conf); static String getSecondaryNameServiceId(Configuration conf); static InetSocketAddress getBindAddress(Configuration conf,
      String confKey, String defaultValue, String bindHostKey); static URI createUri(String scheme, InetSocketAddress address); static URI createUri(String scheme, String host, int port); static void addPBProtocol(Configuration conf, Class<?> protocol,
      BlockingService service, RPC.Server server); @Deprecated static void addPBProtocol(Configuration conf, Class<?> protocol,
      com.google.protobuf.BlockingService service, RPC.Server server); static String getNamenodeServiceAddr(final Configuration conf,
      String nsId, String nnId); static String getNamenodeWebAddr(final Configuration conf, String nsId,
      String nnId); static Map<String, InetSocketAddress> getWebAddressesForNameserviceId(
      Configuration conf, String nsId, String defaultValue); static String getOnlyNameServiceIdOrNull(Configuration conf); static boolean parseHelpArgument(String[] args,
      String helpDescription, PrintStream out, boolean printGenericCommandUsage); static float getInvalidateWorkPctPerIteration(Configuration conf); static int getReplWorkMultiplier(Configuration conf); static String getSpnegoKeytabKey(Configuration conf, String defaultKey); static HttpConfig.Policy getHttpPolicy(Configuration conf); static HttpServer2.Builder loadSslConfToHttpServerBuilder(HttpServer2.Builder builder,
      Configuration sslConf); static String dateToIso8601String(Date date); static String durationToString(long durationMs); static long parseRelativeTime(String relTime); static Configuration loadSslConfiguration(Configuration conf); static HttpServer2.Builder httpServerTemplateForNNAndJN(
      Configuration conf, final InetSocketAddress httpAddr,
      final InetSocketAddress httpsAddr, String name, String spnegoUserNameKey,
      String spnegoKeytabFileKey); static void assertAllResultsEqual(Collection<?> objects); static KeyProviderCryptoExtension createKeyProviderCryptoExtension(
      final Configuration conf); static DelegationTokenIdentifier decodeDelegationToken(
      final Token<DelegationTokenIdentifier> token); static void checkProtectedDescendants(
      FSDirectory fsd, INodesInPath iip); static EnumSet<HdfsFileStatus.Flags> getFlags(
      final boolean isEncrypted, final boolean isErasureCoded,
      boolean isSnapShottable, boolean hasAcl); static boolean isParentEntry(final String path, final String parent); static final Logger LOG; static final Options helpOptions; static final Option helpOpt; }
@Test public void testGetPassword() throws Exception { File testDir = GenericTestUtils.getTestDir(); Configuration conf = new Configuration(); 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[] keypass = {'k', 'e', 'y', 'p', 'a', 's', 's'}; char[] storepass = {'s', 't', 'o', 'r', 'e', 'p', 'a', 's', 's'}; char[] trustpass = {'t', 'r', 'u', 's', 't', 'p', 'a', 's', 's'}; assertEquals(null, provider.getCredentialEntry( DFS_SERVER_HTTPS_KEYPASSWORD_KEY)); assertEquals(null, provider.getCredentialEntry( DFS_SERVER_HTTPS_KEYSTORE_PASSWORD_KEY)); assertEquals(null, provider.getCredentialEntry( DFS_SERVER_HTTPS_TRUSTSTORE_PASSWORD_KEY)); try { provider.createCredentialEntry( DFS_SERVER_HTTPS_KEYPASSWORD_KEY, keypass); provider.createCredentialEntry( DFS_SERVER_HTTPS_KEYSTORE_PASSWORD_KEY, storepass); provider.createCredentialEntry( DFS_SERVER_HTTPS_TRUSTSTORE_PASSWORD_KEY, trustpass); provider.flush(); } catch (Exception e) { e.printStackTrace(); throw e; } assertArrayEquals(keypass, provider.getCredentialEntry( DFS_SERVER_HTTPS_KEYPASSWORD_KEY).getCredential()); assertArrayEquals(storepass, provider.getCredentialEntry( DFS_SERVER_HTTPS_KEYSTORE_PASSWORD_KEY).getCredential()); assertArrayEquals(trustpass, provider.getCredentialEntry( DFS_SERVER_HTTPS_TRUSTSTORE_PASSWORD_KEY).getCredential()); Assert.assertEquals("keypass", DFSUtil.getPassword(conf, DFS_SERVER_HTTPS_KEYPASSWORD_KEY)); Assert.assertEquals("storepass", DFSUtil.getPassword(conf, DFS_SERVER_HTTPS_KEYSTORE_PASSWORD_KEY)); Assert.assertEquals("trustpass", DFSUtil.getPassword(conf, DFS_SERVER_HTTPS_TRUSTSTORE_PASSWORD_KEY)); Assert.assertEquals(null, DFSUtil.getPassword(conf,"invalid-alias")); }