List of usage examples for org.apache.hadoop.security.alias CredentialProvider getCredentialEntry
public abstract CredentialEntry getCredentialEntry(String alias) throws IOException;
From source file:org.apache.zeppelin.jdbc.JDBCInterpreter.java
License:Apache License
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 {/* w w w. j a va 2 s. c o m*/ 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; }
From source file:org.apache.zeppelin.realm.ActiveDirectoryGroupRealm.java
License:Apache License
private String getSystemPassword() { String password = ""; if (StringUtils.isEmpty(this.hadoopSecurityCredentialPath)) { password = this.systemPassword; } else {//from w ww . j ava2 s . c om 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; }
From source file:org.apache.zeppelin.realm.LdapRealm.java
License:Apache License
static String getSystemPassword(String hadoopSecurityCredentialPath, String keystorePass) { String password = ""; try {/*from ww w.j av a2 s . co m*/ Configuration configuration = new Configuration(); configuration.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, hadoopSecurityCredentialPath); CredentialProvider provider = CredentialProviderFactory.getProviders(configuration).get(0); CredentialProvider.CredentialEntry credEntry = provider.getCredentialEntry(keystorePass); if (credEntry != null) { password = new String(credEntry.getCredential()); } } catch (IOException e) { throw new ShiroException("Error from getting credential entry from keystore", e); } if (org.apache.commons.lang.StringUtils.isEmpty(password)) { throw new ShiroException("Error getting SystemPassword from the provided keystore:" + keystorePass + ", in path:" + hadoopSecurityCredentialPath); } return password; }
From source file:uk.gov.gchq.gaffer.slider.util.AccumuloSliderUtils.java
License:Apache License
/** * Retrieves the Accumulo root password from the credential keystores used by an Accumulo instance * * @param appConfig The Slider application configuration for an Accumulo instance * @return The root password/* w w w. j a va 2s .c o m*/ * @throws IOException if IOException * @throws URISyntaxException if URISyntaxException */ public static String getRootPassword(final ConfTree appConfig) throws IOException, URISyntaxException { Map<String, List<String>> keystores = SliderKeystoreUtils.getCredentialKeyStores(appConfig); String passwordKeystore = null; // Identify the keystore that is being used to store the Accumulo root user's password for (final Map.Entry<String, List<String>> keystore : keystores.entrySet()) { if (keystore.getValue().contains(CustomAuthenticator.ROOT_INITIAL_PASSWORD_PROPERTY)) { passwordKeystore = keystore.getKey(); } } if (passwordKeystore == null) { throw new IOException("Unable to identify a keystore that contains: " + CustomAuthenticator.ROOT_INITIAL_PASSWORD_PROPERTY); } // Load keystore CommandTestBase.SLIDER_CONFIG.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, passwordKeystore); CredentialProvider provider = CredentialProviderFactory.getProviders(CommandTestBase.SLIDER_CONFIG).get(0); // Access root password CredentialProvider.CredentialEntry rootPasswordEntry = provider .getCredentialEntry(CustomAuthenticator.ROOT_INITIAL_PASSWORD_PROPERTY); return new String(rootPasswordEntry.getCredential()); }