Example usage for org.apache.hadoop.conf Configuration getPassword

List of usage examples for org.apache.hadoop.conf Configuration getPassword

Introduction

In this page you can find the example usage for org.apache.hadoop.conf Configuration getPassword.

Prototype

public char[] getPassword(String name) throws IOException 

Source Link

Document

Get the value for a known password configuration element.

Usage

From source file:CustomAuthenticator.java

License:Apache License

public static char[] getPassword(String credentialProvider, String alias) throws IOException {
    Configuration conf = new Configuration();
    conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, credentialProvider);
    return conf.getPassword(alias);
}

From source file:hsyndicate.hadoop.utils.HSyndicateConfigUtils.java

License:Apache License

public static String getSyndicateUGSessionKey(Configuration conf, String sessionName) {
    try {// w w  w .  ja  va 2s  . co m
        char[] sessionKey = conf.getPassword(
                String.format("%s.%s.key", CONFIG_SYNDICATE_USER_GATEWAY_SESSION_PREFIX, sessionName));
        if (sessionKey != null) {
            return new String(sessionKey);
        }
        LOG.info(String.format("could not read a session key of %s", sessionName));
        return null;
    } catch (IOException ex) {
        LOG.error("failed to read a session key of " + sessionName, ex);
        return null;
    }
}

From source file:org.apache.sentry.cli.tools.SentrySchemaTool.java

License:Apache License

public SentrySchemaTool(String sentryScripPath, Configuration sentryConf, String dbType)
        throws SentryUserException, IOException {
    if (sentryScripPath == null || sentryScripPath.isEmpty()) {
        throw new SentryUserException("No Sentry script dir provided");
    }/*from   w w  w . j ava  2s  .  c  om*/
    this.sentryConf = sentryConf;
    this.dbType = dbType;
    this.sentryStoreSchemaInfo = new SentryStoreSchemaInfo(sentryScripPath, dbType);
    userName = sentryConf.get(ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_USER,
            ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_USER_DEFAULT);
    //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 = sentryConf.getPassword(ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_PASS);
    if (passTmp != null) {
        passWord = new String(passTmp);
    } else {
        throw new SentrySiteConfigurationException(
                "Error reading " + ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_PASS);
    }

    try {
        connectionURL = getValidConfVar(ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_URL);
        if (dbType.equalsIgnoreCase(SentrySchemaHelper.DB_DERBY)) {
            driver = sentryConf.get(ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_DRIVER,
                    ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_DRIVER_DEFAULT);
        } else {
            driver = getValidConfVar(ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_DRIVER);
        }
        // load required JDBC driver
        Class.forName(driver);
    } catch (IOException e) {
        throw new SentryUserException("Missing property: " + e.getMessage());
    } catch (ClassNotFoundException e) {
        throw new SentryUserException("Failed to load driver", e);
    }
}

From source file:org.apache.sentry.provider.db.service.persistent.SentryStore.java

License:Apache License

public static Properties getDataNucleusProperties(Configuration conf)
        throws SentrySiteConfigurationException, IOException {
    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();/*from   w w w  .j  ava  2s.  c  om*/
    //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);
    if (passTmp == null) {
        throw new SentrySiteConfigurationException("Error reading " + ServerConfig.SENTRY_STORE_JDBC_PASS);
    }
    String pass = new String(passTmp);

    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);

    /*
     * Oracle doesn't support "repeatable-read" isolation level and testing
     * showed issues with "serializable" isolation level for Oracle 12,
     * so we use "read-committed" instead.
     *
     * JDBC URL always looks like jdbc:oracle:<drivertype>:@<database>
     *  we look at the second component.
     *
     * The isolation property can be overwritten via configuration property.
     */
    final String oracleDb = "oracle";
    if (prop.getProperty(ServerConfig.DATANUCLEUS_ISOLATION_LEVEL, "")
            .equals(ServerConfig.DATANUCLEUS_REPEATABLE_READ) && jdbcUrl.contains(oracleDb)) {
        String[] parts = jdbcUrl.split(":");
        if ((parts.length > 1) && parts[1].equals(oracleDb)) {
            // For Oracle JDBC driver, replace "repeatable-read" with "read-committed"
            prop.setProperty(ServerConfig.DATANUCLEUS_ISOLATION_LEVEL, "read-committed");
        }
    }

    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());
        }
    }
    // Disallow operations outside of transactions
    prop.setProperty("datanucleus.NontransactionalRead", "false");
    prop.setProperty("datanucleus.NontransactionalWrite", "false");
    int batchSize = conf.getInt(SENTRY_STATEMENT_BATCH_LIMIT,
            ServerConfig.SENTRY_STATEMENT_BATCH_LIMIT_DEFAULT);
    prop.setProperty("datanucleus.rdbms.statementBatchLimit", Integer.toString(batchSize));

    int allocationSize = conf.getInt(ServerConfig.SENTRY_DB_VALUE_GENERATION_ALLOCATION_SIZE,
            ServerConfig.SENTRY_DB_VALUE_GENERATION_ALLOCATION_SIZE_DEFAULT);
    prop.setProperty("datanucleus.valuegeneration.increment.allocationSize", Integer.toString(allocationSize));
    return prop;
}

From source file:org.apache.slider.server.services.security.AbstractSecurityStoreGenerator.java

License:Apache License

protected String getStorePassword(Map<String, List<String>> credentials, MapOperations compOps, String role)
        throws SliderException, IOException {
    String password = getPassword(compOps);
    if (password == null) {
        // need to leverage credential provider
        String alias = getAlias(compOps);
        LOG.debug("Alias {} found for role {}", alias, role);
        if (alias == null) {
            throw new SliderException("No store password or credential provider " + "alias found");
        }/*  w w w.  j  ava2 s  .  co m*/
        if (credentials.isEmpty()) {
            LOG.info("Credentials can not be retrieved for store generation since "
                    + "no CP paths are configured");
        }
        synchronized (this) {
            for (Map.Entry<String, List<String>> cred : credentials.entrySet()) {
                String provider = cred.getKey();
                Configuration c = new Configuration();
                c.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, provider);
                LOG.debug("Configured provider {}", provider);
                CredentialProvider cp = CredentialProviderFactory.getProviders(c).get(0);
                LOG.debug("Aliases: {}", cp.getAliases());
                char[] credential = c.getPassword(alias);
                if (credential != null) {
                    LOG.info("Credential found for role {}", role);
                    return String.valueOf(credential);
                }
            }
        }

        if (password == null) {
            LOG.info(
                    "No store credential found for alias {}.  " + "Generation of store for {} is not possible.",
                    alias, role);

        }
    }

    return password;

}