@Override protected HttpServletResponse getHttpServletResponse() { return ServletActionContext.getResponse(); }
/** * The default writer writes directly to the response writer. */ protected Writer getWriter() throws IOException { return ServletActionContext.getResponse().getWriter(); }
/** * Prints the current context to the response in XML format. */ protected void printContext() { HttpServletResponse res = ServletActionContext.getResponse(); res.setContentType("text/xml"); try { PrettyPrintWriter writer = new PrettyPrintWriter( ServletActionContext.getResponse().getWriter()); printContext(writer); writer.close(); } catch (IOException ex) { ex.printStackTrace(); } }
/** * Executes the regular servlet result. * * @param finalLocation * @param actionInvocation */ private void executeRegularServletResult(String finalLocation, ActionInvocation actionInvocation) throws ServletException, IOException { ServletContext ctx = ServletActionContext.getServletContext(); HttpServletRequest req = ServletActionContext.getRequest(); HttpServletResponse res = ServletActionContext.getResponse(); try { ctx.getRequestDispatcher(finalLocation).include(req, res); } catch (ServletException e) { LOG.error("ServletException including " + finalLocation, e); throw e; } catch (IOException e) { LOG.error("IOException while including result '" + finalLocation + "'", e); throw e; } }
private boolean authenticateWithSeraphAuthenticator(String userName, String password) throws AuthenticatorException { SecurityConfig securityConfig = SeraphUtils.getConfig(ServletActionContext.getRequest()); if (null != securityConfig) { Authenticator authenticator = securityConfig.getAuthenticator(); boolean authenticated = authenticator.login( ServletActionContext.getRequest(), ServletActionContext.getResponse(), userName, password ); log.debug(new StringBuilder("Authenticating as ") .append(userName) .append(" with md5hex password ").append(DigestUtils.md5Hex(StringUtils.defaultString(password))) .append(" by ").append(authenticator.getClass().getName()) .append(" results in ").append(authenticated).toString()); return authenticated; } log.error("Unable to get an Authenticator from Seraph."); return false; }
ServletActionContext.getResponse().setContentType(attrContentType.toString()); } else { String contentType = getContentType(); ServletActionContext.getResponse().setContentType(contentType);
} else { HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); RequestDispatcher dispatcher = request.getRequestDispatcher(finalLocation);
/** * Sets the optional HTTP response status code and also re-sets HTTP headers after they've * been optionally evaluated against the ValueStack. * * @param invocation an encapsulation of the action execution state. * @throws Exception if an error occurs when re-setting the headers. */ public void execute(ActionInvocation invocation) throws Exception { HttpServletResponse response = ServletActionContext.getResponse(); if (status != -1) { response.setStatus(status); } if (headers != null) { OgnlValueStack stack = ActionContext.getContext().getValueStack(); for (Iterator iterator = headers.entrySet().iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); String value = (String) entry.getValue(); String finalValue = parse ? TextParseUtil.translateVariables(value, stack) : value; response.addHeader((String) entry.getKey(), finalValue); } } } }
HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/html; charset=UTF-8"); response.setHeader("Cache-Control","no-cache");
/** * Executes the result. Writes the given chart as a PNG to the servlet output stream. * * @param invocation an encapsulation of the action execution state. * @throws Exception if an error occurs when creating or writing the chart to the servlet output stream. */ public void execute(ActionInvocation invocation) throws Exception { JFreeChart chart = null; if (chartSet) { chart = this.chart; } else { chart = (JFreeChart) invocation.getStack().findValue("chart"); } if (chart == null) { throw new NullPointerException("No chart found"); } HttpServletResponse response = ServletActionContext.getResponse(); OutputStream os = response.getOutputStream(); ChartUtilities.writeChartAsPNG(os, chart, width, height); os.flush(); } }
@Override public String execute() { ContentTreeLongRunningTask contentTreeLongRunningTask = pdfExportLongRunningTaskFactory.createNewContentTreeLongRunningTask(getI18n(), getSpace(), getAuthenticatedUser(), servletRequest.getContextPath()); taskId = longRunningTaskManager.startLongRunningTask(getAuthenticatedUser(), contentTreeLongRunningTask); ServletActionContext.getResponse().setContentType("text/xml"); return SUCCESS; } }
public void removeRememberMeCookie() { CookieSettings settings = securitySystem.getPolicy().getRememberMeCookieSettings(); removeCookie( ServletActionContext.getResponse(), REMEMBER_ME_KEY, settings.getDomain(), settings.getPath() ); }
@Override public String execute() throws Exception { try { ActionConfig currentConfig = overrideManager.getCurrentActionConfig(); if ( currentConfig instanceof OverriddenActionConfig ) { OverriddenActionConfig overriddenAction = (OverriddenActionConfig) currentConfig; if ( LOG.isDebugEnabled() ) LOG.debug( "Action Request: " + actionRequest ); targetAction = getTargetAction( overriddenAction, actionRequest ); if ( targetAction != null ) return SUCCESS; } // if we get this far, we have issues throw new ConveyorException( "Unable to locate an action to redirect to" + ( actionRequest.getOverrideKey() != null ? " with a bypass of '" + actionRequest.getOverrideType() + actionRequest.getOverrideKey() + "'." : "." ) ); } catch ( ConveyorException e ) { LOG.debug( e.getMessage(), e ); ServletActionContext.getResponse().sendError( HttpServletResponse.SC_NOT_FOUND ); } LOG.debug( "Unable to locate an action to redirect to" + ( actionRequest.getOverrideKey() != null ? " with a bypass of '" + actionRequest.getOverrideKey() + "'." : "." ) ); return ERROR; }
public void removeSignonCookie() { CookieSettings settings = securitySystem.getPolicy().getSignonCookieSettings(); removeCookie( ServletActionContext.getResponse(), SIGNON_KEY, settings.getDomain(), settings.getPath() ); }
public void spool(OutputContext outputContext) throws IOException { if (outputContext.hasStream()) { try (OutputStream outputStream = outputContext.getOutputStream(); InputStream inputStream = getContent()) { outputContext.setContentLength(getContentLength()); outputContext.setContentType(getContentType()); outputContext.setModificationTime(getModificationTime()); //we set all the headers returned by getHeaders(), except content-type as it is already set above. This //is normally going to be an empty set, except for attachment resources, which would contain the same //set of headers as the attachment download from a normal confluence page. This prevents XSS using webdav for (Map.Entry<String, String> header : Maps.filterEntries(getHeaders(), NOT_CONTENT_TYPE_HEADERS).entrySet()) { ServletActionContext.getResponse().setHeader(header.getKey(), header.getValue()); } if (inputStream != null && outputStream != null) IOUtils.copy(inputStream, outputStream); } } else { outputContext.setContentLength(0); outputContext.setModificationTime(getModificationTime()); } }
public void setSignonCookie( String principal ) { try { CookieSettings settings = securitySystem.getPolicy().getSignonCookieSettings(); int timeout = settings.getCookieTimeout(); KeyManager keyManager = securitySystem.getKeyManager(); AuthenticationKey authkey = keyManager.createKey( principal, "Signon Session Key", timeout ); /* The path must remain as "/" in order for SSO to work on installations where the only * all of the servers are installed into the same web container but under different * web contexts. */ Cookie cookie = createCookie( SIGNON_KEY, authkey.getKey(), settings.getDomain(), settings.getPath() ); if ( timeout > 0 ) { cookie.setMaxAge( timeout ); } ServletActionContext.getResponse().addCookie( cookie ); } catch ( KeyManagerException e ) { getLogger().warn( "Unable to set single sign on cookie." ); } }
HttpServletResponse res = ServletActionContext.getResponse();
public void setRememberMeCookie( String principal ) { if ( !isRememberMeEnabled() ) { return; } try { CookieSettings settings = securitySystem.getPolicy().getRememberMeCookieSettings(); int timeout = settings.getCookieTimeout(); KeyManager keyManager = securitySystem.getKeyManager(); AuthenticationKey authkey = keyManager.createKey( principal, "Remember Me Key", timeout ); Cookie cookie = createCookie( REMEMBER_ME_KEY, authkey.getKey(), settings.getDomain(), settings.getPath() ); if ( timeout > 0 ) { cookie.setMaxAge( timeout ); } ServletActionContext.getResponse().addCookie( cookie ); } catch ( KeyManagerException e ) { getLogger().warn( "Unable to set remember me cookie." ); } }
/** * Build the instance of the ScopesHashModel, including JspTagLib support * <p/>Objects added to the model are <p/> * <ul> * <li>Application - servlet context attributes hash model * <li>JspTaglibs - jsp tag lib factory model * <li>Request - request attributes hash model * <li>Session - session attributes hash model * <li>req - the HttpServletRequst object for direct access * <li>res - the HttpServletResponse object for direct access * <li>stack - the OgnLValueStack instance for direct access * <li>ognl - the instance of the OgnlTool * <li>action - the action itself * <li>exception - optional : the JSP or Servlet exception as per the * servlet spec (for JSP Exception pages) * <li>webwork - instance of the WebWorkUtil class * </ul> */ protected TemplateModel createModel() throws TemplateModelException { ServletContext servletContext = ServletActionContext .getServletContext(); HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); OgnlValueStack stack = ServletActionContext.getContext() .getValueStack(); return FreemarkerManager.getInstance().buildTemplateModel(stack, invocation.getAction(), servletContext, request, response, wrapper); }
private AuthenticationKey findAuthKey( String cookieName, String providedKey, String domain, String path ) { try { AuthenticationKey authkey = securitySystem.getKeyManager().findKey( providedKey ); getLogger().debug( "Found AuthKey: " + authkey ); return authkey; } catch ( KeyNotFoundException e ) { getLogger().info( "Invalid AuthenticationKey " + providedKey + " submitted. Invalidating cookie." ); // Invalid Cookie. Remove it. removeCookie( ServletActionContext.getResponse(), cookieName, domain, path ); } catch ( KeyManagerException e ) { getLogger().error( "KeyManagerException: " + e.getMessage(), e ); } return null; }