Search in sources :

Example 6 with ServletActionContext

use of org.apache.struts.chain.contexts.ServletActionContext in project sonarqube by SonarSource.

the class SetOriginalURI method setOriginalURI.

// ------------------------------------------------------- Protected Methods
protected void setOriginalURI(ActionContext context) {
    ServletActionContext swcontext = (ServletActionContext) context;
    HttpServletRequest request = swcontext.getRequest();
    request.setAttribute(Globals.ORIGINAL_URI_KEY, request.getServletPath());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext)

Example 7 with ServletActionContext

use of org.apache.struts.chain.contexts.ServletActionContext in project sonarqube by SonarSource.

the class ValidateActionForm method validate.

// ------------------------------------------------------- Protected Methods
/**
     * <p>Call the <code>validate()</code> method of the specified form bean,
     * and return the resulting <code>ActionErrors</code> object.</p>
     *
     * @param context    The context for this request
     * @param actionForm The form bean for this request
     */
protected ActionErrors validate(ActionContext context, ActionConfig actionConfig, ActionForm actionForm) {
    ServletActionContext saContext = (ServletActionContext) context;
    ActionErrors errors = (actionForm.validate((ActionMapping) actionConfig, saContext.getRequest()));
    // Special handling for multipart request
    if ((errors != null) && !errors.isEmpty()) {
        if (actionForm.getMultipartRequestHandler() != null) {
            if (log.isTraceEnabled()) {
                log.trace("  Rolling back multipart request");
            }
            actionForm.getMultipartRequestHandler().rollback();
        }
    }
    return errors;
}
Also used : ActionMapping(org.apache.struts.action.ActionMapping) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) ActionErrors(org.apache.struts.action.ActionErrors)

Example 8 with ServletActionContext

use of org.apache.struts.chain.contexts.ServletActionContext in project sonarqube by SonarSource.

the class AuthorizeAction method isAuthorized.

// ------------------------------------------------------- Protected Methods
protected boolean isAuthorized(ActionContext context, String[] roles, ActionConfig mapping) throws Exception {
    // Identify the HTTP request object
    ServletActionContext servletActionContext = (ServletActionContext) context;
    HttpServletRequest request = servletActionContext.getRequest();
    // Check the current user against the list of required roles
    for (int i = 0; i < roles.length; i++) {
        if (request.isUserInRole(roles[i])) {
            return (true);
        }
    }
    // Default to unauthorized
    return (false);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext)

Example 9 with ServletActionContext

use of org.apache.struts.chain.contexts.ServletActionContext in project sonarqube by SonarSource.

the class AuthorizeAction method getErrorMessage.

protected String getErrorMessage(ActionContext context, ActionConfig actionConfig) {
    ServletActionContext servletActionContext = (ServletActionContext) context;
    // Retrieve internal message resources
    ActionServlet servlet = servletActionContext.getActionServlet();
    MessageResources resources = servlet.getInternal();
    return resources.getMessage("notAuthorized", actionConfig.getPath());
}
Also used : MessageResources(org.apache.struts.util.MessageResources) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) ActionServlet(org.apache.struts.action.ActionServlet)

Example 10 with ServletActionContext

use of org.apache.struts.chain.contexts.ServletActionContext in project sonarqube by SonarSource.

the class CreateAction method getAction.

/* :TODO The Action class' dependency on having its "servlet" property set
     * requires this API-dependent subclass of AbstractCreateAction.
     */
protected synchronized Action getAction(ActionContext context, String type, ActionConfig actionConfig) throws Exception {
    ModuleConfig moduleConfig = actionConfig.getModuleConfig();
    String actionsKey = Constants.ACTIONS_KEY + moduleConfig.getPrefix();
    Map actions = (Map) context.getApplicationScope().get(actionsKey);
    if (actions == null) {
        actions = new HashMap();
        context.getApplicationScope().put(actionsKey, actions);
    }
    Action action = null;
    synchronized (actions) {
        action = (Action) actions.get(type);
        if (action == null) {
            action = createAction(context, type);
            actions.put(type, action);
        }
    }
    if (action.getServlet() == null) {
        ServletActionContext saContext = (ServletActionContext) context;
        ActionServlet actionServlet = saContext.getActionServlet();
        action.setServlet(actionServlet);
    }
    return (action);
}
Also used : Action(org.apache.struts.action.Action) HashMap(java.util.HashMap) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) ModuleConfig(org.apache.struts.config.ModuleConfig) Map(java.util.Map) HashMap(java.util.HashMap) ActionServlet(org.apache.struts.action.ActionServlet)

Aggregations

ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)22 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 ActionServlet (org.apache.struts.action.ActionServlet)4 MockActionServlet (org.apache.struts.mock.MockActionServlet)3 MockHttpServletRequest (org.apache.struts.mock.MockHttpServletRequest)3 MockHttpServletResponse (org.apache.struts.mock.MockHttpServletResponse)3 MockServletConfig (org.apache.struts.mock.MockServletConfig)3 MockServletContext (org.apache.struts.mock.MockServletContext)3 Map (java.util.Map)2 ActionForm (org.apache.struts.action.ActionForm)2 ActionMapping (org.apache.struts.action.ActionMapping)2 ModuleConfig (org.apache.struts.config.ModuleConfig)2 MockPrincipal (org.apache.struts.mock.MockPrincipal)2 MessageResources (org.apache.struts.util.MessageResources)2 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 ServletContext (javax.servlet.ServletContext)1 HttpSession (javax.servlet.http.HttpSession)1