try { List<CredentialProvider> providers = CredentialProviderFactory.getProviders(this);
try { List<CredentialProvider> providers = CredentialProviderFactory.getProviders(this);
try { List<CredentialProvider> providers = CredentialProviderFactory.getProviders(this);
public void addPropertyReadEntry(Map<String, String> tblProps, Set<ReadEntity> inputs) throws SemanticException { if (tblProps.containsKey(Constants.JDBC_KEYSTORE)) { try { String keystore = tblProps.get(Constants.JDBC_KEYSTORE); Configuration conf = new Configuration(); conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, keystore); boolean found = false; for (CredentialProvider provider : CredentialProviderFactory.getProviders(conf)) { if (provider instanceof AbstractJavaKeyStoreProvider) { Path path = ((AbstractJavaKeyStoreProvider) provider).getPath(); inputs.add(toReadEntity(path)); found = true; } } if (!found) { throw new SemanticException("Cannot recognize keystore " + keystore + ", only JavaKeyStoreProvider is " + "supported"); } } catch (IOException e) { throw new SemanticException(e); } } } }
protected CredentialProvider getCredentialProvider() { CredentialProvider prov = null; List<CredentialProvider> providers; try { providers = CredentialProviderFactory.getProviders(getConf()); if (userSuppliedProvider) { prov = providers.get(0); } else { for (CredentialProvider p : providers) { if (!p.isTransient()) { prov = p; break; } } } } catch (IOException e) { e.printStackTrace(getErr()); } if (prov == null) { getOut().println(NO_VALID_PROVIDERS); } return prov; }
List<CredentialProvider> getCredentialProviders(String url) { try { 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; }
/**\ * Returns a credential provider for the entered JKS path. * @param textDevice the system console. * @return the Credential provider * @throws IOException */ private static CredentialProvider getCredentialProvider(TextDevice textDevice) throws IOException { String providerPath = textDevice.readLine("Please enter the full path to the credential provider:"); if (providerPath != null) { Configuration conf = new Configuration(false); conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerPath); return CredentialProviderFactory.getProviders(conf).get(0); } return null; } }
/** * 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; }
protected CredentialProvider getCredentialProvider() { CredentialProvider prov = null; List<CredentialProvider> providers; try { providers = CredentialProviderFactory.getProviders(getConf()); if (userSuppliedProvider) { prov = providers.get(0); } else { for (CredentialProvider p : providers) { if (!p.isTransient()) { prov = p; break; } } } } catch (IOException e) { e.printStackTrace(err); } if (prov == null) { out.println(NO_VALID_PROVIDERS); } return prov; }
protected CredentialProvider getCredentialProvider() { CredentialProvider provider = null; List<CredentialProvider> providers; try { providers = CredentialProviderFactory.getProviders(getConf()); if (userSuppliedProvider) { provider = providers.get(0); } else { for (CredentialProvider p : providers) { if (!p.isTransient()) { provider = p; break; } } } } catch (IOException e) { e.printStackTrace(err); } return provider; }
protected CredentialProvider getCredentialProvider() { CredentialProvider provider = null; List<CredentialProvider> providers; try { providers = CredentialProviderFactory.getProviders(getConf()); if (userSuppliedProvider) { provider = providers.get(0); } else { for (CredentialProvider p : providers) { if (!p.isTransient()) { provider = p; break; } } } } catch (IOException e) { e.printStackTrace(err); } return provider; }
protected CredentialProvider getCredentialProvider() { CredentialProvider provider = null; List<CredentialProvider> providers; try { providers = CredentialProviderFactory.getProviders(getConf()); if (userSuppliedProvider) { provider = providers.get(0); } else { for (CredentialProvider p : providers) { if (!p.isTransient()) { provider = p; break; } } } } catch (IOException e) { e.printStackTrace(err); } return provider; }
void provisionAccountKey( final Configuration conf, String account, String key) throws Exception { // add our creds to the provider final CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0); provider.createCredentialEntry( SimpleKeyProvider.KEY_ACCOUNT_KEY_PREFIX + account, key.toCharArray()); provider.flush(); }
@Test public void testUriErrors() throws Exception { Configuration conf = new Configuration(); conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, "unkn@own:/x/y"); try { List<CredentialProvider> providers = CredentialProviderFactory.getProviders(conf); assertTrue("should throw!", false); } catch (IOException e) { assertEquals("Bad configuration of " + CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH + " at unkn@own:/x/y", e.getMessage()); } }
@Test public void testFactoryErrors() throws Exception { Configuration conf = new Configuration(); conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, "unknown:///"); try { List<CredentialProvider> providers = CredentialProviderFactory.getProviders(conf); assertTrue("should throw!", false); } catch (IOException e) { assertEquals("No CredentialProviderFactory for unknown:/// in " + CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, e.getMessage()); } }
@Test public void testUriErrors() throws Exception { Configuration conf = new Configuration(); conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, "unkn@own:/x/y"); try { List<CredentialProvider> providers = CredentialProviderFactory.getProviders(conf); assertTrue("should throw!", false); } catch (IOException e) { assertEquals("Bad configuration of " + CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH + " at unkn@own:/x/y", e.getMessage()); } }
@Test public void testFactoryErrors() throws Exception { Configuration conf = new Configuration(); conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, "unknown:///"); try { List<CredentialProvider> providers = CredentialProviderFactory.getProviders(conf); assertTrue("should throw!", false); } catch (IOException e) { assertEquals("No CredentialProviderFactory for unknown:/// in " + CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, e.getMessage()); } }
@Test public void testFactory() throws Exception { Configuration conf = new Configuration(); final String userUri = UserProvider.SCHEME_NAME + ":///"; final Path jksPath = new Path(tmpDir.toString(), "test.jks"); final String jksUri = JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri(); conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, userUri + "," + jksUri); List<CredentialProvider> providers = CredentialProviderFactory.getProviders(conf); assertEquals(2, providers.size()); assertEquals(UserProvider.class, providers.get(0).getClass()); assertEquals(JavaKeyStoreProvider.class, providers.get(1).getClass()); assertEquals(userUri, providers.get(0).toString()); assertEquals(jksUri, providers.get(1).toString()); }
@Test public void testFactory() throws Exception { Configuration conf = new Configuration(); final String userUri = UserProvider.SCHEME_NAME + ":///"; final Path jksPath = new Path(tmpDir.toString(), "test.jks"); final String jksUri = JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri(); conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, userUri + "," + jksUri); List<CredentialProvider> providers = CredentialProviderFactory.getProviders(conf); assertEquals(2, providers.size()); assertEquals(UserProvider.class, providers.get(0).getClass()); assertEquals(JavaKeyStoreProvider.class, providers.get(1).getClass()); assertEquals(userUri, providers.get(0).toString()); assertEquals(jksUri, providers.get(1).toString()); }
@BeforeClass public static void setup() throws Exception { conf = new Configuration(false); final String ourUrl = UserProvider.SCHEME_NAME + ":///"; conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, ourUrl); CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0); provider.createCredentialEntry(ServerConfig. SENTRY_STORE_JDBC_PASS, passwd); provider.flush(); dataDir = new File(Files.createTempDir(), "sentry_policy_db"); conf.set(ServerConfig.SENTRY_VERIFY_SCHEM_VERSION, "false"); conf.set(ServerConfig.SENTRY_STORE_JDBC_URL, "jdbc:derby:;databaseName=" + dataDir.getPath() + ";create=true"); conf.set(ServerConfig.SENTRY_STORE_JDBC_PASS, "dummy"); conf.setStrings(ServerConfig.ADMIN_GROUPS, adminGroups); conf.set(ServerConfig.SENTRY_STORE_GROUP_MAPPING, ServerConfig.SENTRY_STORE_LOCAL_GROUP_MAPPING); policyFilePath = new File(dataDir, "local_policy_file.ini"); conf.set(ServerConfig.SENTRY_STORE_GROUP_MAPPING_RESOURCE, policyFilePath.getPath()); sentryStore = new SentryStore(conf); }