From ca8f112d2f422c11c62bb30660b60fb5fb275457 Mon Sep 17 00:00:00 2001 From: Brandon Li Date: Wed, 11 Jun 2014 18:54:09 +0000 Subject: [PATCH] HADOOP-10656. The password keystore file is not picked by LDAP group mapping. Contributed by Brandon Li git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1601985 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../org/apache/hadoop/security/LdapGroupsMapping.java | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index a70221e2f2..59a9e62bf7 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -547,6 +547,9 @@ Release 2.5.0 - UNRELEASED HADOOP-10664. TestNetUtils.testNormalizeHostName fails. (atm) + HADOOP-10656. The password keystore file is not picked by LDAP group mapping + (brandonli) + Release 2.4.1 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/LdapGroupsMapping.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/LdapGroupsMapping.java index 754c387135..a7ffc934d6 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/LdapGroupsMapping.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/LdapGroupsMapping.java @@ -40,6 +40,7 @@ import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.conf.Configurable; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.io.IOUtils; /** * An implementation of {@link GroupMappingServiceProvider} which @@ -312,8 +313,8 @@ public synchronized void setConf(Configuration conf) { keystorePass = conf.get(LDAP_KEYSTORE_PASSWORD_KEY, LDAP_KEYSTORE_PASSWORD_DEFAULT); if (keystorePass.isEmpty()) { - keystorePass = extractPassword( - conf.get(LDAP_KEYSTORE_PASSWORD_KEY, LDAP_KEYSTORE_PASSWORD_DEFAULT)); + keystorePass = extractPassword(conf.get(LDAP_KEYSTORE_PASSWORD_FILE_KEY, + LDAP_KEYSTORE_PASSWORD_FILE_DEFAULT)); } bindUser = conf.get(BIND_USER_KEY, BIND_USER_DEFAULT); @@ -346,18 +347,20 @@ String extractPassword(String pwFile) { return ""; } + Reader reader = null; try { StringBuilder password = new StringBuilder(); - Reader reader = new FileReader(pwFile); + reader = new FileReader(pwFile); int c = reader.read(); while (c > -1) { password.append((char)c); c = reader.read(); } - reader.close(); return password.toString().trim(); } catch (IOException ioe) { throw new RuntimeException("Could not read password file: " + pwFile, ioe); + } finally { + IOUtils.cleanup(LOG, reader); } } }