Example usage for org.apache.hadoop.security HadoopKerberosName getShortName

List of usage examples for org.apache.hadoop.security HadoopKerberosName getShortName

Introduction

In this page you can find the example usage for org.apache.hadoop.security HadoopKerberosName getShortName.

Prototype

public String getShortName() throws IOException 

Source Link

Document

Get the translation of the principal name into an operating system user name.

Usage

From source file:org.apache.drill.exec.rpc.BitConnectionConfig.java

License:Apache License

public Map<String, ?> getSaslClientProperties(final DrillbitEndpoint remoteEndpoint) throws IOException {
    final DrillProperties properties = DrillProperties.createEmpty();

    final UserGroupInformation loginUser = UserGroupInformation.getLoginUser();
    if (loginUser.getAuthenticationMethod() == UserGroupInformation.AuthenticationMethod.KERBEROS) {
        final HadoopKerberosName loginPrincipal = new HadoopKerberosName(loginUser.getUserName());
        if (!useLoginPrincipal) {
            properties.setProperty(DrillProperties.SERVICE_PRINCIPAL, KerberosUtil.getPrincipalFromParts(
                    loginPrincipal.getShortName(), remoteEndpoint.getAddress(), loginPrincipal.getRealm()));
        } else {//from w ww.  ja  v a 2  s  . c om
            properties.setProperty(DrillProperties.SERVICE_PRINCIPAL, loginPrincipal.toString());
        }
    }
    return properties.stringPropertiesAsMap();
}