本文整理汇总了Java中org.apache.hadoop.security.alias.CredentialProvider.CredentialEntry方法的典型用法代码示例。如果您正苦于以下问题:Java CredentialProvider.CredentialEntry方法的具体用法?Java CredentialProvider.CredentialEntry怎么用?Java CredentialProvider.CredentialEntry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.security.alias.CredentialProvider
的用法示例。
在下文中一共展示了CredentialProvider.CredentialEntry方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPassword
import org.apache.hadoop.security.alias.CredentialProvider; //导入方法依赖的package包/类
/**
* Retrieves a password from a configured credential provider or prompts for the password and stores it in the
* configured credential provider.
* @param config application configuration
* @param key the key/alias for the password.
* @return the password.
* @throws IOException
*/
private String getPassword(org.apache.commons.configuration.Configuration config, String key) throws IOException {
String password;
String provider = config.getString(CERT_STORES_CREDENTIAL_PROVIDER_PATH);
if (provider != null) {
LOG.info("Attempting to retrieve password from configured credential provider path");
Configuration c = new Configuration();
c.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, provider);
CredentialProvider credentialProvider = CredentialProviderFactory.getProviders(c).get(0);
CredentialProvider.CredentialEntry entry = credentialProvider.getCredentialEntry(key);
if (entry == null) {
throw new IOException(String.format("No credential entry found for %s. "
+ "Please create an entry in the configured credential provider", key));
} else {
password = String.valueOf(entry.getCredential());
}
} else {
throw new IOException("No credential provider path configured for storage of certificate store passwords");
}
return password;
}
示例2: getSystemPassword
import org.apache.hadoop.security.alias.CredentialProvider; //导入方法依赖的package包/类
private String getSystemPassword() {
String password = "";
if (StringUtils.isEmpty(this.hadoopSecurityCredentialPath)) {
password = this.systemPassword;
} else {
try {
Configuration configuration = new Configuration();
configuration.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH,
this.hadoopSecurityCredentialPath);
CredentialProvider provider =
CredentialProviderFactory.getProviders(configuration).get(0);
CredentialProvider.CredentialEntry credEntry = provider.getCredentialEntry(
KEYSTORE_PASS);
if (credEntry != null) {
password = new String(credEntry.getCredential());
}
} catch (Exception e) {
}
}
return password;
}
示例3: getPassword
import org.apache.hadoop.security.alias.CredentialProvider; //导入方法依赖的package包/类
private String getPassword(Properties properties) throws IOException, InterpreterException {
if (isNotEmpty(properties.getProperty(PASSWORD_KEY))) {
return properties.getProperty(PASSWORD_KEY);
} else if (isNotEmpty(properties.getProperty(JDBC_JCEKS_FILE))
&& isNotEmpty(properties.getProperty(JDBC_JCEKS_CREDENTIAL_KEY))) {
try {
Configuration configuration = new Configuration();
configuration.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH,
properties.getProperty(JDBC_JCEKS_FILE));
CredentialProvider provider = CredentialProviderFactory.getProviders(configuration).get(0);
CredentialProvider.CredentialEntry credEntry =
provider.getCredentialEntry(properties.getProperty(JDBC_JCEKS_CREDENTIAL_KEY));
if (credEntry != null) {
return new String(credEntry.getCredential());
} else {
throw new InterpreterException("Failed to retrieve password from JCEKS from key: "
+ properties.getProperty(JDBC_JCEKS_CREDENTIAL_KEY));
}
} catch (Exception e) {
logger.error("Failed to retrieve password from JCEKS \n" +
"For file: " + properties.getProperty(JDBC_JCEKS_FILE) +
"\nFor key: " + properties.getProperty(JDBC_JCEKS_CREDENTIAL_KEY), e);
throw e;
}
}
return null;
}
示例4: testEnterValidValues
import org.apache.hadoop.security.alias.CredentialProvider; //导入方法依赖的package包/类
@Test
public void testEnterValidValues() throws Exception {
Path testPath = null;
try {
testPath = new Path(Files.createTempDirectory("tempproviders").toString(), "test.jks");
} catch (IOException e) {
e.printStackTrace();
}
new File(testPath.toUri().getPath()).delete();
final Path finalTestPath = testPath;
CredentialProviderUtility.textDevice = new CredentialProviderUtility.TextDevice() {
@Override
public void printf(String fmt, Object... params) {
System.out.print(String.format(fmt, params));
}
public String readLine(String fmt, Object... args) {
return JavaKeyStoreProvider.SCHEME_NAME + "://file/" + finalTestPath.toString();
}
@Override
public char[] readPassword(String fmt, Object... args) {
return defaultPass;
}
};
CredentialProviderUtility.main(new String[]{});
String providerUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file/" + testPath.toUri();
Configuration conf = new Configuration(false);
conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerUrl);
CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0);
CredentialProvider.CredentialEntry entry =
provider.getCredentialEntry(SecurityProperties.KEYSTORE_PASSWORD_KEY);
assertCredentialEntryCorrect(entry);
entry = provider.getCredentialEntry(SecurityProperties.TRUSTSTORE_PASSWORD_KEY);
assertCredentialEntryCorrect(entry);
entry = provider.getCredentialEntry(SecurityProperties.SERVER_CERT_PASSWORD_KEY);
assertCredentialEntryCorrect(entry);
}
示例5: assertCredentialEntryCorrect
import org.apache.hadoop.security.alias.CredentialProvider; //导入方法依赖的package包/类
protected void assertCredentialEntryCorrect(CredentialProvider.CredentialEntry entry) {
assertCredentialEntryCorrect(entry, defaultPass);
}
示例6: testEnterEmptyValues
import org.apache.hadoop.security.alias.CredentialProvider; //导入方法依赖的package包/类
@Test
public void testEnterEmptyValues() throws Exception {
Path testPath = null;
try {
testPath = new Path(Files.createTempDirectory("tempproviders").toString(), "test.jks");
} catch (IOException e) {
e.printStackTrace();
}
new File(testPath.toUri().getPath()).delete();
final Path finalTestPath = testPath;
CredentialProviderUtility.textDevice = new CredentialProviderUtility.TextDevice() {
private Random random = new Random();
@Override
public void printf(String fmt, Object... params) {
System.out.print(String.format(fmt, params));
}
public String readLine(String fmt, Object... args) {
return JavaKeyStoreProvider.SCHEME_NAME + "://file/" + finalTestPath.toString();
}
@Override
public char[] readPassword(String fmt, Object... args) {
List<char[]> responses = new ArrayList<>();
responses.add(new char[0]);
responses.add(defaultPass);
int size = responses.size();
int item = random.nextInt(size);
return responses.get(item);
}
};
CredentialProviderUtility.main(new String[]{});
String providerUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file/" + testPath.toUri();
Configuration conf = new Configuration(false);
conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerUrl);
CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0);
CredentialProvider.CredentialEntry entry =
provider.getCredentialEntry(SecurityProperties.KEYSTORE_PASSWORD_KEY);
assertCredentialEntryCorrect(entry);
entry = provider.getCredentialEntry(SecurityProperties.TRUSTSTORE_PASSWORD_KEY);
assertCredentialEntryCorrect(entry);
entry = provider.getCredentialEntry(SecurityProperties.SERVER_CERT_PASSWORD_KEY);
assertCredentialEntryCorrect(entry);
}
示例7: testEnterMismatchedValues
import org.apache.hadoop.security.alias.CredentialProvider; //导入方法依赖的package包/类
@Test
public void testEnterMismatchedValues() throws Exception {
Path testPath = null;
try {
testPath = new Path(Files.createTempDirectory("tempproviders").toString(), "test.jks");
} catch (IOException e) {
e.printStackTrace();
}
new File(testPath.toUri().getPath()).delete();
final Path finalTestPath = testPath;
CredentialProviderUtility.textDevice = new CredentialProviderUtility.TextDevice() {
int i = 0;
@Override
public void printf(String fmt, Object... params) {
System.out.print(String.format(fmt, params));
}
public String readLine(String fmt, Object... args) {
return JavaKeyStoreProvider.SCHEME_NAME + "://file/" + finalTestPath.toString();
}
@Override
public char[] readPassword(String fmt, Object... args) {
List<char[]> responses = new ArrayList<>();
responses.add(defaultPass);
responses.add(new char[]{'b', 'a', 'd', 'p', 'a', 's', 's'});
responses.add(defaultPass);
int item = i % 3;
i++;
return responses.get(item);
}
};
CredentialProviderUtility.main(new String[]{});
String providerUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file/" + testPath.toUri();
Configuration conf = new Configuration(false);
conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerUrl);
CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0);
CredentialProvider.CredentialEntry entry =
provider.getCredentialEntry(SecurityProperties.KEYSTORE_PASSWORD_KEY);
assertCredentialEntryCorrect(entry);
entry = provider.getCredentialEntry(SecurityProperties.TRUSTSTORE_PASSWORD_KEY);
assertCredentialEntryCorrect(entry);
entry = provider.getCredentialEntry(SecurityProperties.SERVER_CERT_PASSWORD_KEY);
assertCredentialEntryCorrect(entry);
}
示例8: testOverwriteValues
import org.apache.hadoop.security.alias.CredentialProvider; //导入方法依赖的package包/类
@Test
public void testOverwriteValues() throws Exception {
Path testPath = null;
try {
testPath = new Path(Files.createTempDirectory("tempproviders").toString(), "test.jks");
} catch (IOException e) {
e.printStackTrace();
}
new File(testPath.toUri().getPath()).delete();
final Path finalTestPath = testPath;
CredentialProviderUtility.textDevice = new CredentialProviderUtility.TextDevice() {
@Override
public void printf(String fmt, Object... params) {
System.out.print(String.format(fmt, params));
}
public String readLine(String fmt, Object... args) {
return JavaKeyStoreProvider.SCHEME_NAME + "://file/" + finalTestPath.toString();
}
@Override
public char[] readPassword(String fmt, Object... args) {
return defaultPass;
}
};
CredentialProviderUtility.main(new String[]{});
// now attempt to overwrite values
CredentialProviderUtility.textDevice = new CredentialProviderUtility.TextDevice() {
int i = 0;
@Override
public void printf(String fmt, Object... params) {
System.out.print(String.format(fmt, params));
}
public String readLine(String fmt, Object... args) {
return i++ == 0 ? JavaKeyStoreProvider.SCHEME_NAME + "://file/" + finalTestPath.toString() : "y";
}
@Override
public char[] readPassword(String fmt, Object... args) {
return new char[]{'n', 'e', 'w', 'p', 'a', 's', 's'};
}
};
CredentialProviderUtility.main(new String[]{});
String providerUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file/" + testPath.toUri();
Configuration conf = new Configuration(false);
conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerUrl);
CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0);
char[] newpass = "newpass".toCharArray();
CredentialProvider.CredentialEntry entry =
provider.getCredentialEntry(SecurityProperties.KEYSTORE_PASSWORD_KEY);
assertCredentialEntryCorrect(entry, newpass);
entry = provider.getCredentialEntry(SecurityProperties.TRUSTSTORE_PASSWORD_KEY);
assertCredentialEntryCorrect(entry, newpass);
entry = provider.getCredentialEntry(SecurityProperties.SERVER_CERT_PASSWORD_KEY);
assertCredentialEntryCorrect(entry, newpass);
}