/** * Convenience method to verify that the current request is a POST request. * * @deprecated * Use {@link RequirePOST} on your method. */ @Deprecated protected final void requirePOST() throws ServletException { StaplerRequest req = Stapler.getCurrentRequest(); if (req==null) return; // invoked outside the context of servlet String method = req.getMethod(); if(!method.equalsIgnoreCase("POST")) throw new ServletException("Must be POST, Can't be "+method); }
/** * 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()); }
/** * Perform a restart of Jenkins, if we can. * * This first replaces "app" to {@link HudsonIsRestarting} */ @CLIMethod(name="restart") public void doRestart(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, RestartNotSupportedException { checkPermission(ADMINISTER); if (req != null && req.getMethod().equals("GET")) { req.getView(this,"_restart.jelly").forward(req,rsp); return; } if (req == null || req.getMethod().equals("POST")) { restart(); } if (rsp != null) { rsp.sendRedirect2("."); } }
/** * Queues up a restart of Jenkins for when there are no builds running, if we can. * * This first replaces "app" to {@link HudsonIsRestarting} * * @since 1.332 */ @CLIMethod(name="safe-restart") public HttpResponse doSafeRestart(StaplerRequest req) throws IOException, ServletException, RestartNotSupportedException { checkPermission(ADMINISTER); if (req != null && req.getMethod().equals("GET")) return HttpResponses.forwardToView(this,"_safeRestart.jelly"); if (req == null || req.getMethod().equals("POST")) { safeRestart(); } return HttpResponses.redirectToDot(); }
/** * Accepts {@code config.xml} submission, as well as serve it. */ @WebMethod(name = "config.xml") public void doConfigDotXml(StaplerRequest req, StaplerResponse rsp) throws IOException { if (req.getMethod().equals("GET")) { // read rsp.setContentType("application/xml"); writeConfigDotXml(rsp.getOutputStream()); return; } if (req.getMethod().equals("POST")) { // submission updateByXml((Source)new StreamSource(req.getReader())); return; } // huh? rsp.sendError(SC_BAD_REQUEST); }
/** * @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); }
@Override public Object getTarget() { StaplerRequest req = Stapler.getCurrentRequest(); if (req.getRestOfPath().length()==0 && "POST".equals(req.getMethod())) { // CLI connection request if ("false".equals(req.getParameter("remoting"))) { throw new PlainCliEndpointResponse(); } else if (jenkins.CLI.get().isEnabled()) { throw new RemotingCliEndpointResponse(); } else { throw HttpResponses.forbidden(); } } else { return this; } }
private WebHookAction resolveAction(Item project, String restOfPath, StaplerRequest request) { String method = request.getMethod(); if (method.equals("POST")) { return onPost(project, request); } else if (method.equals("GET")) { if (project instanceof Job<?, ?>) { return onGet((Job<?, ?>) project, restOfPath, request); } else { LOGGER.log(Level.FINE, "GET is not supported for this project {0}", project.getName()); return new NoopAction(); } } LOGGER.log(Level.FINE, "Unsupported HTTP method: {0}", method); return new NoopAction(); }
/** * Accepts and serves the job description */ public void doDescription(StaplerRequest req, StaplerResponse rsp) throws IOException { if (req.getMethod().equals("GET")) { //read rsp.setContentType("text/plain;charset=UTF-8"); rsp.getWriter().write(Util.fixNull(this.getDescription())); return; } if (req.getMethod().equals("POST")) { checkPermission(CONFIGURE); // submission if (req.getParameter("description") != null) { this.setDescription(req.getParameter("description")); rsp.sendError(SC_NO_CONTENT); return; } } // huh? rsp.sendError(SC_BAD_REQUEST); }
/** * Accepts {@code config.xml} submission, as well as serve it. */ @WebMethod(name = "config.xml") public void doConfigDotXml(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { if (req.getMethod().equals("GET")) { // read checkPermission(EXTENDED_READ); rsp.setContentType("application/xml"); Node node = getNode(); if (node == null) { throw HttpResponses.notFound(); } Jenkins.XSTREAM2.toXMLUTF8(node, rsp.getOutputStream()); return; } if (req.getMethod().equals("POST")) { // submission updateByXml(req.getInputStream()); return; } // huh? rsp.sendError(SC_BAD_REQUEST); }
public static void checkPermission(Job<?,?> project, BuildAuthorizationToken token, StaplerRequest req, StaplerResponse rsp) throws IOException { if (!Jenkins.getInstance().isUseSecurity()) return; // everyone is authorized if(token!=null && token.token != null) { //check the provided token String providedToken = req.getParameter("token"); if (providedToken != null && providedToken.equals(token.token)) return; if (providedToken != null) throw new AccessDeniedException(Messages.BuildAuthorizationToken_InvalidTokenProvided()); } project.checkPermission(Item.BUILD); if (req.getMethod().equals("POST")) { return; } if (req.getAttribute(ApiTokenProperty.class.getName()) instanceof User) { return; } rsp.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); rsp.addHeader("Allow", "POST"); throw HttpResponses.forwardToView(project, "requirePOST.jelly"); }
/** * 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("."); } }
/** * Convenience method to verify that the current request is a POST request. */ protected final void requirePOST() throws ServletException { StaplerRequest req = Stapler.getCurrentRequest(); if (req==null) return; // invoked outside the context of servlet String method = req.getMethod(); if(!method.equalsIgnoreCase("POST")) throw new ServletException("Must be POST, Can't be "+method); }
/** * Convenience method to verify that the current request is a POST request. */ protected final void requirePOST() throws ServletException { StaplerRequest req = Stapler.getCurrentRequest(); if (req==null) return; // invoked outside the context of servlet String method = req.getMethod(); if(!method.equalsIgnoreCase("POST")) throw new ServletException("Must be POST, Can't be "+method); }
/** * Convenience method to verify that the current request is a POST request. */ protected final void requirePOST() throws ServletException { StaplerRequest req = Stapler.getCurrentRequest(); if (req==null) return; // invoked outside the context of servlet String method = req.getMethod(); if(!method.equalsIgnoreCase("POST")) throw new ServletException("Must be POST, Can't be "+method); }
/** * 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")); } }
/** * Convenience method to verify that the current request is a POST request. */ protected final void requirePOST() throws ServletException { StaplerRequest req = Stapler.getCurrentRequest(); if (req == null) { return; // invoked outside the context of servlet } String method = req.getMethod(); if (!method.equalsIgnoreCase("POST")) { throw new ServletException("Must be POST, Can't be " + method); } }
/** * Convenience method to verify that the current request is a POST request. * * @deprecated * Use {@link RequirePOST} on your method. */ @Deprecated protected final void requirePOST() throws ServletException { StaplerRequest req = Stapler.getCurrentRequest(); if (req==null) return; // invoked outside the context of servlet String method = req.getMethod(); if(!method.equalsIgnoreCase("POST")) throw new ServletException("Must be POST, Can't be "+method); }
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")); } }
public void doIndex(final StaplerRequest req, final StaplerResponse response) throws IOException { String payload = req.getParameter("payload"); if (StringUtils.isEmpty(payload) && "POST".equalsIgnoreCase(req.getMethod())) { payload = getRequestPayload(req); } if (StringUtils.isEmpty(payload)) { throw new IllegalArgumentException("Not intended to be browsed interactively (must specify payload parameter)"); } processGitHubPayload(req.getHeader("X-GitHub-Event"), payload); }