private static void obtainTokenForHBase ( Credentials credentials , Configuration conf ) throws IOException { if ( UserGroupInformation . isSecurityEnabled ( ) ) { LOG . info ( "Attempting to obtain Kerberos security token for HBase" ) ; try { // ---- // Intended call: HBaseConfiguration.addHbaseResources(conf); Class . forName ( "org.apache.hadoop.hbase.HBaseConfiguration" ) . getMethod ( "addHbaseResources" , Configuration . class ) . invoke ( null , conf ) ; // ---- LOG . info ( "HBase security setting: {}" , conf . get ( "hbase.security.authentication" ) ) ; if ( ! "kerberos" . equals ( conf . get ( "hbase.security.authentication" ) ) ) { LOG . info ( "HBase has not been configured to use Kerberos." ) ; return ; } LOG . info ( "Obtaining Kerberos security token for HBase" ) ; // ---- // Intended call: Token<AuthenticationTokenIdentifier> token = TokenUtil.obtainToken(conf); Token < ? > token = ( Token < ? > ) Class . forName ( "org.apache.hadoop.hbase.security.token.TokenUtil" ) . getMethod ( "obtainToken" , Configuration . class ) . invoke ( null , conf ) ; // ---- if ( token == null ) { LOG . error ( "No Kerberos security token for HBase available" ) ; return ; } credentials . addToken ( token . getService ( ) , token ) ; LOG . info ( "Added HBase Kerberos security token to credentials." ) ; } catch ( ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e ) { LOG . info ( "HBase is not available (not packaged with this application): {} : \"{}\"." , e . getClass ( ) . getSimpleName ( ) , e . getMessage ( ) ) ; } } }
Obtain Kerberos security token for HBase .