Java Code Examples for org.apache.hadoop.conf.Configuration#getPassword()

The following examples show how to use org.apache.hadoop.conf.Configuration#getPassword() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SslConfigurer.java    From ambari-logsearch with Apache License 2.0 6 votes vote down vote up
private String getPasswordFromCredentialStore(String propertyName) {
  try {
    String providerPath = logSearchSslConfig.getCredentialStoreProviderPath();
    if (StringUtils.isEmpty(providerPath)) {
      return null;
    }
    
    Configuration config = new Configuration();
    config.set(CREDENTIAL_STORE_PROVIDER_PATH, providerPath);
    char[] passwordChars = config.getPassword(propertyName);
    return (ArrayUtils.isNotEmpty(passwordChars)) ? new String(passwordChars) : null;
  } catch (Exception e) {
    logger.warn(String.format("Could not load password %s from credential store, using default password", propertyName), e);
    return null;
  }
}
 
Example 2
Source File: LdapGroupsMapping.java    From hadoop with Apache License 2.0 6 votes vote down vote up
String getPassword(Configuration conf, String alias, String defaultPass) {
  String password = null;
  try {
    char[] passchars = conf.getPassword(alias);
    if (passchars != null) {
      password = new String(passchars);
    }
    else {
      password = defaultPass;
    }
  }
  catch (IOException ioe) {
    LOG.warn("Exception while trying to password for alias " + alias + ": "
        + ioe.getMessage());
  }
  return password;
}
 
Example 3
Source File: LdapGroupsMapping.java    From big-c with Apache License 2.0 6 votes vote down vote up
String getPassword(Configuration conf, String alias, String defaultPass) {
  String password = null;
  try {
    char[] passchars = conf.getPassword(alias);
    if (passchars != null) {
      password = new String(passchars);
    }
    else {
      password = defaultPass;
    }
  }
  catch (IOException ioe) {
    LOG.warn("Exception while trying to password for alias " + alias + ": "
        + ioe.getMessage());
  }
  return password;
}
 
Example 4
Source File: WebAppUtils.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Leverages the Configuration.getPassword method to attempt to get
 * passwords from the CredentialProvider API before falling back to
 * clear text in config - if falling back is allowed.
 * @param conf Configuration instance
 * @param alias name of the credential to retreive
 * @return String credential value or null
 */
static String getPassword(Configuration conf, String alias) {
  String password = null;
  try {
    char[] passchars = conf.getPassword(alias);
    if (passchars != null) {
      password = new String(passchars);
    }
  }
  catch (IOException ioe) {
    password = null;
  }
  return password;
}
 
Example 5
Source File: HadoopConfigurationProperty.java    From hadoop-connectors with Apache License 2.0 5 votes vote down vote up
public String getPassword(Configuration config) {
  checkState(defaultValue == null || defaultValue instanceof String, "Not a string property");
  String lookupKey = getLookupKey(config, key, deprecatedKeys, (c, k) -> c.get(k) != null);
  char[] value;
  try {
    value = config.getPassword(lookupKey);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
  return logProperty(lookupKey, value == null ? (String) defaultValue : String.valueOf(value));
}
 
Example 6
Source File: HttpServer2.java    From knox with Apache License 2.0 5 votes vote down vote up
/**
 * A wrapper of {@link Configuration#getPassword(String)}. It returns
 * <code>String</code> instead of <code>char[]</code>.
 *
 * @param conf the configuration
 * @param name the property name
 * @return the password string or null
 */
private static String getPasswordString(Configuration conf, String name)
    throws IOException {
  char[] passchars = conf.getPassword(name);
  if (passchars == null) {
    return null;
  }
  return new String(passchars);
}
 
Example 7
Source File: HttpServer2.java    From knox with Apache License 2.0 5 votes vote down vote up
/**
 * A wrapper of {@link Configuration#getPassword(String)}. It returns
 * <code>String</code> instead of <code>char[]</code>.
 *
 * @param conf the configuration
 * @param name the property name
 * @return the password string or null
 */
private static String getPasswordString(Configuration conf, String name)
    throws IOException {
  char[] passchars = conf.getPassword(name);
  if (passchars == null) {
    return null;
  }
  return new String(passchars);
}
 
Example 8
Source File: HttpServer2.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * A wrapper of {@link Configuration#getPassword(String)}. It returns
 * <code>String</code> instead of <code>char[]</code>.
 *
 * @param conf the configuration
 * @param name the property name
 * @return the password string or null
 */
private static String getPasswordString(Configuration conf, String name)
    throws IOException {
  char[] passchars = conf.getPassword(name);
  if (passchars == null) {
    return null;
  }
  return new String(passchars);
}
 
Example 9
Source File: FileBasedKeyStoresFactory.java    From big-c with Apache License 2.0 5 votes vote down vote up
String getPassword(Configuration conf, String alias, String defaultPass) {
  String password = defaultPass;
  try {
    char[] passchars = conf.getPassword(alias);
    if (passchars != null) {
      password = new String(passchars);
    }
  }
  catch (IOException ioe) {
    LOG.warn("Exception while trying to get password for alias " + alias +
        ": " + ioe.getMessage());
  }
  return password;
}
 
Example 10
Source File: DFSUtil.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Leverages the Configuration.getPassword method to attempt to get
 * passwords from the CredentialProvider API before falling back to
 * clear text in config - if falling back is allowed.
 * @param conf Configuration instance
 * @param alias name of the credential to retreive
 * @return String credential value or null
 */
static String getPassword(Configuration conf, String alias) {
  String password = null;
  try {
    char[] passchars = conf.getPassword(alias);
    if (passchars != null) {
      password = new String(passchars);
    }
  }
  catch (IOException ioe) {
    password = null;
  }
  return password;
}
 
Example 11
Source File: FileSystemPlugin.java    From Bats with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve secret and access keys from configured (with
 * {@link org.apache.hadoop.security.alias.CredentialProviderFactory#CREDENTIAL_PROVIDER_PATH} property)
 * credential providers and set it into {@code conf}. If provider path is not configured or credential
 * is absent in providers, it will conditionally fallback to configuration setting. The fallback will occur unless
 * {@link org.apache.hadoop.security.alias.CredentialProvider#CLEAR_TEXT_FALLBACK} is set to {@code false}.
 *
 * @param conf {@code Configuration} which will be updated with credentials from provider
 * @throws IOException thrown if a credential cannot be retrieved from provider
 */
private void handleS3Credentials(Configuration conf) throws IOException {
  String[] credentialKeys = {"fs.s3a.secret.key", "fs.s3a.access.key"};
  for (String key : credentialKeys) {
    char[] credentialChars = conf.getPassword(key);
    if (credentialChars == null) {
      logger.warn(String.format("Property '%s' is absent.", key));
    } else {
      conf.set(key, String.valueOf(credentialChars));
    }
  }
}
 
Example 12
Source File: STSCredentialProviderV2.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
static String lookupPassword(Configuration conf, String key) throws IOException {
  try {
    final char[] pass = conf.getPassword(key);
    return pass != null ? (new String(pass)).trim() : null;
  } catch (IOException ioe) {
    throw new IOException("Cannot find password option " + key, ioe);
  }
}
 
Example 13
Source File: FileBasedKeyStoresFactory.java    From hadoop with Apache License 2.0 5 votes vote down vote up
String getPassword(Configuration conf, String alias, String defaultPass) {
  String password = defaultPass;
  try {
    char[] passchars = conf.getPassword(alias);
    if (passchars != null) {
      password = new String(passchars);
    }
  }
  catch (IOException ioe) {
    LOG.warn("Exception while trying to get password for alias " + alias +
        ": " + ioe.getMessage());
  }
  return password;
}
 
Example 14
Source File: DFSUtil.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Leverages the Configuration.getPassword method to attempt to get
 * passwords from the CredentialProvider API before falling back to
 * clear text in config - if falling back is allowed.
 * @param conf Configuration instance
 * @param alias name of the credential to retreive
 * @return String credential value or null
 */
static String getPassword(Configuration conf, String alias) {
  String password = null;
  try {
    char[] passchars = conf.getPassword(alias);
    if (passchars != null) {
      password = new String(passchars);
    }
  }
  catch (IOException ioe) {
    password = null;
  }
  return password;
}
 
Example 15
Source File: WebAppUtils.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Leverages the Configuration.getPassword method to attempt to get
 * passwords from the CredentialProvider API before falling back to
 * clear text in config - if falling back is allowed.
 * @param conf Configuration instance
 * @param alias name of the credential to retreive
 * @return String credential value or null
 */
static String getPassword(Configuration conf, String alias) {
  String password = null;
  try {
    char[] passchars = conf.getPassword(alias);
    if (passchars != null) {
      password = new String(passchars);
    }
  }
  catch (IOException ioe) {
    password = null;
  }
  return password;
}
 
Example 16
Source File: AWSCredentialUtils.java    From circus-train with Apache License 2.0 5 votes vote down vote up
static String getKey(Configuration conf, String keyType) {
  checkNotNull(conf, "conf cannot be null");
  checkNotNull(keyType, "KeyType cannot be null");

  try {
    char[] key = conf.getPassword(keyType);
    if (key == null) {
      throw new IllegalStateException(format("Unable to get value of '%s'", keyType));
    }
    return new String(key);
  } catch (IOException e) {
    throw new RuntimeException(format("Error getting key for '%s' from credential provider", keyType), e);
  }
}
 
Example 17
Source File: SentryStore.java    From incubator-sentry with Apache License 2.0 4 votes vote down vote up
public SentryStore(Configuration conf) throws SentryNoSuchObjectException,
SentryAccessDeniedException, SentryConfigurationException, IOException {
  commitSequenceId = 0;
  this.conf = conf;
  Properties prop = new Properties();
  prop.putAll(ServerConfig.SENTRY_STORE_DEFAULTS);
  String jdbcUrl = conf.get(ServerConfig.SENTRY_STORE_JDBC_URL, "").trim();
  Preconditions.checkArgument(!jdbcUrl.isEmpty(), "Required parameter " +
      ServerConfig.SENTRY_STORE_JDBC_URL + " is missed");
  String user = conf.get(ServerConfig.SENTRY_STORE_JDBC_USER, ServerConfig.
      SENTRY_STORE_JDBC_USER_DEFAULT).trim();
  //Password will be read from Credential provider specified using property
  // CREDENTIAL_PROVIDER_PATH("hadoop.security.credential.provider.path" in sentry-site.xml
  // it falls back to reading directly from sentry-site.xml
  char[] passTmp = conf.getPassword(ServerConfig.SENTRY_STORE_JDBC_PASS);
  String pass = null;
  if(passTmp != null) {
    pass = new String(passTmp);
  } else {
    throw new SentryConfigurationException("Error reading " + ServerConfig.SENTRY_STORE_JDBC_PASS);
  }

  String driverName = conf.get(ServerConfig.SENTRY_STORE_JDBC_DRIVER,
      ServerConfig.SENTRY_STORE_JDBC_DRIVER_DEFAULT);
  prop.setProperty(ServerConfig.JAVAX_JDO_URL, jdbcUrl);
  prop.setProperty(ServerConfig.JAVAX_JDO_USER, user);
  prop.setProperty(ServerConfig.JAVAX_JDO_PASS, pass);
  prop.setProperty(ServerConfig.JAVAX_JDO_DRIVER_NAME, driverName);
  for (Map.Entry<String, String> entry : conf) {
    String key = entry.getKey();
    if (key.startsWith(ServerConfig.SENTRY_JAVAX_JDO_PROPERTY_PREFIX) ||
        key.startsWith(ServerConfig.SENTRY_DATANUCLEUS_PROPERTY_PREFIX)) {
      key = StringUtils.removeStart(key, ServerConfig.SENTRY_DB_PROPERTY_PREFIX);
      prop.setProperty(key, entry.getValue());
    }
  }


  boolean checkSchemaVersion = conf.get(
      ServerConfig.SENTRY_VERIFY_SCHEM_VERSION,
      ServerConfig.SENTRY_VERIFY_SCHEM_VERSION_DEFAULT).equalsIgnoreCase(
          "true");
  if (!checkSchemaVersion) {
    prop.setProperty("datanucleus.autoCreateSchema", "true");
    prop.setProperty("datanucleus.fixedDatastore", "false");
  }

  // Disallow operations outside of transactions
  prop.setProperty("datanucleus.NontransactionalRead", "false");
  prop.setProperty("datanucleus.NontransactionalWrite", "false");

  pmf = JDOHelper.getPersistenceManagerFactory(prop);
  verifySentryStoreSchema(checkSchemaVersion);

  // Kick off the thread that cleans orphaned privileges (unless told not to)
  privCleaner = this.new PrivCleaner();
  if (conf.get(ServerConfig.SENTRY_STORE_ORPHANED_PRIVILEGE_REMOVAL,
          ServerConfig.SENTRY_STORE_ORPHANED_PRIVILEGE_REMOVAL_DEFAULT)
          .equalsIgnoreCase("true")) {
    privCleanerThread = new Thread(privCleaner);
    privCleanerThread.start();
  }
}