[HADOOP-19010] - NullPointerException in Hadoop Credential Check CLI (#6351)
This commit is contained in:
parent
3caabb2957
commit
62cc673d00
@ -25,6 +25,7 @@
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.hadoop.security.alias.CredentialProvider.CredentialEntry;
|
||||||
import org.apache.hadoop.classification.VisibleForTesting;
|
import org.apache.hadoop.classification.VisibleForTesting;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -365,12 +366,17 @@ public void execute() throws IOException, NoSuchAlgorithmException {
|
|||||||
} else {
|
} else {
|
||||||
password = c.readPassword("Enter alias password: ");
|
password = c.readPassword("Enter alias password: ");
|
||||||
}
|
}
|
||||||
char[] storePassword =
|
CredentialEntry credentialEntry = provider.getCredentialEntry(alias);
|
||||||
provider.getCredentialEntry(alias).getCredential();
|
if(credentialEntry == null) {
|
||||||
String beMatch =
|
// Fail the password match when alias not found
|
||||||
Arrays.equals(storePassword, password) ? "success" : "failed";
|
getOut().println("Password match failed for " + alias + ".");
|
||||||
|
} else {
|
||||||
|
char[] storePassword = credentialEntry.getCredential();
|
||||||
|
String beMatch =
|
||||||
|
Arrays.equals(storePassword, password) ? "success" : "failed";
|
||||||
|
|
||||||
getOut().println("Password match " + beMatch + " for " + alias + ".");
|
getOut().println("Password match " + beMatch + " for " + alias + ".");
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
getOut().println("Cannot check aliases for CredentialProvider: " +
|
getOut().println("Cannot check aliases for CredentialProvider: " +
|
||||||
provider.toString()
|
provider.toString()
|
||||||
|
@ -165,6 +165,21 @@ public void testPromptForCredentialWithEmptyPasswd() throws Exception {
|
|||||||
assertTrue(outContent.toString().contains("Passwords don't match"));
|
assertTrue(outContent.toString().contains("Passwords don't match"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPromptForCredentialNotFound() throws Exception {
|
||||||
|
String[] args1 = {"check", "credential1", "-provider",
|
||||||
|
jceksProvider};
|
||||||
|
ArrayList<String> password = new ArrayList<String>();
|
||||||
|
password.add("p@ssw0rd");
|
||||||
|
int rc = 0;
|
||||||
|
CredentialShell shell = new CredentialShell();
|
||||||
|
shell.setConf(new Configuration());
|
||||||
|
shell.setPasswordReader(new MockPasswordReader(password));
|
||||||
|
rc = shell.run(args1);
|
||||||
|
assertEquals(0, rc);
|
||||||
|
assertOutputContains("Password match failed for credential1.");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPromptForCredential() throws Exception {
|
public void testPromptForCredential() throws Exception {
|
||||||
String[] args1 = {"create", "credential1", "-provider",
|
String[] args1 = {"create", "credential1", "-provider",
|
||||||
|
Loading…
Reference in New Issue
Block a user