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

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

Introduction

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

Prototype

public static AuthenticationMethod getAuthenticationMethod(Configuration conf) 

Source Link

Usage

From source file:com.intel.hadoopRPCBenchmark.HadoopRPCBenchmarkEngine.java

License:Apache License

public HadoopRPCBenchmarkEngine(String mode, int packetSize, int clientNum, int execTime) throws IOException {
    if (mode.equalsIgnoreCase("simple")) {
        if (SecurityUtil.getAuthenticationMethod(conf) != UserGroupInformation.AuthenticationMethod.SIMPLE) {
            throw new IOException(
                    "Mode is simple, but configuration " + "hadoop.security.authentication is kerberos");
        }/*from w  w  w  . j a  va  2  s . c  o  m*/
        this.enginePreparer = new SimpleBasedEnginePreparer();
    } else if (mode.equalsIgnoreCase("token")) {
        this.enginePreparer = new TokenBasedEnginePreparer();
    } else if (mode.equalsIgnoreCase("kerberos")) {
        if (SecurityUtil.getAuthenticationMethod(conf) == UserGroupInformation.AuthenticationMethod.SIMPLE) {
            throw new IOException(
                    "Mode is kerberos, but configuration " + "hadoop.security.authentication is simple");
        }
        this.enginePreparer = new KerberosBasedEnginePreparer();
    } else {
        throw new IOException("Mode: " + mode + " not supported!");
    }
    this.packetSize = packetSize;
    this.clientNum = clientNum;
    this.execTime = execTime;
}

From source file:org.apache.atlas.web.listeners.LoginProcessor.java

License:Apache License

protected void doServiceLogin(Configuration hadoopConfig,
        org.apache.commons.configuration.Configuration configuration) {
    UserGroupInformation.setConfiguration(hadoopConfig);

    UserGroupInformation ugi = null;//from ww w  .j av a 2  s .  com
    UserGroupInformation.AuthenticationMethod authenticationMethod = SecurityUtil
            .getAuthenticationMethod(hadoopConfig);
    try {
        if (authenticationMethod == UserGroupInformation.AuthenticationMethod.SIMPLE) {
            UserGroupInformation.loginUserFromSubject(null);
        } else if (authenticationMethod == UserGroupInformation.AuthenticationMethod.KERBEROS) {
            String bindAddress = getHostname(configuration);
            UserGroupInformation.loginUserFromKeytab(
                    getServerPrincipal(configuration.getString(AUTHENTICATION_PRINCIPAL), bindAddress),
                    configuration.getString(AUTHENTICATION_KEYTAB));
        }
        LOG.info("Logged in user {}", UserGroupInformation.getLoginUser());
    } catch (IOException e) {
        throw new IllegalStateException(String.format("Unable to perform %s login.", authenticationMethod), e);
    }
}

From source file:org.apache.slider.common.tools.SliderUtils.java

License:Apache License

/**
 * Flag to indicate whether the cluster is in secure mode
 * @param conf configuration to look at/* w ww  .  ja v a2  s.  co  m*/
 * @return true if the slider client/service should be in secure mode
 */
public static boolean isHadoopClusterSecure(Configuration conf) {
    return SecurityUtil.getAuthenticationMethod(conf) != UserGroupInformation.AuthenticationMethod.SIMPLE;
}