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();
  }
public static Subject loginService ( String serviceName ) throws LoginException { LoginContext loginCtx = new LoginContext ( serviceName , new CallbackHandler ( ) { 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

@param serviceName service name defined in jass.conf file
@return the authenticated Subject or <code>null</code> is the authentication failed
@throws LoginException if there is any error during the login