Search in sources :

Example 1 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class ActionServlet method initModuleActions.

/**
     * <p>Initialize the action configs for the specified module.</p>
     *
     * @param config ModuleConfig information for this module
     * @throws ServletException if initialization cannot be performed
     * @since Struts 1.3
     */
protected void initModuleActions(ModuleConfig config) throws ServletException {
    if (log.isDebugEnabled()) {
        log.debug("Initializing module path '" + config.getPrefix() + "' action configs");
    }
    // Process ActionConfig extensions.
    ActionConfig[] actionConfigs = config.findActionConfigs();
    for (int i = 0; i < actionConfigs.length; i++) {
        ActionConfig actionConfig = actionConfigs[i];
        processActionConfigExtension(actionConfig, config);
    }
    for (int i = 0; i < actionConfigs.length; i++) {
        ActionConfig actionConfig = actionConfigs[i];
        // Verify that required fields are all present for the forward
        // configs
        ForwardConfig[] forwards = actionConfig.findForwardConfigs();
        for (int j = 0; j < forwards.length; j++) {
            ForwardConfig forward = forwards[j];
            if (forward.getPath() == null) {
                handleValueRequiredException("path", forward.getName(), "action forward");
            }
        }
        // ... and the exception configs
        ExceptionConfig[] exceptions = actionConfig.findExceptionConfigs();
        for (int j = 0; j < exceptions.length; j++) {
            ExceptionConfig exception = exceptions[j];
            if (exception.getKey() == null) {
                handleValueRequiredException("key", exception.getType(), "action exception config");
            }
        }
    }
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ExceptionConfig(org.apache.struts.config.ExceptionConfig) ForwardConfig(org.apache.struts.config.ForwardConfig)

Example 2 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class ActionServlet method processActionConfigClass.

/**
     * <p>Checks if the current actionConfig is using the correct class based
     * on the class of its ancestor ActionConfig.</p>
     *
     * @param actionConfig The action config to check.
     * @param moduleConfig The config for the current module.
     * @return The config object using the correct class as determined by the
     *         config's ancestor and its own overridden value.
     * @throws ServletException if an instance of the action config class
     *                          cannot be created.
     */
protected ActionConfig processActionConfigClass(ActionConfig actionConfig, ModuleConfig moduleConfig) throws ServletException {
    String ancestor = actionConfig.getExtends();
    if (ancestor == null) {
        // Nothing to do, then
        return actionConfig;
    }
    // Make sure that this config is of the right class
    ActionConfig baseConfig = moduleConfig.findActionConfig(ancestor);
    if (baseConfig == null) {
        throw new UnavailableException("Unable to find " + "action config for '" + ancestor + "' to extend.");
    }
    // Was our actionConfig's class overridden already?
    if (actionConfig.getClass().equals(ActionMapping.class)) {
        // Ensure that our config is using the correct class
        if (!baseConfig.getClass().equals(actionConfig.getClass())) {
            // Replace the config with an instance of the correct class
            ActionConfig newActionConfig = null;
            String baseConfigClassName = baseConfig.getClass().getName();
            try {
                newActionConfig = (ActionConfig) RequestUtils.applicationInstance(baseConfigClassName);
                // copy the values
                BeanUtils.copyProperties(newActionConfig, actionConfig);
                // copy the forward and exception configs, too
                ForwardConfig[] forwards = actionConfig.findForwardConfigs();
                for (int i = 0; i < forwards.length; i++) {
                    newActionConfig.addForwardConfig(forwards[i]);
                }
                ExceptionConfig[] exceptions = actionConfig.findExceptionConfigs();
                for (int i = 0; i < exceptions.length; i++) {
                    newActionConfig.addExceptionConfig(exceptions[i]);
                }
            } catch (Exception e) {
                handleCreationException(baseConfigClassName, e);
            }
            // replace actionConfig with newActionConfig
            moduleConfig.removeActionConfig(actionConfig);
            moduleConfig.addActionConfig(newActionConfig);
            actionConfig = newActionConfig;
        }
    }
    return actionConfig;
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ExceptionConfig(org.apache.struts.config.ExceptionConfig) UnavailableException(javax.servlet.UnavailableException) ForwardConfig(org.apache.struts.config.ForwardConfig) ServletException(javax.servlet.ServletException) MissingResourceException(java.util.MissingResourceException) SAXException(org.xml.sax.SAXException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException)

Example 3 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class AbstractAuthorizeAction method execute.

// ---------------------------------------------------------- Public Methods
/**
     * <p>Determine whether the requested action is authorized for the current
     * user.  If not, abort chain processing and perferably, return an error
     * message of some kind.</p>
     *
     * @param actionCtx The <code>Context</code> for the current request
     * @return <code>false</code> if the user is authorized for the selected
     *         action, else <code>true</code> to abort processing.
     * @throws UnauthorizedActionException if authorization fails 
     * or if an error is encountered in the course of performing the authorization.
     */
public boolean execute(ActionContext actionCtx) throws Exception {
    // Retrieve ActionConfig
    ActionConfig actionConfig = actionCtx.getActionConfig();
    // Is this action protected by role requirements?
    if (!isAuthorizationRequired(actionConfig)) {
        return (false);
    }
    boolean throwEx;
    try {
        throwEx = !(isAuthorized(actionCtx, actionConfig.getRoleNames(), actionConfig));
    } catch (UnauthorizedActionException ex) {
        throw ex;
    } catch (Exception ex) {
        throwEx = true;
        LOG.error("Unable to complete authorization process", ex);
    }
    if (throwEx) {
        // The current user is not authorized for this action
        throw new UnauthorizedActionException(getErrorMessage(actionCtx, actionConfig));
    } else {
        return (false);
    }
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig)

Example 4 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class AbstractCreateAction method execute.

// ---------------------------------------------------------- Public Methods
/**
     * <p>Create (if necessary) and cache an <code>Action</code> for this
     * request.</p>
     *
     * @param actionCtx The <code>Context</code> for the current request
     * @return <code>false</code> so that processing continues
     * @throws Exception if there are any problems instantiating the Action
     *                   class.
     */
public boolean execute(ActionContext actionCtx) throws Exception {
    // Skip processing if the current request is not valid
    Boolean valid = actionCtx.getFormValid();
    if ((valid == null) || !valid.booleanValue()) {
        LOG.trace("Invalid form; not going to execute.");
        return (false);
    }
    // Check to see if an action has already been created
    if (actionCtx.getAction() != null) {
        LOG.trace("already have an action [" + actionCtx.getAction() + "]");
        return (false);
    }
    // Look up the class name for the desired Action
    ActionConfig actionConfig = actionCtx.getActionConfig();
    String type = actionConfig.getType();
    if (type == null) {
        String command = actionConfig.getCommand();
        if ((command == null) && (actionConfig.getForward() == null) && (actionConfig.getInclude() == null)) {
            LOG.error("no type or command for " + actionConfig.getPath());
        } else {
            LOG.trace("no type for " + actionConfig.getPath());
        }
        return (false);
    }
    // Create (if necessary) and cache an Action instance
    Action action = getAction(actionCtx, type, actionConfig);
    if (LOG.isTraceEnabled()) {
        LOG.trace("setting action to " + action);
    }
    actionCtx.setAction(action);
    return (false);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) Action(org.apache.struts.action.Action)

Example 5 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class AbstractExecuteAction method execute.

// ---------------------------------------------------------- Public Methods
/**
     * <p>Invoke the appropriate <code>Action</code> for this request, and
     * cache the returned <code>ActionForward</code>.</p>
     *
     * @param actionCtx The <code>Context</code> for the current request
     * @return <code>false</code> so that processing continues
     * @throws Exception if thrown by the Action class
     */
public boolean execute(ActionContext actionCtx) throws Exception {
    // Skip processing if the current request is not valid
    Boolean valid = actionCtx.getFormValid();
    if ((valid == null) || !valid.booleanValue()) {
        return (false);
    }
    // Acquire the resources we will need to send to the Action
    Action action = actionCtx.getAction();
    if (action == null) {
        return (false);
    }
    ActionConfig actionConfig = actionCtx.getActionConfig();
    ActionForm actionForm = actionCtx.getActionForm();
    // Execute the Action for this request, caching returned ActionForward
    ForwardConfig forwardConfig = execute(actionCtx, action, actionConfig, actionForm);
    actionCtx.setForwardConfig(forwardConfig);
    return (false);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) Action(org.apache.struts.action.Action) ActionForm(org.apache.struts.action.ActionForm) ForwardConfig(org.apache.struts.config.ForwardConfig)

Aggregations

ActionConfig (org.apache.struts.config.ActionConfig)76 ForwardConfig (org.apache.struts.config.ForwardConfig)14 UnavailableException (javax.servlet.UnavailableException)8 ActionForm (org.apache.struts.action.ActionForm)8 ExceptionConfig (org.apache.struts.config.ExceptionConfig)8 FormBeanConfig (org.apache.struts.config.FormBeanConfig)8 ModuleConfig (org.apache.struts.config.ModuleConfig)8 ServletException (javax.servlet.ServletException)6 MalformedURLException (java.net.MalformedURLException)4 Map (java.util.Map)4 Action (org.apache.struts.action.Action)4 UnauthorizedActionException (org.apache.struts.chain.commands.UnauthorizedActionException)4 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 MissingResourceException (java.util.MissingResourceException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 JspException (javax.servlet.jsp.JspException)2 ActionErrors (org.apache.struts.action.ActionErrors)2 MockActionContext (org.apache.struts.chain.contexts.MockActionContext)2 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)2