got rid of the notion that the transport can implicitly authenticate the session.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@28502 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke committed 2010-03-10 22:59:23 +00:00
1 parent 1952937655
commit 084591eecc
7 files changed
+10 -31

No files matched your search

@@ -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();
}
+3 -14
View File
@@ -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<String> args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr) {
return main(args,locale,stdin,stdout,stderr,Hudson.ANONYMOUS);
}
public int main(List<String> 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());
@@ -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<String> 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);
@@ -57,7 +57,7 @@ public class GroovyshCommand extends CLICommand {
}
@Override
public int main(List<String> args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr, Authentication a) {
public int main(List<String> 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);
@@ -101,7 +101,7 @@ public class CLIRegisterer extends ExtensionFinder {
}
@Override
public int main(List<String> args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr, Authentication a) {
public int main(List<String> args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr) {
CmdLineParser parser = new CmdLineParser(null);
try {
try {
+1 -2
View File
@@ -2832,13 +2832,12 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, 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 {
@@ -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));
}