}
}
}
public void testCredentialProviderLoader() throws Exception {
CredentialProviderPasswordLoader pl =
new CredentialProviderPasswordLoader();
if (!CredentialProviderHelper.isProviderAvailable()) {
LOG.info("CredentialProvider facility not available "
+ "in the hadoop environment used");
} else {
String alias = "super.secret.alias";
String pw = "super.secret.password";
String passwordFilePath = TEMP_BASE_DIR + ".pwd";
String jksFile = "creds.jks";
createTempFile(passwordFilePath);
writeToFile(passwordFilePath, alias.getBytes());
File credDir = new File(".");
Configuration conf = getConf();
String ourUrl = CredentialProviderHelper.SCHEME_NAME +
"://file/" + credDir.getAbsolutePath() + "/" + jksFile;
File file = new File(credDir, jksFile);
file.delete();
conf.set(CredentialProviderHelper.CREDENTIAL_PROVIDER_PATH,
ourUrl);
CredentialProviderHelper.createCredentialEntry(conf, alias, pw);
conf.set("org.apache.sqoop.credentials.loader.class",
CredentialProviderPasswordLoader.class.getCanonicalName());
ArrayList<String> extraArgs = new ArrayList<String>();
extraArgs.add("--username");
extraArgs.add("username");
extraArgs.add("--password-file");
extraArgs.add(passwordFilePath);
String[] commonArgs = getCommonArgs(false, extraArgs);
SqoopOptions in = getSqoopOptions(conf);
ImportTool importTool = new ImportTool();
SqoopOptions out = importTool.parseArguments(commonArgs, conf, in, true);
assertEquals(pw, pl.loadPassword(passwordFilePath, conf));
assertEquals(pw, out.getPassword());
}
}