public static byte [ ] initiateSecurityContext ( Subject subject , String servicePrincipalName ) throws GSSException { GSSManager manager = GSSManager . getInstance ( ) ; GSSName serverName = manager . createName ( servicePrincipalName , GSSName . NT_HOSTBASED_SERVICE ) ; final GSSContext context = manager . createContext ( serverName , krb5Oid , null , GSSContext . DEFAULT_LIFETIME ) ; // The GSS context initiation has to be performed as a privileged action. return Subject . doAs ( subject , ( PrivilegedAction < byte [ ] > ) ( ) -> { try { byte [ ] token = new byte [ 0 ] ; // This is a one pass context initialization. context . requestMutualAuth ( false ) ; context . requestCredDeleg ( false ) ; return context . initSecContext ( token , 0 , token . length ) ; } catch ( GSSException e ) { log . error ( Util . getMessage ( "Krb5TokenKerberosContextProcessingException" ) , e ) ; return null ; } } ) ; }
Generate the service ticket that will be passed to the cluster master for authentication