public static Subject loginService ( String serviceName ) throws LoginException { LoginContext loginCtx = new LoginContext ( serviceName , new CallbackHandler ( ) { // as we use .keytab file there is no need to specify any options in callback public void handle ( Callback [ ] callbacks ) throws IOException , UnsupportedCallbackException { } } ) ; loginCtx . login ( ) ; return loginCtx . getSubject ( ) ; }
Log in using the service name for jaas . conf file and . keytab instead of specifying username and password