Niall Pemberton wrote:
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
<param-value>au.com.common.struts.action.mapping.SecureActionMapping</param-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>
value>
type="au.com.plantechnology.common.struts.action.mapping.SecureActionMapping</init-param>
and in the struts-config.xml
<action-mappings
">
false);<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, ",",
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]
Thanks for the reply Niall,
Yes I am sure that the message is not being displayed in the output of Tomcat's startup ;
- Initializing Coyote HTTP/1.1 on http-8080
- Initialization processed in 2406 ms
- Starting service Catalina
- Starting Servlet Engine: Apache Tomcat/5.0.24
- XML validation disabled
- Create Host deployer for direct deployment ( non-jmx )
- Processing Context configuration file URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\conf\Catalina\localhost\admin.xml
- Initializing, config='org.apache.struts.util.LocalStrings', returnNull=true
- Initializing, config='org.apache.struts.action.ActionResources', returnNull=true
- Initializing, config='org.apache.webapp.admin.ApplicationResources', returnNull=true
- Processing Context configuration file URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\conf\Catalina\localhost\finance_revamp.xml
- Tiles definition factory loaded for module ''.
- Loading validation rules file from '/WEB-INF/validator-rules.xml'
- Loading validation rules file from '/WEB-INF/validation.xml'
- Processing Context configuration file URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\conf\Catalina\localhost\ROOT.xml
- Processing Context configuration file URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\conf\Catalina\localhost\tomcat-docs.xml
- Starting Coyote HTTP/1.1 on http-8080
- JK2: ajp13 listening on /0.0.0.0:8009
- Jk running ID=0 time=0/235 config=C:\Program Files\Apache Software Foundation\Tomcat 5.0\conf\jk2.properties
- Server startup in 13110 ms
found mapping type au.com.plantechnology.common.struts.action.mapping.SecureActionMapping
The last line is displayed on a call to SecureAction which is expecting a SecureActionMapping.
It just doesn't seem to make sense. I have continued searching the web and have still found nada. The configuration seems to be correct, I have changed the name of the property, added new ones and still nothing. It is definitely creating the correct mapping type but just not initialising it.
Steve.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]