@Override public boolean toggleCollapsed(String paneId) { final HttpSession session = Stapler.getCurrentRequest().getSession(); final String property = format(attribute, paneId); final Object collapsed = session.getAttribute(property); if (collapsed == null) { session.setAttribute(property, true); return true; } session.removeAttribute(property); return false; } }
/** * @param permission * Permission needed to perform this validation, or null if no permission is necessary. */ protected FormFieldValidator(Permission permission) { this(Stapler.getCurrentRequest(),Stapler.getCurrentResponse(),permission); }
public void handle(ServletRequest request, ServletResponse response, AccessDeniedException cause) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse rsp = (HttpServletResponse) response; rsp.setStatus(HttpServletResponse.SC_FORBIDDEN); req.setAttribute("exception",cause); if (cause instanceof AccessDeniedException2) { ((AccessDeniedException2)cause).reportAsHeaders(rsp); } WebApp.get(Jenkins.getInstance().servletContext).getSomeStapler() .invoke(req,rsp, Jenkins.getInstance(), "/accessDenied"); } }
@Initializer public static void init(final Jenkins j) throws IOException { CompressionFilter.setUncaughtExceptionHandler(j.servletContext, (e, context, req, rsp) -> { if (rsp.isCommitted()) { LOGGER.log(isEOFException(e) ? Level.FINE : Level.WARNING, null, e); return; } req.setAttribute("javax.servlet.error.exception",e); try { WebApp.get(j.servletContext).getSomeStapler().invoke(req, rsp, j, "/oops"); } catch (ServletException | IOException x) { if (!Stapler.isSocketException(x)) { throw x; } } }); try { Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler()); LOGGER.log(Level.FINE, "Successfully installed a global UncaughtExceptionHandler."); } catch (SecurityException ex) { LOGGER.log(Level.SEVERE, "Failed to set the default UncaughtExceptionHandler. " + "If any threads die due to unhandled coding errors then there will be no logging of this information. " + "The lack of this diagnostic information will make it harder to track down issues which will reduce the supportability of Jenkins. " + "It is highly recommended that you consult the documentation that comes with you servlet container on how to allow the " + "`setDefaultUncaughtExceptionHandler` permission and enable it.", ex); } }
Stapler stapler = Stapler.getCurrent(); if (stapler != null) { try { WebApp webapp = WebApp.getCurrent(); MetaClass meta = webapp.getMetaClass(this); Script s = meta.loadTearOff(JellyClassTearOff.class).findScript("newInstanceDetail"); if (s == null) { StringWriter sw = new StringWriter(); XMLOutput xml = dsi.createXMLOutput(sw, true); dsi.invokeScript(Stapler.getCurrentRequest(), Stapler.getCurrentResponse(), s, this, xml); return sw.toString(); } catch (Exception e) {
@Override public boolean isCollapsed(String paneId) { final HttpSession session = Stapler.getCurrentRequest().getSession(); return session.getAttribute(format(attribute, paneId)) != null; }
/** * Call this to show the upgrade wizard */ public HttpResponse doShowUpgradeWizard() throws Exception { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); HttpSession session = Stapler.getCurrentRequest().getSession(true); session.setAttribute(SHOW_UPGRADE_WIZARD_FLAG, true); return HttpResponses.redirectToContextRoot(); }
/** * Show the sign up page with the data from the identity. */ @Override public HttpResponse commenceSignup(final FederatedIdentity identity) { // store the identity in the session so that we can use this later Stapler.getCurrentRequest().getSession().setAttribute(FEDERATED_IDENTITY_SESSION_KEY,identity); return new ForwardToView(this,"signupWithFederatedIdentity.jelly") { @Override public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException { SignupInfo si = new SignupInfo(identity); si.errorMessage = Messages.HudsonPrivateSecurityRealm_WouldYouLikeToSignUp(identity.getPronoun(),identity.getIdentifier()); req.setAttribute("data", si); super.generateResponse(req, rsp, node); } }; }
public static String getFrom() { String from = null, returnValue = null; final StaplerRequest request = Stapler.getCurrentRequest(); && request.getSession(false) != null) { from = (String) request.getSession().getAttribute("from"); } else if (request != null) { from = request.getParameter("from");
/** * Call this to hide the upgrade wizard */ public HttpResponse doHideUpgradeWizard() { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); HttpSession session = Stapler.getCurrentRequest().getSession(false); if(session != null) { session.removeAttribute(SHOW_UPGRADE_WIZARD_FLAG); } return HttpResponses.redirectToContextRoot(); }
/** * Validates the captcha. */ protected final boolean validateCaptcha(String text) { if (captchaSupport != null) { String id = Stapler.getCurrentRequest().getSession().getId(); return captchaSupport.validateCaptcha(id, text); } // If no Captcha Support then bogus validation always returns true return true; }
@Override public Details newInstance(StaplerRequest req, JSONObject formData) throws FormException { if (req == null) { // Should never happen, see newInstance() Javadoc throw new FormException("Stapler request is missing in the call", "staplerRequest"); } String pwd = Util.fixEmpty(req.getParameter("user.password")); String pwd2= Util.fixEmpty(req.getParameter("user.password2")); if(!Util.fixNull(pwd).equals(Util.fixNull(pwd2))) throw new FormException("Please confirm the password by typing it twice","user.password2"); String data = Protector.unprotect(pwd); if(data!=null) { String prefix = Stapler.getCurrentRequest().getSession().getId() + ':'; if(data.startsWith(prefix)) return Details.fromHashedPassword(data.substring(prefix.length())); } User user = Util.getNearestAncestorOfTypeOrThrow(req, User.class); // the UserSeedProperty is not touched by the configure page UserSeedProperty userSeedProperty = user.getProperty(UserSeedProperty.class); if (userSeedProperty != null) { userSeedProperty.renewSeed(); } return Details.fromPlainPassword(Util.fixNull(pwd)); }
@Override public ConsoleAnnotator annotate(Object context, MarkupText text, int charPos) { String url = this.url; if (url.startsWith("/")) { StaplerRequest req = Stapler.getCurrentRequest(); if (req!=null) { // if we are serving HTTP request, we want to use app relative URL url = req.getContextPath()+url; } else { // otherwise presumably this is rendered for e-mails and other non-HTTP stuff url = Jenkins.getInstance().getRootUrl()+url.substring(1); } } text.addMarkup(charPos, charPos + length, "<a href='" + url + "'"+extraAttributes()+">", "</a>"); return null; }
View view=null; StaplerRequest request = Stapler.getCurrentRequest(); for( Ancestor a : request.getAncestors() ) { ancestors.put(a.getObject(),a.getRelativePath()); if(a.getObject() instanceof View) view = (View) a.getObject(); return normalizeURI(path + '/'); url = i.getShortUrl()+url; if(ig== Jenkins.getInstance() || (view != null && ig == view.getOwner().getItemGroup())) { assert i instanceof TopLevelItem; if (view != null) { return normalizeURI(ancestors.get(view)+'/'+url); } else { return normalizeURI(request.getContextPath()+'/'+p.getUrl());
/** * Obtains the host name of the Hudson server that clients can use to talk back to. * <p> * This is primarily used in {@code slave-agent.jnlp.jelly} to specify the destination * that the agents talk to. */ public String getServerName() { // Try to infer this from the configured root URL. // This makes it work correctly when Hudson runs behind a reverse proxy. String url = Jenkins.getInstance().getRootUrl(); try { if(url!=null) { String host = new URL(url).getHost(); if(host!=null) return host; } } catch (MalformedURLException e) { // fall back to HTTP request } return Stapler.getCurrentRequest().getServerName(); }
private static void checkPermissionForValidate() { AccessControlled subject = Stapler.getCurrentRequest().findAncestorObject(AbstractProject.class); if (subject == null) Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); else subject.checkPermission(Item.CONFIGURE); }
public HttpResponse doTest() { String referer = Stapler.getCurrentRequest().getReferer(); Jenkins j = Jenkins.getInstance(); // May need to send an absolute URL, since handling of HttpRedirect with a relative URL does not currently honor X-Forwarded-Proto/Port at all. String redirect = j.getRootUrl() + "administrativeMonitor/" + id + "/testForReverseProxySetup/" + (referer != null ? Util.rawEncode(referer) : "NO-REFERER") + "/"; LOGGER.log(Level.FINE, "coming from {0} and redirecting to {1}", new Object[] {referer, redirect}); return new HttpRedirect(redirect); }
/** * This version is so that the 'hasPermission' can degrade gracefully * if "it" is not an {@link AccessControlled} object. */ public static boolean hasPermission(Object object, Permission permission) throws IOException, ServletException { if (permission == null) return true; if (object instanceof AccessControlled) return ((AccessControlled)object).hasPermission(permission); else { List<Ancestor> ancs = Stapler.getCurrentRequest().getAncestors(); for(Ancestor anc : Iterators.reverse(ancs)) { Object o = anc.getObject(); if (o instanceof AccessControlled) { return ((AccessControlled)o).hasPermission(permission); } } return Jenkins.getInstance().hasPermission(permission); } }
if(Jenkins.getInstance().hasPermission(Jenkins.READ)) { long now = System.currentTimeMillis(); for (Downloadable d : Downloadable.all()) { .append("{version:"+QuotedStringTokenizer.quote(Jenkins.VERSION)+'}') .append(',') .append(QuotedStringTokenizer.quote(Stapler.getCurrentRequest().getContextPath()+'/'+getUrl()+"/byId/"+d.getId()+"/postBack")) .append(',') .append("null);")
/** * This version is so that the 'checkPermission' on {@code layout.jelly} * degrades gracefully if "it" is not an {@link AccessControlled} object. * Otherwise it will perform no check and that problem is hard to notice. */ public static void checkPermission(Object object, Permission permission) throws IOException, ServletException { if (permission == null) return; if (object instanceof AccessControlled) checkPermission((AccessControlled) object,permission); else { List<Ancestor> ancs = Stapler.getCurrentRequest().getAncestors(); for(Ancestor anc : Iterators.reverse(ancs)) { Object o = anc.getObject(); if (o instanceof AccessControlled) { checkPermission((AccessControlled) o,permission); return; } } checkPermission(Jenkins.getInstance(),permission); } }