/** * @since 1.509.1 */ public static void _doScript(StaplerRequest req, StaplerResponse rsp, RequestDispatcher view, VirtualChannel channel, ACL acl) throws IOException, ServletException { // ability to run arbitrary script is dangerous acl.checkPermission(RUN_SCRIPTS); String text = req.getParameter("script"); if (text != null) { if (!"POST".equals(req.getMethod())) { throw HttpResponses.error(HttpURLConnection.HTTP_BAD_METHOD, "requires POST"); } if (channel == null) { throw HttpResponses.error(HttpURLConnection.HTTP_NOT_FOUND, "Node is offline"); } try { req.setAttribute("output", RemotingDiagnostics.executeGroovy(text, channel)); } catch (InterruptedException e) { throw new ServletException(e); } } view.forward(req, rsp); }
private User _doCreateAccount(StaplerRequest req, StaplerResponse rsp, String formView) throws ServletException, IOException { if(!allowsSignup()) throw HttpResponses.error(SC_UNAUTHORIZED,new Exception("User sign up is prohibited")); boolean firstUser = !hasSomeUser(); User u = createAccount(req, rsp, enableCaptcha, formView); if(u!=null) { if(firstUser) tryToMakeAdmin(u); // the first user should be admin, or else there's a risk of lock out loginAndTakeBack(req, rsp, u); } return u; }
/** * Accepts {@code config.xml} submission, as well as serve it. */ @WebMethod(name = "config.xml") public HttpResponse doConfigDotXml(StaplerRequest req) throws IOException { if (req.getMethod().equals("GET")) { // read checkPermission(READ); return new HttpResponse() { public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException { rsp.setContentType("application/xml"); View.this.writeXml(rsp.getOutputStream()); } }; } if (req.getMethod().equals("POST")) { // submission updateByXml(new StreamSource(req.getReader())); return HttpResponses.ok(); } // huh? return HttpResponses.error(SC_BAD_REQUEST, "Unexpected request method " + req.getMethod()); }
/** * Standard implementation of {@link ParameterizedJob#doBuildWithParameters}. */ @SuppressWarnings("deprecation") public final void doBuildWithParameters(StaplerRequest req, StaplerResponse rsp, @QueryParameter TimeDuration delay) throws IOException, ServletException { hudson.model.BuildAuthorizationToken.checkPermission(asJob(), asJob().getAuthToken(), req, rsp); ParametersDefinitionProperty pp = asJob().getProperty(ParametersDefinitionProperty.class); if (!asJob().isBuildable()) { throw HttpResponses.error(SC_CONFLICT, new IOException(asJob().getFullName() + " is not buildable!")); } if (pp != null) { pp.buildWithParameters(req, rsp, delay); } else { throw new IllegalStateException("This build is not parameterized!"); } }
/** * When the agent is deleted, free the node right away. */ @Override @RequirePOST public HttpResponse doDoDelete() throws IOException { checkPermission(DELETE); try { T node = getNode(); if (node != null) { // No need to terminate nodes again node.terminate(); } return new HttpRedirect(".."); } catch (InterruptedException e) { return HttpResponses.error(500,e); } } }
/** * Standard implementation of {@link ParameterizedJob#doBuild}. */ @SuppressWarnings("deprecation") public final void doBuild(StaplerRequest req, StaplerResponse rsp, @QueryParameter TimeDuration delay) throws IOException, ServletException { if (delay == null) { delay=new TimeDuration(TimeUnit.MILLISECONDS.convert(asJob().getQuietPeriod(), TimeUnit.SECONDS)); } if (!asJob().isBuildable()) { throw HttpResponses.error(SC_CONFLICT, new IOException(asJob().getFullName() + " is not buildable")); } // if a build is parameterized, let that take over ParametersDefinitionProperty pp = asJob().getProperty(ParametersDefinitionProperty.class); if (pp != null && !req.getMethod().equals("POST")) { // show the parameter entry form. req.getView(pp, "index.jelly").forward(req, rsp); return; } hudson.model.BuildAuthorizationToken.checkPermission(asJob(), asJob().getAuthToken(), req, rsp); if (pp != null) { pp._doBuild(req, rsp, delay); return; } Queue.Item item = Jenkins.getInstance().getQueue().schedule2(asJob(), delay.getTimeInSeconds(), getBuildCause(asJob(), req)).getItem(); if (item != null) { rsp.sendRedirect(SC_CREATED, req.getContextPath() + '/' + item.getUrl()); } else { rsp.sendRedirect("."); } }
/** * Sends an error with a stack trace. * @see #errorWithoutStack */ @SuppressWarnings({"ThrowableInstanceNeverThrown"}) public static HttpResponseException error(int code, String errorMessage) { return error(code,new Exception(errorMessage)); }
@SuppressWarnings({"ThrowableInstanceNeverThrown"}) public static HttpResponseException error(int code, String errorMessage) { return error(code,new Exception(errorMessage)); }
/** * Sends an error with a stack trace. * @see #errorWithoutStack */ @SuppressWarnings({"ThrowableInstanceNeverThrown"}) public static HttpResponseException error(int code, String errorMessage) { return error(code,new Exception(errorMessage)); }
public HttpResponse doNotifyCommit(@QueryParameter(required=true) final String url) throws ServletException, IOException { // run in high privilege to see all the projects anonymous users don't see. // this is safe because we only initiate polling. //SecurityContext securityContext = ACL.impersonate(ACL.SYSTEM); try { return handleNotifyCommit(new URI(url)); } catch ( URISyntaxException ex ) { throw HttpResponses.error(SC_BAD_REQUEST, ex); } finally { //SecurityContextHolder.setContext(securityContext); } }
/** * Duplicates {@link @org.kohsuke.stapler.interceptor.RequirePOST} precheck. * As of it can't guarantee order of multiply interceptor calls, * it should implement all features of required interceptors in one class * * @throws InvocationTargetException if method os not POST */ protected void shouldBePostMethod(StaplerRequest request) throws InvocationTargetException { if (!request.getMethod().equals("POST")) { throw new InvocationTargetException(error(SC_METHOD_NOT_ALLOWED, "Method POST required")); } }
protected void check(StaplerRequest request) throws InvocationTargetException { if (!request.getMethod().equals("POST")) { throw new InvocationTargetException(error(SC_METHOD_NOT_ALLOWED, "Method POST required")); } if (request.getHeader("User-Agent") == null || request.getHeader("User-Agent").toLowerCase().indexOf("coding") == -1 ){ throw new InvocationTargetException(error(SC_METHOD_NOT_ALLOWED, "From Coding.Net required")); } }
private User _doCreateAccount(StaplerRequest req, StaplerResponse rsp, String formView) throws ServletException, IOException { if(!allowsSignup()) throw HttpResponses.error(SC_UNAUTHORIZED,new Exception("User sign up is prohibited")); boolean firstUser = !hasSomeUser(); User u = createAccount(req, rsp, enableCaptcha, formView); if(u!=null) { if(firstUser) tryToMakeAdmin(u); // the first user should be admin, or else there's a risk of lock out loginAndTakeBack(req, rsp, u); } return u; }
private User _doCreateAccount(StaplerRequest req, StaplerResponse rsp, String formView) throws ServletException, IOException { if(!allowsSignup()) throw HttpResponses.error(SC_UNAUTHORIZED,new Exception("User sign up is prohibited")); boolean firstUser = !hasSomeUser(); User u = createAccount(req, rsp, enableCaptcha, formView); if(u!=null) { if(firstUser) tryToMakeAdmin(u); // the first user should be admin, or else there's a risk of lock out loginAndTakeBack(req, rsp, u); } return u; }
private User _doCreateAccount(StaplerRequest req, StaplerResponse rsp, String formView) throws ServletException, IOException { if(!allowsSignup()) throw HttpResponses.error(SC_UNAUTHORIZED,new Exception("User sign up is prohibited")); boolean firstUser = !hasSomeUser(); User u = createAccount(req, rsp, enableCaptcha, formView); if(u!=null) { if(firstUser) tryToMakeAdmin(u); // the first user should be admin, or else there's a risk of lock out loginAndTakeBack(req, rsp, u); } return u; }
private User _doCreateAccount(StaplerRequest req, StaplerResponse rsp, String formView) throws ServletException, IOException { if(!allowsSignup()) throw HttpResponses.error(SC_UNAUTHORIZED,new Exception("User sign up is prohibited")); boolean firstUser = !hasSomeUser(); User u = createAccount(req, rsp, enableCaptcha, formView); if(u!=null) { if(firstUser) tryToMakeAdmin(u); // the first user should be admin, or else there's a risk of lock out loginAndTakeBack(req, rsp, u); } return u; }
private User _doCreateAccount(StaplerRequest req, StaplerResponse rsp, String formView) throws ServletException, IOException { if (!allowsSignup()) { throw HttpResponses.error(SC_UNAUTHORIZED, new Exception("User sign up is prohibited")); } boolean firstUser = !hasSomeUser(); User u = createAccount(req, rsp, enableCaptcha, formView); if (u != null) { if (firstUser) { tryToMakeAdmin(u); // the first user should be admin, or else there's a risk of lock out } loginAndTakeBack(req, rsp, u); } return u; }
@Override @Restricted(NoExternalUse.class) @RequirePOST public HttpResponse doDoDelete() { checkPermission(Permission.DELETE); try { deleteSlave(); return new HttpRedirect(".."); } catch (Exception ex) { return HttpResponses.error(500, ex); } }
@RequirePOST public HttpResponse doBuild(@QueryParameter TimeDuration delay) { checkPermission(BUILD); if (!isBuildable()) { throw HttpResponses.error(SC_INTERNAL_SERVER_ERROR, new IOException(getFullName() + " cannot be recomputed")); } scheduleBuild2(delay == null ? 0 : delay.getTime(), new CauseAction(new Cause.UserIdCause())); return HttpResponses.forwardToPreviousPage(); }
@RequirePOST public HttpResponse doBuild(@QueryParameter TimeDuration delay) { checkPermission(BUILD); if (!isBuildable()) { throw HttpResponses.error(SC_INTERNAL_SERVER_ERROR, new IOException(getFullName() + " cannot be recomputed")); } scheduleBuild2(delay == null ? 0 : delay.getTimeInSeconds(), new CauseAction(new Cause.UserIdCause())); return HttpResponses.forwardToPreviousPage(); }