Search in sources :

Example 1 with AccessDeniedException

use of org.acegisecurity.AccessDeniedException in project workflow-cps-plugin by jenkinsci.

the class ReplayAction method doRun.

@Restricted(DoNotUse.class)
@RequirePOST
public void doRun(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException {
    if (!isEnabled() || !(isReplayableSandboxTest())) {
        // AccessDeniedException2 requires us to look up the specific Permission
        throw new AccessDeniedException("not allowed to replay");
    }
    JSONObject form = req.getSubmittedForm();
    // Copy originalLoadedScripts, replacing values with those from the form wherever defined.
    Map<String, String> replacementLoadedScripts = new HashMap<>();
    for (Map.Entry<String, String> entry : getOriginalLoadedScripts().entrySet()) {
        // optString since you might be replaying a running build, which might have loaded a script after the page load but before submission.
        replacementLoadedScripts.put(entry.getKey(), form.optString(entry.getKey().replace('.', '_'), entry.getValue()));
    }
    if (run(form.getString("mainScript"), replacementLoadedScripts) == null) {
        throw HttpResponses.error(SC_CONFLICT, new IOException(run.getParent().getFullName() + " is not buildable"));
    }
    // back to WorkflowJob; new build might not start instantly so cannot redirect to it
    rsp.sendRedirect("../..");
}
Also used : AccessDeniedException(org.acegisecurity.AccessDeniedException) JSONObject(net.sf.json.JSONObject) HashMap(java.util.HashMap) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) RequirePOST(org.kohsuke.stapler.interceptor.RequirePOST) Restricted(org.kohsuke.accmod.Restricted)

Aggregations

IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 JSONObject (net.sf.json.JSONObject)1 AccessDeniedException (org.acegisecurity.AccessDeniedException)1 Restricted (org.kohsuke.accmod.Restricted)1 RequirePOST (org.kohsuke.stapler.interceptor.RequirePOST)1