Example usage for org.apache.hadoop.security SecurityUtil login

List of usage examples for org.apache.hadoop.security SecurityUtil login

Introduction

In this page you can find the example usage for org.apache.hadoop.security SecurityUtil login.

Prototype

@InterfaceAudience.Public
@InterfaceStability.Evolving
public static void login(final Configuration conf, final String keytabFileKey, final String userNameKey)
        throws IOException 

Source Link

Document

Login as a principal specified in config.

Usage

From source file:org.apache.storm.hdfs.security.AutoHDFS.java

License:Apache License

private void login(Configuration configuration) throws IOException {
    if (configuration.get(STORM_KEYTAB_FILE_KEY) == null) {
        configuration.set(STORM_KEYTAB_FILE_KEY, hdfsKeyTab);
    }//w w  w .ja  v  a2 s .  c  o m
    if (configuration.get(STORM_USER_NAME_KEY) == null) {
        configuration.set(STORM_USER_NAME_KEY, hdfsPrincipal);
    }
    SecurityUtil.login(configuration, STORM_KEYTAB_FILE_KEY, STORM_USER_NAME_KEY);

    LOG.info("Logged into hdfs with principal {}", configuration.get(STORM_USER_NAME_KEY));
}

From source file:org.apache.storm.hdfs.security.HdfsSecurityUtil.java

License:Apache License

public static void login(Map<String, Object> conf, Configuration hdfsConfig) throws IOException {
    //If AutoHDFS is specified, do not attempt to login using keytabs, only kept for backward compatibility.
    if (conf.get(TOPOLOGY_AUTO_CREDENTIALS) == null
            || (!(((List) conf.get(TOPOLOGY_AUTO_CREDENTIALS)).contains(AutoHDFS.class.getName()))
                    && !(((List) conf.get(TOPOLOGY_AUTO_CREDENTIALS)).contains(AutoTGT.class.getName())))) {
        if (UserGroupInformation.isSecurityEnabled()) {
            // compareAndSet added because of https://issues.apache.org/jira/browse/STORM-1535
            if (isLoggedIn.compareAndSet(false, true)) {
                LOG.info("Logging in using keytab as AutoHDFS is not specified for "
                        + TOPOLOGY_AUTO_CREDENTIALS);
                String keytab = (String) conf.get(STORM_KEYTAB_FILE_KEY);
                if (keytab != null) {
                    hdfsConfig.set(STORM_KEYTAB_FILE_KEY, keytab);
                }/*from   w ww. jav a  2  s. c  o m*/
                String userName = (String) conf.get(STORM_USER_NAME_KEY);
                if (userName != null) {
                    hdfsConfig.set(STORM_USER_NAME_KEY, userName);
                }
                SecurityUtil.login(hdfsConfig, STORM_KEYTAB_FILE_KEY, STORM_USER_NAME_KEY);
            }
        }
    }
}

From source file:org.apache.storm.hive.security.AutoHive.java

License:Apache License

private void login(Configuration configuration) throws IOException {
    if (configuration.get(HIVE_KEYTAB_FILE_KEY) == null) {
        configuration.set(HIVE_KEYTAB_FILE_KEY, hiveKeytab);
    }//  w w w .  j av  a  2  s  .c om
    if (configuration.get(HIVE_PRINCIPAL_KEY) == null) {
        configuration.set(HIVE_PRINCIPAL_KEY, hivePrincipal);
    }
    SecurityUtil.login(configuration, HIVE_KEYTAB_FILE_KEY, HIVE_PRINCIPAL_KEY);
    LOG.info("Logged into hive with principal {}", configuration.get(HIVE_PRINCIPAL_KEY));
}

From source file:org.springframework.xd.sqoop.SqoopRunner.java

License:Apache License

protected static Configuration createConfiguration(Map<String, String> configOptions) {

    Configuration configuration = new Configuration();
    setConfigurationProperty(configOptions, configuration, CommonConfigurationKeys.FS_DEFAULT_NAME_KEY);
    setConfigurationProperty(configOptions, configuration, YarnConfiguration.RM_HOSTNAME);
    setConfigurationProperty(configOptions, configuration, YarnConfiguration.RM_ADDRESS);
    setConfigurationProperty(configOptions, configuration, YarnConfiguration.RM_SCHEDULER_ADDRESS);
    setConfigurationProperty(configOptions, configuration, YarnConfiguration.YARN_APPLICATION_CLASSPATH);
    setConfigurationProperty(configOptions, configuration, "mapreduce.framework.name");
    if (StringUtils.hasText(configOptions.get("mapreduce.jobhistory.address"))) {
        setConfigurationProperty(configOptions, configuration, "mapreduce.jobhistory.address");
    }/*from  ww w .  jav  a 2  s .c  o  m*/
    if (configOptions.containsKey(SECURITY_AUTH_METHOD)
            && "kerberos".equals(configOptions.get(SECURITY_AUTH_METHOD))) {
        configuration.setBoolean("hadoop.security.authorization", true);
        configuration.set("hadoop.security.authentication", configOptions.get(SECURITY_AUTH_METHOD));
        configuration.set("dfs.namenode.kerberos.principal", configOptions.get(SECURITY_NAMENODE_PRINCIPAL));
        configuration.set("yarn.resourcemanager.principal", configOptions.get(SECURITY_RM_MANAGER_PRINCIPAL));
        if (StringUtils.hasText(configOptions.get(SECURITY_MAPREDUCE_JOBHISTORY_PRINCIPAL))) {
            configuration.set("mapreduce.jobhistory.principal",
                    configOptions.get(SECURITY_MAPREDUCE_JOBHISTORY_PRINCIPAL));
        }
        String userKeytab = configOptions.get(SECURITY_USER_KEYTAB);
        String userPrincipal = configOptions.get(SECURITY_USER_PRINCIPAL);
        UserGroupInformation.setConfiguration(configuration);
        if (StringUtils.hasText(userKeytab)) {
            configuration.set(ConfigurationFactoryBean.USERKEYTAB, userKeytab.trim());
        }
        if (StringUtils.hasText(userPrincipal)) {
            configuration.set(ConfigurationFactoryBean.USERPRINCIPAL, userPrincipal.trim());
        }
        if (StringUtils.hasText(userKeytab) && StringUtils.hasText(userPrincipal)) {
            try {
                SecurityUtil.login(configuration, ConfigurationFactoryBean.USERKEYTAB,
                        ConfigurationFactoryBean.USERPRINCIPAL);
            } catch (Exception e) {
                logger.warn("Cannot login using keytab " + userKeytab + " and principal " + userPrincipal, e);
            }
        }
    }

    for (Entry<String, String> entry : configOptions.entrySet()) {
        String key = entry.getKey();
        if (key.startsWith(SPRING_HADOOP_CONFIG_PREFIX + ".")) {
            String prop = key.substring(SPRING_HADOOP_CONFIG_PREFIX.length() + 1);
            String value = entry.getValue();
            logger.info("Setting configuration property: " + prop + "=" + value);
            configuration.set(prop, value);
        }
    }
    return configuration;
}