public MenuItem withUrl(String url) { try { this.url = new URI(Stapler.getCurrentRequest().getRequestURI()).resolve(new URI(url)).toString(); } catch (URISyntaxException x) { throw new IllegalArgumentException("Bad URI from " + Stapler.getCurrentRequest().getRequestURI() + " vs. " + url, x); } return this; }
/** * This method serves static resources in the plugin under {@code hudson/plugin/SHORTNAME}. */ public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { String path = req.getRestOfPath(); String pathUC = path.toUpperCase(Locale.ENGLISH); if (path.isEmpty() || path.contains("..") || path.startsWith(".") || path.contains("%") || pathUC.contains("META-INF") || pathUC.contains("WEB-INF") // ClassicPluginStrategy#explode produce that file to know if a new explosion is required or not || pathUC.equals("/.TIMESTAMP2") ) { LOGGER.warning("rejecting possibly malicious " + req.getRequestURIWithQueryString()); rsp.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } // Stapler routes requests like the "/static/.../foo/bar/zot" to be treated like "/foo/bar/zot" // and this is used to serve long expiration header, by using Jenkins.VERSION_HASH as "..." // to create unique URLs. Recognize that and set a long expiration header. String requestPath = req.getRequestURI().substring(req.getContextPath().length()); boolean staticLink = requestPath.startsWith("/static/"); long expires = staticLink ? TimeUnit.DAYS.toMillis(365) : -1; // use serveLocalizedFile to support automatic locale selection rsp.serveLocalizedFile(req, new URL(wrapper.baseResourceURL, '.' + path), expires); }
&& request.getRequestURI() != null && !request.getRequestURI().equals("/loginError") && !request.getRequestURI().equals("/login")) { from = request.getRequestURI();
/** * Exposes assets in the core classloader over HTTP. */ public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { String path = req.getRestOfPath(); URL resource = findResource(path); if (resource == null) { rsp.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } // Stapler routes requests like the "/static/.../foo/bar/zot" to be treated like "/foo/bar/zot" // and this is used to serve long expiration header, by using Jenkins.VERSION_HASH as "..." // to create unique URLs. Recognize that and set a long expiration header. String requestPath = req.getRequestURI().substring(req.getContextPath().length()); boolean staticLink = requestPath.startsWith("/static/"); long expires = staticLink ? TimeUnit.DAYS.toMillis(365) : -1; // use serveLocalizedFile to support automatic locale selection rsp.serveLocalizedFile(req, resource, expires); }
String uri = req == null ? null : req.getRequestURI(); if (req != null) { String seed = Functions.getNearestAncestorUrl(req,this);
@Override public Object getTarget() { final StaplerRequest currentRequest = Stapler.getCurrentRequest(); //@formatter:off if (!currentRequest.getRequestURI().matches(".*(api/(json|xml)).*") && !currentRequest.getRequestURI().contains("buildWithParameters") && !currentRequest.getRequestURI().contains("logTail") && !currentRequest.getRequestURI().contains("artifact")) { //@formatter:on authenticate(); } return this; }
public MenuItem withUrl(String url) { try { this.url = new URI(Stapler.getCurrentRequest().getRequestURI()).resolve(new URI(url)).toString(); } catch (URISyntaxException x) { throw new IllegalArgumentException("Bad URI from " + Stapler.getCurrentRequest().getRequestURI() + " vs. " + url, x); } return this; }
@Override public void sendRedirect(@Nonnull String url) throws IOException { // WebSphere doesn't apparently handle relative URLs, so // to be safe, always resolve relative URLs to absolute URLs by ourselves. // see http://www.nabble.com/Hudson%3A-1.262%3A-Broken-link-using-update-manager-to21067157.html if(url.startsWith("http://") || url.startsWith("https://") || url.startsWith("/")) { // absolute URLs super.sendRedirect(url); return; } // example: /foo/bar/zot + ../abc -> /foo/bar/../abc String base = Stapler.getCurrentRequest().getRequestURI(); base = base.substring(0,base.lastIndexOf('/')+1); if(!url.equals(".")) base += url; super.sendRedirect(base); }
private InheritanceProject getProjectFromRequest(StaplerRequest req) { //First, we check if an ancestor is defined InheritanceProject ip = req.findAncestorObject(InheritanceProject.class); if (ip != null) { return ip; } //Otherwise, we decode the URI and try to find the project that way String jobName = null; String uri = req.getRequestURI(); if (uri != null && !uri.isEmpty()) { Matcher m = DescriptorImpl.urlJobPattern.matcher(uri); if (m.find()) { if (m.group(1) != null && !m.group(1).isEmpty()) { jobName = m.group(1); } } } ip = null; if (jobName != null) { ip = InheritanceProject.getProjectByName(jobName); } return ip; }
@Override public void sendRedirect(@Nonnull String url) throws IOException { // WebSphere doesn't apparently handle relative URLs, so // to be safe, always resolve relative URLs to absolute URLs by ourselves. // see http://www.nabble.com/Hudson%3A-1.262%3A-Broken-link-using-update-manager-to21067157.html if(url.startsWith("http://") || url.startsWith("https://") || url.startsWith("/")) { // absolute URLs super.sendRedirect(url); return; } // example: /foo/bar/zot + ../abc -> /foo/bar/../abc String base = Stapler.getCurrentRequest().getRequestURI(); base = base.substring(0,base.lastIndexOf('/')+1); if(!url.equals(".")) base += url; super.sendRedirect(base); }
@Override public void sendRedirect(String url) throws IOException { // WebSphere doesn't apparently handle relative URLs, so // to be safe, always resolve relative URLs to absolute URLs by ourselves. // see http://www.nabble.com/Hudson%3A-1.262%3A-Broken-link-using-update-manager-to21067157.html if(url.startsWith("http://") || url.startsWith("https://") || url.startsWith("/")) { // absolute URLs super.sendRedirect(url); return; } // example: /foo/bar/zot + ../abc -> /foo/bar/../abc String base = Stapler.getCurrentRequest().getRequestURI(); base = base.substring(0,base.lastIndexOf('/')+1); if(!url.equals(".")) base += url; super.sendRedirect(base); }
/** * This method serves static resources in the plugin under <tt>hudson/plugin/SHORTNAME</tt>. */ public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { String path = req.getRestOfPath(); if (path.startsWith("/META-INF/") || path.startsWith("/WEB-INF/")) { throw HttpResponses.notFound(); } if(path.length()==0) path = "/"; // Stapler routes requests like the "/static/.../foo/bar/zot" to be treated like "/foo/bar/zot" // and this is used to serve long expiration header, by using Jenkins.VERSION_HASH as "..." // to create unique URLs. Recognize that and set a long expiration header. String requestPath = req.getRequestURI().substring(req.getContextPath().length()); boolean staticLink = requestPath.startsWith("/static/"); long expires = staticLink ? TimeUnit.DAYS.toMillis(365) : -1; // use serveLocalizedFile to support automatic locale selection try { rsp.serveLocalizedFile(req, wrapper.baseResourceURL.toURI().resolve(new URI(null, '.' + path, null)).toURL(), expires); } catch (URISyntaxException x) { throw new IOException(x); } }
/** * This method serves static resources in the plugin under * <tt>hudson/plugin/SHORTNAME</tt>. */ public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, URISyntaxException { String path = req.getRestOfPath(); if (path.length() == 0) { path = "/"; } String requestPath = req.getRequestURI().substring(req.getContextPath().length()); boolean staticLink = requestPath.startsWith("/static/"); long expires = staticLink ? TimeUnit2.DAYS.toMillis(365) : -1; try { rsp.serveLocalizedFile(req, wrapper.baseResourceURL.toURI().resolve(new URI(null, '.' + path, null)).toURL(), expires); } catch (URISyntaxException x) { throw new IOException(x); } }
/** * Bitbucket send <a href="https://confluence.atlassian.com/display/BITBUCKET/Write+brokers+(hooks)+for+Bitbucket">payload</a> * as form-urlencoded <pre>payload=JSON</pre> * @throws IOException */ public void doIndex(StaplerRequest req) throws IOException { String body = IOUtils.toString(req.getInputStream()); if (!body.isEmpty() && req.getRequestURI().contains("/" + BITBUCKET_HOOK_URL + "/")) { String contentType = req.getContentType(); if (contentType != null && contentType.startsWith("application/x-www-form-urlencoded")) { body = URLDecoder.decode(body); } if (body.startsWith("payload=")) body = body.substring(8); LOGGER.log(Level.FINE, "Received commit hook notification : {0}", body); JSONObject payload = JSONObject.fromObject(body); payloadProcessor.processPayload(payload, req); } else { LOGGER.log(Level.WARNING, "The Jenkins job cannot be triggered. You might no have configured correctly the WebHook on BitBucket with the last slash `http://<JENKINS-URL>/bitbucket-hook/`"); } }
@SuppressWarnings("unchecked") private void removeActions(Class type, StaplerRequest req, StaplerResponse rsp) throws IOException { req.findAncestorObject(Job.class).checkPermission(Run.UPDATE); Run run = req.findAncestorObject(Run.class); if (run != null) { List<Action> actions = run.getActions(); List<Action> groovyActions = run.getActions(type); for(Action action : groovyActions) { actions.remove(action); } run.save(); rsp.sendRedirect(req.getRequestURI().substring(0, req.getRequestURI().indexOf("parent/parent"))); } }
@SuppressWarnings("unchecked") private void removeAction(Class type, StaplerRequest req, StaplerResponse rsp) throws IOException { String index = req.getParameter("index"); if(index == null) { throw new IOException("Missing parameter 'index'."); } int idx; try { idx = Integer.parseInt(index); } catch (NumberFormatException e) { throw new IOException("Invalid index: " + index); } req.findAncestorObject(Job.class).checkPermission(Run.UPDATE); Run run = req.findAncestorObject(Run.class); if (run != null) { List<Action> actions = run.getActions(); List<Action> groovyActions = run.getActions(type); if(idx < 0 || idx >= groovyActions.size()) { throw new IOException("Index out of range: " + idx); } actions.remove(groovyActions.get(idx)); run.save(); rsp.sendRedirect(req.getRequestURI().substring(0, req.getRequestURI().indexOf("parent/parent"))); } } }
/** * Exposes assets in the core classloader over HTTP. */ public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { String path = req.getRestOfPath(); URL resource = findResource(path); if (resource == null) { rsp.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } // Stapler routes requests like the "/static/.../foo/bar/zot" to be treated like "/foo/bar/zot" // and this is used to serve long expiration header, by using Jenkins.VERSION_HASH as "..." // to create unique URLs. Recognize that and set a long expiration header. String requestPath = req.getRequestURI().substring(req.getContextPath().length()); boolean staticLink = requestPath.startsWith("/static/"); long expires = staticLink ? TimeUnit.DAYS.toMillis(365) : -1; // use serveLocalizedFile to support automatic locale selection rsp.serveLocalizedFile(req, resource, expires); }
/** * {@inheritDoc} */ @Exported @Override public boolean isConcurrentBuild() { //Check if we're called from a configure page; if so, do not inherit //In all other cases, do full inheritance StaplerRequest req = Stapler.getCurrentRequest(); if (req != null && req.getRequestURI().endsWith("/configure")) { return this.isConcurrentBuildFast(false); } return this.isConcurrentBuildFast(true); }
@Override public boolean filter(Object context, Descriptor descriptor) { StaplerRequest req = Stapler.getCurrentRequest(); // View/newJob.jelly for 1.x, View.doItemCategories for 2.x if (req == null || !req.getRequestURI().matches(".*/(newJob|itemCategories)")) { return true; } if (!(descriptor instanceof TopLevelItemDescriptor)) { return true; } Folder d; if (context instanceof Folder) { d = ((Folder) context); } else if (context instanceof View && ((View) context).getOwnerItemGroup() instanceof Folder) { d = (Folder) ((View) context).getOwnerItemGroup(); } else { return true; } return d.isAllowedChildDescriptor((TopLevelItemDescriptor) descriptor); }
@Override public boolean filter(Object context, Descriptor descriptor) { StaplerRequest req = Stapler.getCurrentRequest(); // View/newJob.jelly for 1.x, View.doItemCategories for 2.x if (req == null || !req.getRequestURI().matches(".*/(newJob|itemCategories)")) { return true; } if (!(descriptor instanceof TopLevelItemDescriptor)) { return true; } Folder d; if (context instanceof Folder) { d = ((Folder) context); } else if (context instanceof View && ((View) context).getOwner().getItemGroup() instanceof Folder) { d = (Folder) ((View) context).getOwner().getItemGroup(); } else { return true; } return d.isAllowedChildDescriptor((TopLevelItemDescriptor) descriptor); }