提交 86319ad5 编写于 作者: K Kohsuke Kawaguchi

[FIXED JENKINS-10890]

The closures sent from the CLI client should carry over its
authentication. Test is written in the SSH cli auth module.
上级 b5973a4a
......@@ -65,6 +65,9 @@ Upcoming changes</a>
<li class="bug">
Default e-mail suffix should be used to complete the domain name portion of the recipients list.
(<a href="https://github.com/jenkinsci/jenkins/pull/324">pull #324</a>)
<li class="bug">
Closure execution after <tt>CLI.upgrade()</tt> should carry over the transport credential.
<a href="https://issues.jenkins-ci.org/browse/JENKINS-10890">issue 10890</a>
<li class="bug">
Incorrect path delimiter used in ZipArchiver when creating archive on Windows.
<a href="https://issues.jenkins-ci.org/browse/JENKINS-9942">issue 9942</a>
......
......@@ -23,8 +23,12 @@
*/
package hudson.cli;
import hudson.remoting.CallableFilter;
import hudson.remoting.Channel;
import hudson.remoting.Pipe;
import org.acegisecurity.Authentication;
import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import java.io.InputStream;
import java.io.OutputStream;
......@@ -33,6 +37,7 @@ import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.Callable;
import java.util.logging.Logger;
/**
......@@ -43,8 +48,28 @@ import java.util.logging.Logger;
public class CliManagerImpl implements CliEntryPoint, Serializable {
private transient final Channel channel;
private Authentication transportAuth;
/**
* Runs callable from this CLI client with the transport authentication credential.
*/
private final CallableFilter authenticationFilter = new CallableFilter() {
public <V> V call(Callable<V> callable) throws Exception {
SecurityContext context = SecurityContextHolder.getContext();
Authentication old = context.getAuthentication();
if (transportAuth!=null)
context.setAuthentication(transportAuth);
try {
return callable.call();
} finally {
context.setAuthentication(old);
}
}
};
public CliManagerImpl(Channel channel) {
this.channel = channel;
channel.addLocalExecutionInterceptor(authenticationFilter);
}
public int main(List<String> args, Locale locale, InputStream stdin, OutputStream stdout, OutputStream stderr) {
......@@ -62,7 +87,8 @@ public class CliManagerImpl implements CliEntryPoint, Serializable {
cmd.channel = Channel.current();
final CLICommand old = CLICommand.setCurrent(cmd);
try {
cmd.setTransportAuth(Channel.current().getProperty(CLICommand.TRANSPORT_AUTHENTICATION));
transportAuth = Channel.current().getProperty(CLICommand.TRANSPORT_AUTHENTICATION);
cmd.setTransportAuth(transportAuth);
return cmd.main(args.subList(1,args.size()),locale, stdin, out, err);
} finally {
CLICommand.setCurrent(old);
......
......@@ -188,7 +188,7 @@ THE SOFTWARE.
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>remoting</artifactId>
<version>2.11</version>
<version>2.12</version>
</dependency>
<dependency>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册