Skip to content

Commit

Permalink
[JENKINS-18274] ComputerListener methods should be called as ACL.SYSTEM.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick authored and olivergondza committed Sep 25, 2013
1 parent 76163e2 commit b358d71
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions core/src/main/java/hudson/slaves/SlaveComputer.java
Expand Up @@ -39,6 +39,7 @@
import hudson.Util;
import hudson.AbortException;
import hudson.remoting.Launcher;
import hudson.security.ACL;
import static hudson.slaves.SlaveComputer.LogHolder.SLAVE_LOG_HANDLER;
import hudson.slaves.OfflineCause.ChannelTermination;
import hudson.util.Secret;
Expand Down Expand Up @@ -81,6 +82,8 @@
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponseWrapper;
import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import org.kohsuke.stapler.ResponseImpl;
import org.kohsuke.stapler.WebMethod;
import org.kohsuke.stapler.compression.FilterServletOutputStream;
Expand Down Expand Up @@ -446,8 +449,14 @@ public void onClosed(Channel c, IOException cause) {
channel.pinClassLoader(getClass().getClassLoader());

channel.call(new SlaveInitializer());
for (ComputerListener cl : ComputerListener.all())
cl.preOnline(this,channel,root,taskListener);
SecurityContext old = ACL.impersonate(ACL.SYSTEM);
try {
for (ComputerListener cl : ComputerListener.all()) {
cl.preOnline(this,channel,root,taskListener);
}
} finally {
SecurityContextHolder.setContext(old);
}

offlineCause = null;

Expand All @@ -472,8 +481,14 @@ public void onClosed(Channel c, IOException cause) {
statusChangeLock.notifyAll();
}
}
for (ComputerListener cl : ComputerListener.all())
cl.onOnline(this,taskListener);
old = ACL.impersonate(ACL.SYSTEM);
try {
for (ComputerListener cl : ComputerListener.all()) {
cl.onOnline(this,taskListener);
}
} finally {
SecurityContextHolder.setContext(old);
}
log.println("Slave successfully connected and online");
Jenkins.getInstance().getQueue().scheduleMaintenance();
}
Expand Down

0 comments on commit b358d71

Please sign in to comment.