List of usage examples for org.apache.hadoop.security.alias CredentialProviderFactory getProviders
public static List<CredentialProvider> getProviders(Configuration conf) throws IOException
From source file:org.apache.atlas.CredentialProviderUtilityIT.java
License:Apache License
@Test public void testEnterValidValues() throws Exception { Path testPath = null;//www. ja v a2 s . com 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 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); }
From source file:org.apache.atlas.CredentialProviderUtilityIT.java
License:Apache License
@Test public void testEnterEmptyValues() throws Exception { Path testPath = null;//from w ww . ja va 2s.c o m 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 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); }
From source file:org.apache.atlas.CredentialProviderUtilityIT.java
License:Apache License
@Test public void testEnterMismatchedValues() throws Exception { Path testPath = null;//from w w w .ja v a2 s . com 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 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); }
From source file:org.apache.atlas.CredentialProviderUtilityIT.java
License:Apache License
@Test public void testOverwriteValues() throws Exception { Path testPath = null;/* ww w .ja v a2 s . co m*/ 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 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 ? 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); }
From source file:org.apache.atlas.util.CredentialProviderUtility.java
License:Apache License
/**\ * Returns a credential provider for the entered JKS path. * @param textDevice the system console. * @return the Credential provider//from w w w . j a v a2s. co m * @throws IOException */ private static CredentialProvider getCredentialProvider(TextDevice textDevice) throws IOException { String providerPath = textDevice.readLine("Please enter the full path to the credential provider:"); File file = new File(providerPath); if (file.exists()) { textDevice.printf("%s already exists. You will need to specify whether existing entries should be " + "overwritten " + "(default is 'yes')\n", providerPath); } String providerURI = JavaKeyStoreProvider.SCHEME_NAME + "://file/" + providerPath; Configuration conf = new Configuration(false); conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerURI); return CredentialProviderFactory.getProviders(conf).get(0); }
From source file:org.apache.atlas.web.security.BaseSSLAndKerberosTest.java
License:Apache License
protected void setupCredentials() throws Exception { Configuration conf = new Configuration(false); File file = new File(jksPath.toUri().getPath()); file.delete();/*from w w w .j a va 2 s . c o m*/ conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerUrl); CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0); // create new aliases try { char[] storepass = { 'k', 'e', 'y', 'p', 'a', 's', 's' }; provider.createCredentialEntry(SecurityProperties.KEYSTORE_PASSWORD_KEY, storepass); char[] trustpass = { 'k', 'e', 'y', 'p', 'a', 's', 's' }; provider.createCredentialEntry(SecurityProperties.TRUSTSTORE_PASSWORD_KEY, trustpass); char[] trustpass2 = { 'k', 'e', 'y', 'p', 'a', 's', 's' }; provider.createCredentialEntry("ssl.client.truststore.password", trustpass2); char[] certpass = { 'k', 'e', 'y', 'p', 'a', 's', 's' }; provider.createCredentialEntry(SecurityProperties.SERVER_CERT_PASSWORD_KEY, certpass); // write out so that it can be found in checks provider.flush(); } catch (Exception e) { e.printStackTrace(); throw e; } }
From source file:org.apache.atlas.web.security.SSLTest.java
License:Apache License
protected void setupCredentials() throws Exception { Configuration conf = new Configuration(false); File file = new File(jksPath.toUri().getPath()); file.delete();//from w w w.j ava 2 s . c o m conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerUrl); CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0); // create new aliases try { char[] storepass = { 'k', 'e', 'y', 'p', 'a', 's', 's' }; provider.createCredentialEntry(KEYSTORE_PASSWORD_KEY, storepass); char[] trustpass = { 'k', 'e', 'y', 'p', 'a', 's', 's' }; provider.createCredentialEntry(TRUSTSTORE_PASSWORD_KEY, trustpass); char[] trustpass2 = { 'k', 'e', 'y', 'p', 'a', 's', 's' }; provider.createCredentialEntry("ssl.client.truststore.password", trustpass2); char[] certpass = { 'k', 'e', 'y', 'p', 'a', 's', 's' }; provider.createCredentialEntry(SERVER_CERT_PASSWORD_KEY, certpass); // write out so that it can be found in checks provider.flush(); } catch (Exception e) { e.printStackTrace(); throw e; } }
From source file:org.apache.atlas.web.service.SecureEmbeddedServer.java
License:Apache License
/** * Retrieves a password from a configured credential provider or prompts for the password and stores it in the * configured credential provider./* ww w . jav a2 s .c o m*/ * @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; }
From source file:org.apache.atlas.web.service.SecureEmbeddedServerTestBase.java
License:Apache License
protected void setupCredentials() throws Exception { Configuration conf = new Configuration(false); File file = new File(jksPath.toUri().getPath()); file.delete();// w w w .j ava 2s . co m conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerUrl); CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0); // create new aliases try { char[] storepass = { 'k', 'e', 'y', 'p', 'a', 's', 's' }; provider.createCredentialEntry(KEYSTORE_PASSWORD_KEY, storepass); char[] trustpass = { 'k', 'e', 'y', 'p', 'a', 's', 's' }; provider.createCredentialEntry(TRUSTSTORE_PASSWORD_KEY, trustpass); char[] certpass = { 'k', 'e', 'y', 'p', 'a', 's', 's' }; provider.createCredentialEntry(SERVER_CERT_PASSWORD_KEY, certpass); // write out so that it can be found in checks provider.flush(); } catch (Exception e) { e.printStackTrace(); throw e; } }
From source file:org.apache.ranger.authorization.hadoop.utils.RangerCredentialProvider.java
License:Apache License
List<CredentialProvider> getCredentialProviders(String url) { try {//w ww .j a v a 2s. co m Configuration conf = new Configuration(); conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, url); return CredentialProviderFactory.getProviders(conf); } catch (Exception ie) { LOG.error("Unable to get the Credential Provider from the Configuration", ie); } return null; }