diff --git a/core/src/main/java/hudson/TcpSlaveAgentListener.java b/core/src/main/java/hudson/TcpSlaveAgentListener.java index e4432c349c..c6b8670294 100644 --- a/core/src/main/java/hudson/TcpSlaveAgentListener.java +++ b/core/src/main/java/hudson/TcpSlaveAgentListener.java @@ -199,7 +199,7 @@ public final class TcpSlaveAgentListener extends Thread { Computer.threadPoolForRemoting, Mode.BINARY, new BufferedInputStream(new SocketInputStream(this.s)), new BufferedOutputStream(new SocketOutputStream(this.s)), null, true); - channel.setProperty(CliEntryPoint.class.getName(),new CliManagerImpl(null)); + channel.setProperty(CliEntryPoint.class.getName(),new CliManagerImpl()); channel.join(); } diff --git a/core/src/main/java/hudson/cli/CLICommand.java b/core/src/main/java/hudson/cli/CLICommand.java index cf542bcff4..ff908eb0d7 100644 --- a/core/src/main/java/hudson/cli/CLICommand.java +++ b/core/src/main/java/hudson/cli/CLICommand.java @@ -148,15 +148,7 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable { */ public abstract String getShortDescription(); - /** - * @deprecated as of 1.350 - * Use {@link #main(List, Locale, InputStream, PrintStream, PrintStream, Authentication)} - */ public int main(List args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr) { - return main(args,locale,stdin,stdout,stderr,Hudson.ANONYMOUS); - } - - public int main(List args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr, Authentication auth) { this.stdin = new BufferedInputStream(stdin); this.stdout = stdout; this.stderr = stderr; @@ -168,15 +160,12 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable { SecurityContext sc = SecurityContextHolder.getContext(); Authentication old = sc.getAuthentication(); - CliAuthenticator authenticator = null; - if (shouldPerformAuthentication(auth)) { - authenticator = Hudson.getInstance().getSecurityRealm().createCliAuthenticator(this); - new ClassParser().parse(authenticator,p); - } + CliAuthenticator authenticator = Hudson.getInstance().getSecurityRealm().createCliAuthenticator(this); + new ClassParser().parse(authenticator,p); try { p.parseArgument(args.toArray(new String[args.size()])); - sc.setAuthentication(authenticator!=null? authenticator.authenticate() : auth); // run the CLI with the right credential + sc.setAuthentication(authenticator.authenticate()); // run the CLI with the right credential return run(); } catch (CmdLineException e) { stderr.println(e.getMessage()); diff --git a/core/src/main/java/hudson/cli/CliManagerImpl.java b/core/src/main/java/hudson/cli/CliManagerImpl.java index 7eb6db3575..17f2d73fd4 100644 --- a/core/src/main/java/hudson/cli/CliManagerImpl.java +++ b/core/src/main/java/hudson/cli/CliManagerImpl.java @@ -25,8 +25,6 @@ package hudson.cli; import hudson.remoting.Channel; import hudson.model.Hudson; -import org.acegisecurity.Authentication; -import org.acegisecurity.context.SecurityContextHolder; import org.apache.commons.discovery.resource.ClassLoaders; import org.apache.commons.discovery.resource.classes.DiscoverClasses; import org.apache.commons.discovery.resource.names.DiscoverServiceNames; @@ -50,14 +48,7 @@ import java.io.Serializable; * @author Kohsuke Kawaguchi */ public class CliManagerImpl implements CliEntryPoint, Serializable { - /** - * If the transport has already authenticated this CLI command execution, a valid {@link Authentication} object. - * Otherwise {@link Hudson#ANONYMOUS} - */ - private final Authentication auth; - - public CliManagerImpl(Authentication auth) { - this.auth = auth!=null ? auth : Hudson.ANONYMOUS; + public CliManagerImpl() { } public int main(List args, Locale locale, InputStream stdin, OutputStream stdout, OutputStream stderr) { @@ -73,7 +64,7 @@ public class CliManagerImpl implements CliEntryPoint, Serializable { CLICommand cmd = CLICommand.clone(subCmd); if(cmd!=null) { // execute the command, do so with the originator of the request as the principal - return cmd.main(args.subList(1,args.size()),locale, stdin, out, err,auth); + return cmd.main(args.subList(1,args.size()),locale, stdin, out, err); } err.println("No such command: "+subCmd); diff --git a/core/src/main/java/hudson/cli/GroovyshCommand.java b/core/src/main/java/hudson/cli/GroovyshCommand.java index cbb25516d2..fab488013b 100644 --- a/core/src/main/java/hudson/cli/GroovyshCommand.java +++ b/core/src/main/java/hudson/cli/GroovyshCommand.java @@ -57,7 +57,7 @@ public class GroovyshCommand extends CLICommand { } @Override - public int main(List args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr, Authentication a) { + public int main(List args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr) { // this allows the caller to manipulate the JVM state, so require the admin privilege. Hudson.getInstance().checkPermission(Hudson.ADMINISTER); diff --git a/core/src/main/java/hudson/cli/declarative/CLIRegisterer.java b/core/src/main/java/hudson/cli/declarative/CLIRegisterer.java index be8cf5ccdd..b5b02e80d3 100644 --- a/core/src/main/java/hudson/cli/declarative/CLIRegisterer.java +++ b/core/src/main/java/hudson/cli/declarative/CLIRegisterer.java @@ -101,7 +101,7 @@ public class CLIRegisterer extends ExtensionFinder { } @Override - public int main(List args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr, Authentication a) { + public int main(List args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr) { CmdLineParser parser = new CmdLineParser(null); try { try { diff --git a/core/src/main/java/hudson/model/Hudson.java b/core/src/main/java/hudson/model/Hudson.java index abf90d8e98..40f020f538 100644 --- a/core/src/main/java/hudson/model/Hudson.java +++ b/core/src/main/java/hudson/model/Hudson.java @@ -2832,13 +2832,12 @@ public final class Hudson extends Node implements ItemGroup, Stapl UUID uuid = UUID.fromString(req.getHeader("Session")); rsp.setHeader("Hudson-Duplex",""); // set the header so that the client would know - final Authentication auth = getAuthentication(); FullDuplexHttpChannel server; if(req.getHeader("Side").equals("download")) { duplexChannels.put(uuid,server=new FullDuplexHttpChannel(uuid, !hasPermission(ADMINISTER)) { protected void main(Channel channel) throws IOException, InterruptedException { - channel.setProperty(CliEntryPoint.class.getName(),new CliManagerImpl(auth)); + channel.setProperty(CliEntryPoint.class.getName(),new CliManagerImpl()); } }); try { diff --git a/test/src/test/java/hudson/security/CliAuthenticationTest.java b/test/src/test/java/hudson/security/CliAuthenticationTest.java index 7cc013c2bf..1e4d11e9d8 100644 --- a/test/src/test/java/hudson/security/CliAuthenticationTest.java +++ b/test/src/test/java/hudson/security/CliAuthenticationTest.java @@ -43,7 +43,7 @@ public class CliAuthenticationTest extends HudsonTestCase { } }); - assertEquals(0,new CliManagerImpl(null).main(Arrays.asList("test","--username","abc","--password","abc"), + assertEquals(0,new CliManagerImpl().main(Arrays.asList("test","--username","abc","--password","abc"), Locale.ENGLISH, System.in, System.out, System.err)); }