Search in sources :

Example 61 with ActionConfig

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

the class TestAuthorizeAction method testAuthorizeOneRole.

public void testAuthorizeOneRole() throws Exception {
    ActionConfig config = new ActionConfig();
    config.setPath("/testAuthorizeOneRole");
    config.setRoles("administrator");
    this.saContext.setActionConfig(config);
    boolean result = command.execute(saContext);
    assertFalse(result);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig)

Example 62 with ActionConfig

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

the class TestAuthorizeAction method testNotAuthorizedOneOfManyRoles.

public void testNotAuthorizedOneOfManyRoles() throws Exception {
    ActionConfig config = new ActionConfig();
    config.setPath("/testNotAuthorizedOneOfManyRoles");
    config.setRoles("roustabout,memory");
    this.saContext.setActionConfig(config);
    try {
        boolean result = command.execute(saContext);
    } catch (UnauthorizedActionException ex) {
    }
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) UnauthorizedActionException(org.apache.struts.chain.commands.UnauthorizedActionException)

Example 63 with ActionConfig

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

the class AbstractSelectAction method execute.

// ---------------------------------------------------------- Public Methods
/**
 * <p>Cache the <code>ActionConfig</code> instance for the action to be
 * used for processing this request.</p>
 *
 * @param actionCtx The <code>Context</code> for the current request
 * @return <code>false</code> so that processing continues
 * @throws InvalidPathException if no valid action can be identified for
 *                              this request
 * @throws Exception            if thrown by the Action class
 */
public boolean execute(ActionContext actionCtx) throws Exception {
    // Identify the matching path for this request
    String path = getPath(actionCtx);
    // Cache the corresponding ActonConfig instance
    ModuleConfig moduleConfig = actionCtx.getModuleConfig();
    ActionConfig actionConfig = moduleConfig.findActionConfig(path);
    if (actionConfig == null) {
        // NOTE Shouldn't this be the responsibility of ModuleConfig?
        // Locate the mapping for unknown paths (if any)
        ActionConfig[] configs = moduleConfig.findActionConfigs();
        for (int i = 0; i < configs.length; i++) {
            if (configs[i].getUnknown()) {
                actionConfig = configs[i];
                break;
            }
        }
    }
    if (actionConfig == null) {
        throw new InvalidPathException("No action config found for the specified url.", path);
    }
    actionCtx.setActionConfig(actionConfig);
    return (false);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 64 with ActionConfig

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

the class AbstractSelectInput method execute.

// ---------------------------------------------------------- Public Methods
/**
 * <p>Select and cache a <code>ForwardConfig</code> for the input page for
 * the current request.</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 valid
    Boolean valid = actionCtx.getFormValid();
    if ((valid != null) && valid.booleanValue()) {
        return (false);
    }
    // Acquire configuration objects that we need
    ActionConfig actionConfig = actionCtx.getActionConfig();
    ModuleConfig moduleConfig = actionConfig.getModuleConfig();
    // Cache an ForwardConfig back to our input page
    ForwardConfig forwardConfig;
    String input = actionConfig.getInput();
    if (moduleConfig.getControllerConfig().getInputForward()) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Finding ForwardConfig for '" + input + "'");
        }
        forwardConfig = actionConfig.findForwardConfig(input);
        if (forwardConfig == null) {
            forwardConfig = moduleConfig.findForwardConfig(input);
        }
    } else {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Delegating to forward() for '" + input + "'");
        }
        forwardConfig = forward(actionCtx, moduleConfig, input);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Forwarding back to " + forwardConfig);
    }
    actionCtx.setForwardConfig(forwardConfig);
    return (false);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ModuleConfig(org.apache.struts.config.ModuleConfig) ForwardConfig(org.apache.struts.config.ForwardConfig)

Example 65 with ActionConfig

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

the class AbstractValidateActionForm method execute.

// ---------------------------------------------------------- Public Methods
/**
 * <p>Validate the properties of the form bean for this request.  If there
 * are any validation errors, execute the child commands in our chain;
 * otherwise, proceed normally.</p>
 *
 * @param actionCtx The <code>Context</code> for the current request
 * @return <code>false</code> so that processing continues, if there are
 *         no validation errors; otherwise <code>true</code>
 * @throws Exception if thrown by the Action class
 */
public boolean execute(ActionContext actionCtx) throws Exception {
    // Set form valid until found otherwise
    actionCtx.setFormValid(Boolean.TRUE);
    // Is there a form bean for this request?
    ActionForm actionForm = actionCtx.getActionForm();
    if (actionForm == null) {
        return false;
    }
    // Is validation disabled on this request?
    ActionConfig actionConfig = actionCtx.getActionConfig();
    if (!actionConfig.getValidate()) {
        return false;
    }
    // Was this request cancelled?
    if (isCancelled(actionCtx, actionConfig)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(" Cancelled transaction, skipping validation");
        }
        return false;
    }
    // Call the validate() method of this form bean
    ActionErrors errors = validate(actionCtx, actionConfig, actionForm);
    // If there were no errors, proceed normally
    if ((errors == null) || (errors.isEmpty())) {
        return false;
    }
    // Flag the validation failure and proceed
    /* NOTE: Is there any concern that there might have already
         * been errors, or that other errors might be coming?
         */
    actionCtx.saveErrors(errors);
    actionCtx.setFormValid(Boolean.FALSE);
    return false;
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ActionForm(org.apache.struts.action.ActionForm) ActionErrors(org.apache.struts.action.ActionErrors)

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