Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p><strong>ModelDriven interceptor is blind</strong></p> </blockquote> <p>Yes Model Interface could be a source of security issue, if you do not handle incoming parameters you will face security holes. </p> <p>You have to use parameter interceptor.</p> <p>In the struts.xml change your params interceptor as:</p> <pre><code>&lt;interceptor-ref name="params"&gt; &lt;param name="excludeParams"&gt;\w+((\.\w+)|(\[\d+\])|(\(\d+\))|(\['\w+'\])|(\('\w+'\)))*&lt;/param&gt; &lt;/interceptor-ref&gt; </code></pre> <p>Then in your action implement <code>ParameterNameAware</code> and write <code>acceptableParameterName</code>.</p> <pre><code>public class sample implements ParameterNameAware(){ public boolean acceptableParameterName(String parameterName) { if (("username".equals(parameterName) || "firstname".equals(parameterName) || "lastname".equals(parameterName)) return true; else return false; } } </code></pre> <p>The above is important, if your <strong>User</strong> pojo has lots of other properties and <strong>only</strong> some of them should be get from user.</p> <p>If you use lots of ModelDriven actions you can make it general.</p> <p>Create an base action which extends the <code>ParameterNameAware</code> . Then try to develop a general approach to have a list of your action and valid parameters :</p> <p>We used spring to read the list of actions and their acceptable parameters. In the spring xml we added:</p> <pre><code>&lt;util:properties id="actionsValidParameters" location="classpath:/configs/actions-valid-parameters.properties" /&gt; </code></pre> <p>The <code>actions-valid-parameters.properties</code> is as :</p> <pre><code>save-user=username,description,firstname,lastname save-address=zipcode,city,detail,detail.addLine1,detail.addLine2,detail.no </code></pre> <p>Hint, If Address Object has an Detail object and you want to fill some properties in the Detail object, make sure you include the 'detail' in above list.</p> <p>The action is as</p> <pre><code>public class BaseActionSupport extends ActionSupport implements ParameterNameAware { @Resource(name = "actionsValidParameters") public Properties actionsValidParameters; @Override public boolean acceptableParameterName(String parameterName) { String actionName = ActionContext.getContext().getName(); String validParams = (String) actionsValidParameters.get(actionName); //If the action is not defined in the list, it is assumed that the action can accept all parameters. You can return false so if the action is not in the list no parameter is accepeted. It is up to you! if(StringUtils.isBlank(validParams)) return true; // Search all the list of parameters. //You can split the validParams to array and search array. Pattern pattern = Pattern.compile("(?&lt;=^|,)" + parameterName + "(?=,|$)"); Matcher matcher = pattern.matcher(validParams); boolean accepeted = matcher.find(); LOG.debug( "The {} parameter is {} in action {}, Position (excluding the action name) {} , {} , mathced {} ", parameterName, accepeted, actionName, matcher.start(), matcher.end(), matcher.group()); return accepeted; } } </code></pre> <p>Now wrtie your actions as </p> <pre><code> public class UserAction extends BaseActionSupport implements ModelDriven&lt;User&gt;{ } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload