File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\cli\LoginCommand.java.html

1 package hudson.cli;
2
3 import hudson.Extension;
4 import jenkins.model.Jenkins;
5 import org.acegisecurity.Authentication;
6 import org.kohsuke.args4j.CmdLineException;
7
8 /**
9 * Saves the current credential to allow future commands to run without explicit credential information.
10 *
11 * @author Kohsuke Kawaguchi
12 * @since 1.351
13 */
14 @Extension
15 public class LoginCommand extends CLICommand {
16 @Override
17 public String getShortDescription() {
18 return Messages.LoginCommand_ShortDescription();
19 }
20
21 /**
22 * If we use the stored authentication for the login command, login becomes no-op, which is clearly not what
23 * the user has intended.
24 */
25 @Override
26 protected Authentication loadStoredAuthentication() throws InterruptedException {
27 return Jenkins.ANONYMOUS;
28 }
29
30 @Override
31 protected int run() throws Exception {
32 Authentication a = Jenkins.getAuthentication();
33 if (a== Jenkins.ANONYMOUS)
34 throw new CmdLineException("No credentials specified."); // this causes CLI to show the command line options.
35
36 ClientAuthenticationCache store = new ClientAuthenticationCache(checkChannel());
37 store.set(a);
38
39 return 0;
40 }
41
42 }
43