Source:
public int main(List<String> args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr) { this.stdin = new BufferedInputStream(stdin); this.stdout = stdout; this.stderr = stderr; this.locale = locale; registerOptionHandlers(); CmdLineParser p = getCmdLineParser(); SecurityContext sc = SecurityContextHolder.getContext(); Authentication old = sc.getAuthentication(); CliAuthenticator authenticator = Jenkins.getInstance().getSecurityRealm().createCliAuthenticator(this); sc.setAuthentication(getTransportAuthentication()); new ClassParser().parse(authenticator,p); try { p.parseArgument(args.toArray(new String[args.size()])); Authentication auth = authenticator.authenticate(); if (auth==Jenkins.ANONYMOUS) auth = loadStoredAuthentication(); sc.setAuthentication(auth); if (!(this instanceof LoginCommand || this instanceof HelpCommand)) Jenkins.getInstance().checkPermission(Jenkins.READ); return run(); } catch (CmdLineException e) { stderr.println(e.getMessage()); printUsage(stderr, p); return -1; } catch (AccessDeniedException e) { stderr.println(e.getMessage()); return -1; } catch (AbortException e) { stderr.println(e.getMessage()); return -1; } catch (BadCredentialsException e) { String id = UUID.randomUUID().toString(); LOGGER.log(Level.INFO, "CLI login attempt failed: "+id, e); stderr.println("Bad Credentials. Search the server log for "+id+" for more details."); return -1; } catch (Exception e) { final String errorMsg = String.format("Unexpected exception occurred during performing %s command: %s", getName(), e.getMessage()); stderr.println(errorMsg); LOGGER.log(Level.WARNING, errorMsg); e.printStackTrace(stderr); return -1; } finally { sc.setAuthentication(old); } }

Target:
public int main(List<String> args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr) { this.stdin = new BufferedInputStream(stdin); this.stdout = stdout; this.stderr = stderr; this.locale = locale; registerOptionHandlers(); CmdLineParser p = getCmdLineParser(); SecurityContext sc = SecurityContextHolder.getContext(); Authentication old = sc.getAuthentication(); CliAuthenticator authenticator = Jenkins.getInstance().getSecurityRealm().createCliAuthenticator(this); sc.setAuthentication(getTransportAuthentication()); new ClassParser().parse(authenticator,p); try { p.parseArgument(args.toArray(new String[args.size()])); Authentication auth = authenticator.authenticate(); if (auth==Jenkins.ANONYMOUS) auth = loadStoredAuthentication(); sc.setAuthentication(auth); if (!(this instanceof LoginCommand || this instanceof HelpCommand)) Jenkins.getInstance().checkPermission(Jenkins.READ); return run(); } catch (CmdLineException e) { stderr.println(e.getMessage()); printUsage(stderr, p); return -1; } catch (AccessDeniedException e) { stderr.println(e.getMessage()); return -1; } catch (AbortException e) { stderr.println(e.getMessage()); return -1; } catch (BadCredentialsException e) { String id = UUID.randomUUID().toString(); LOGGER.log(Level.INFO, "CLI login attempt failed: "+id, e); stderr.println("Bad Credentials. Search the server log for "+id+" for more details."); return -1; } catch (Exception e) { final String errorMsg = String.format("Unexpected exception occurred while performing %s command!", getName()); stderr.println(errorMsg); LOGGER.log(Level.WARNING, errorMsg, e); e.printStackTrace(stderr); return -1; } finally { sc.setAuthentication(old); } }