private static UnixUserGroupInformation getUgi ( String userName ) throws IOException { if ( userName == null || ! USERNAME_PATTERN . matcher ( userName ) . matches ( ) ) throw new IOException ( "Invalid username=" + userName ) ; String [ ] cmd = new String [ ] { "bash" , "-c" , "id -Gn '" + userName + "'" } ; String [ ] groups = Shell . execCommand ( cmd ) . split ( "\\s+" ) ; return new UnixUserGroupInformation ( userName , groups ) ; }
Get the ugi for a user by running shell command id - Gn