Many of the configuration options available using <init-param> in the
web.xml were deprecated in Struts 1.1 and removed in Struts 1.2, including
the "mapping" one you're trying to use. The upgrade notes on the wiki have a
full list:

http://wiki.apache.org/struts/StrutsUpgradeNotes11to124

However having said that, you are setting the type on <action-mappings>
element in the struts-config - so the fact that the above is ignored is
irrelevant. If you didn't want to use the "type" on the <action-mappings>
element, but install a default implementation on a strust-wide replacement,
then you the replacement mechanism for a "mapping" <init-param> would be to
use a custom ModuleConfigFactory, as follows...

 <init-param>
   <param-name>configFactory</param-name>
   <param-value>myPackage.MyConfigFactory</param-value>
 </init-param>

Your custom factory might look something like this...

public class MyConfigFactory extends DefaultModuleConfigFactory {
   public ModuleConfig createModuleConfig(String prefix) {
        ModuleConfig config = super.createModuleConfig(prefix);

config.setActionMappingClass("au.com.common.struts.action.mapping.SecureActi
onMapping");
        return config;
    }
}

Having said that, none of the above addresses why what you're expecting to
happen isn't being done. You say "the property's set method is not called on
execution of an action" - but thats not what happens. Struts should be
calling your setSecurityRoles() method when Struts starts up and parses the
struts-config.xml - thats when the ActionMapping gets instantiated and
intialized, not when the Action's execute method is called on receving a
request. Are you sure you're not getting your message displayed when Tomcat
starts up?

Niall

----- Original Message ----- 
From: "Stephen Peck" <[EMAIL PROTECTED]>
Sent: Sunday, February 13, 2005 11:18 PM


> Hi,
>
> I am currently trying to set up a custom security model using struts
> which involves extending ActionMapping
> with a class called SecureActionMapping using Tomcat 5.0 and Struts 1.2.
>
> My problem is that after initialisation of the actions, which definitely
> creates and parses the extended action mapping for each action because
> the bean property is checked for exuistence in the extending class, the
> property's set method is not called on execution of an action.
> Therefore rendering the vector that is initialised with the value
> parameter as empty instead of placing the value in it.
>
> After searching for some alternate solutions on the web at JavaWorld and
> the struts.apache.org FAQ I was unable to find a solution to this.  The
> following is how I have set this up;
>
> in my web.xml file I tried adding a initialisation parameter for the
> ActionServlet as mentioned at JavaWorld
>
> <init-param>
> <param-name>mapping</param-name>
>
<param-value>au.com.common.struts.action.mapping.SecureActionMapping</param-
value>
> </init-param>
>
> and in the struts-config.xml
>
> <action-mappings
>
type="au.com.plantechnology.common.struts.action.mapping.SecureActionMapping
">
>     <action path="/SecureAction" scope="request"
> type="au.com.plantechnology.finance.struts.action.SecureAction">
>        <set-property property="securityRoles"
> value="admin,manager,finance"/>
>        <forward name="success" path="/test_security.jsp"/>
>        <forward name="failure" path="/login.jsp"/>
>   </action>
> </action-mappings>
>
> Where my property is securityRoles.  The java class is as follows;
>
> package au.com.common.struts.action.mapping;
>
> import java.util.StringTokenizer;
> import java.util.Vector;
>
> import org.apache.struts.action.ActionMapping;
>
> public class SecureActionMapping extends ActionMapping
> {
>     private Vector myRoles = new Vector();
>
>     public SecureActionMapping() {}
>
>     public void setSecurityRoles(String aRolesString)
>     {
>         System.out.println("WTF ?");
>
>         StringTokenizer st = new StringTokenizer(aRolesString, ",",
false);
>
>         while (st.hasMoreTokens())
>         {
>             myRoles.add(st.nextToken().trim());
>         }
>     }
>
>     public Vector getSecurityRoles()
>     {
>         return myRoles;
>     }
> }
>
> As the the System.out.println in my set method does not display I assume
> that this method is not being correctly called by the ActionServlet when
> creating the ActionMapping.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to