Skip to content

Commit

Permalink
Exclude the plugin rooth path from requiring crumb
Browse files Browse the repository at this point in the history
  • Loading branch information
s0undt3ch authored and ydubreuil committed Apr 26, 2016
1 parent 1bfbfda commit a0b99f9
Showing 1 changed file with 26 additions and 5 deletions.
Expand Up @@ -35,15 +35,18 @@
import hudson.model.Queue;
import hudson.model.UnprotectedRootAction;
import hudson.security.ACL;
import hudson.security.csrf.CrumbExclusion;
import hudson.triggers.SCMTrigger;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;
import jenkins.model.Jenkins;
import jenkins.model.ParameterizedJobMixIn;
import jenkins.triggers.SCMTriggerItem;
Expand All @@ -62,9 +65,10 @@
public class BuildRootAction implements UnprotectedRootAction {

private static final Logger LOGGER = Logger.getLogger(BuildRootAction.class.getName());
public static final String URLNAME = "buildByToken";

@Override public String getUrlName() {
return "buildByToken";
return URLNAME;
}

@Override public String getIconFileName() {
Expand Down Expand Up @@ -107,10 +111,10 @@ public void doBuildWithParameters(StaplerRequest req, StaplerResponse rsp, @Quer
}
List<ParameterValue> values = new ArrayList<ParameterValue>();
for (ParameterDefinition d : pp.getParameterDefinitions()) {
ParameterValue value = d.createValue(req);
if (value != null) {
values.add(value);
}
ParameterValue value = d.createValue(req);
if (value != null) {
values.add(value);
}
}
Queue.Item item = Jenkins.getInstance().getQueue().schedule(p, delay.getTime(), new ParametersAction(values), getBuildCause(req));
if (item != null) {
Expand Down Expand Up @@ -188,4 +192,21 @@ private void ok(StaplerResponse rsp) throws IOException {
w.close();
}

@Extension
public static class BuildRootActionCrumbExclusion extends CrumbExclusion {

@Override
public boolean process(HttpServletRequest req, HttpServletResponse resp, FilterChain chain) throws IOException, ServletException {
String pathInfo = req.getPathInfo();
if (pathInfo != null && pathInfo.startsWith(getExclusionPath())) {
chain.doFilter(req, resp);
return true;
}
return false;
}

public String getExclusionPath() {
return "/" + URLNAME + "/";
}
}
}

0 comments on commit a0b99f9

Please sign in to comment.