Search in sources :

Example 31 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonar-java by SonarSource.

the class SelectInclude method execute.

// ---------------------------------------------------------- Public Methods
/**
 * <p>Select and cache the include uri for this <code>ActionConfig</code>
 * if specified.</p>
 *
 * @param actionCtx The <code>Context</code> for the current request
 * @return <code>false</code> so that processing continues
 * @throws Exception on any error
 */
public boolean execute(ActionContext actionCtx) throws Exception {
    // Acquire configuration objects that we need
    ActionConfig actionConfig = actionCtx.getActionConfig();
    // Cache an include uri if found
    String include = actionConfig.getInclude();
    if (include != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Including " + include);
        }
        actionCtx.setInclude(include);
    }
    return (false);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig)

Example 32 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonar-java by SonarSource.

the class CopyFormToContext method findOrCreateForm.

/**
 * <p>Based on the properties of this command and the given
 * <code>ActionContext</code>, find or create an ActionForm instance for
 * preparation.</p>
 *
 * @param context ActionContextBase class that we are processing
 * @return ActionForm instance
 * @throws IllegalArgumentException On ActionConfig not found
 * @throws IllegalStateException    On undefined scope and formbean
 * @throws IllegalAccessException   On failed instantiation
 * @throws InstantiationException   If ActionContext is not subsclass of
 *                                  ActionContextBase
 */
protected ActionForm findOrCreateForm(ActionContext context) throws IllegalAccessException, InstantiationException {
    String effectiveFormName;
    String effectiveScope;
    if (!(isEmpty(this.getActionPath()))) {
        ActionConfig actionConfig = context.getModuleConfig().findActionConfig(this.getActionPath());
        if (actionConfig == null) {
            throw new IllegalArgumentException("No ActionConfig found for path " + this.getActionPath());
        }
        effectiveFormName = actionConfig.getName();
        effectiveScope = actionConfig.getScope();
    } else {
        effectiveFormName = this.getFormName();
        effectiveScope = this.getScope();
    }
    if (isEmpty(effectiveScope) || isEmpty(effectiveFormName)) {
        throw new IllegalStateException("Both scope [" + effectiveScope + "] and formName [" + effectiveFormName + "] must be defined.");
    }
    return findOrCreateForm(context, effectiveFormName, effectiveScope);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig)

Example 33 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonar-java by SonarSource.

the class RequestUtils method actionIdURL.

/**
 * <p>Returns the true path of the destination action if the specified forward
 * is an action-aliased URL. This method version forms the URL based on
 * the specified module.
 *
 * @param originalPath the action-aliased path
 * @param moduleConfig the module config for this request
 * @param servlet the servlet handling the current request
 * @return the context-relative URL of the action if the path has an action identifier; otherwise <code>null</code>.
 * @since Struts 1.3.6
 */
public static String actionIdURL(String originalPath, ModuleConfig moduleConfig, ActionServlet servlet) {
    if (originalPath.startsWith("http") || originalPath.startsWith("/")) {
        return null;
    }
    // Split the forward path into the resource and query string;
    // it is possible a forward (or redirect) has added parameters.
    String actionId = null;
    String qs = null;
    int qpos = originalPath.indexOf("?");
    if (qpos == -1) {
        actionId = originalPath;
    } else {
        actionId = originalPath.substring(0, qpos);
        qs = originalPath.substring(qpos);
    }
    // Find the action of the given actionId
    ActionConfig actionConfig = moduleConfig.findActionConfigId(actionId);
    if (actionConfig == null) {
        if (log.isDebugEnabled()) {
            log.debug("No actionId found for " + actionId);
        }
        return null;
    }
    String path = actionConfig.getPath();
    String mapping = RequestUtils.getServletMapping(servlet);
    StringBuffer actionIdPath = new StringBuffer();
    // Form the path based on the servlet mapping pattern
    if (mapping.startsWith("*")) {
        actionIdPath.append(path);
        actionIdPath.append(mapping.substring(1));
    } else if (mapping.startsWith("/")) {
        // implied ends with a *
        mapping = mapping.substring(0, mapping.length() - 1);
        if (mapping.endsWith("/") && path.startsWith("/")) {
            actionIdPath.append(mapping);
            actionIdPath.append(path.substring(1));
        } else {
            actionIdPath.append(mapping);
            actionIdPath.append(path);
        }
    } else {
        log.warn("Unknown servlet mapping pattern");
        actionIdPath.append(path);
    }
    // Lastly add any query parameters (the ? is part of the query string)
    if (qs != null) {
        actionIdPath.append(qs);
    }
    // Return the path
    if (log.isDebugEnabled()) {
        log.debug(originalPath + " unaliased to " + actionIdPath.toString());
    }
    return actionIdPath.toString();
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig)

Example 34 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonar-java 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 35 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonar-java 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)

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