You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by "Gallagher, Jim (UK Europe Middle East & Group Functions, Technology Services)" <Ji...@rbs.co.uk> on 2010/03/09 11:27:04 UTC

Issue with retrieving Tiles definitions in code

Hi,

I'm currently writing a web application using Java 5, Websphere 6.1, JSF
and Tiles 2.0.6 (versions mandated by organisation).

I'm converting a multi-brand menu system from Struts-Tiles, and having
an issue when processing definitions. What I'm trying to achieve is:

Define a DefinitionManager in the ViewPreparer for a given definition
Read another definition (stored in menus.xml, referenced in the web.xml)
into a Definition object, to process the rules contained therein

My problem is that I cannot see how to get a link to the correct
DefinitionsFactory that contains the default definitions read in at
application startup. I'd even settle for re-reading them, but cannot
find a way how to do that either without getting a reference to the
factory.

Could anyone provide any assistance or advice? All constructive advice
gratefully received.


                                 Regards,

                                         Jim

Jim Gallagher,
Internet mail: 	jim.gallagher@rbs.co.uk





The Royal Bank of Scotland plc, Registered in Scotland No. 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB

Authorised and regulated by the Financial Services Authority.

This e-mail message is confidential and for use by the addressee only. If the message is received by anyone other than the addressee, please return the message to the sender by replying to it and then delete the message from your computer. Internet e-mails are not necessarily secure. The Royal Bank of Scotland plc does not accept responsibility for changes made to this message after it was sent.

Whilst all reasonable care has been taken to avoid the transmission of viruses, it is the responsibility of the recipient to ensure that the onward transmission, opening or use of this message and any attachments will not adversely affect its systems or data. No responsibility is accepted by The Royal Bank of Scotland plc in this regard and the recipient should carry out such virus and other checks as it considers appropriate.


Re: Issue with retrieving Tiles definitions in code

Posted by Antonio Petrelli <an...@gmail.com>.
2010/3/10 Gallagher, Jim (UK Europe Middle East & Group Functions,
Technology Services) <Ji...@rbs.co.uk>:
> I understand your point about moving to Tiles 2.x, but we're using mandated codebases here, and the standards people take a little while to certify releases for use!

I understand your point too :-D I've been in various places where such
"certification" rhymes with "absurdity". They search for "malware
code", doing anything but reading the code itself.

Anyway, good luck :-)

Antonio

RE: Issue with retrieving Tiles definitions in code

Posted by "Gallagher, Jim (UK Europe Middle East & Group Functions, Technology Services)" <Ji...@rbs.co.uk>.
Antonio,

Thanks for all your help on this.

I've managed to fix it, using a rather inelegant approach of including the roles logic further up the dependency chain for the definitions, rather than further down.

I understand your point about moving to Tiles 2.x, but we're using mandated codebases here, and the standards people take a little while to certify releases for use!



                                 Regards,

                                         Jim

Jim Gallagher,
Core Web Security,
Group Technology Solutions,
Royal Bank of Scotland,
Parkgate Business Park,
Parkgate Street,
Dublin 8.
RBS Depot Code: DUB

ITS: 			7-4171-7167
External:		+353-1-648 7167 
Internet mail: 	jim.gallagher@rbs.co.uk
P Please don't print this e-mail unless you really need to.




-----Original Message-----
From: Antonio Petrelli [mailto:antonio.petrelli@gmail.com] 
Sent: 09 March 2010 12:48
To: users@tiles.apache.org
Subject: Re: Issue with retrieving Tiles definitions in code

2010/3/9 Gallagher, Jim (UK Europe Middle East & Group Functions, Technology Services) <Ji...@rbs.co.uk>:
> This behaviour was available in Struts-Tiles, has it been removed from Tiles 2.0?

I think it was an unintended feature :-D

> The rules definition is, as you say, not designed to be rendered. It's purpose is to hold a list of security roles  - these roles are processed programmatically and this decides whether the user sees that menu item (or entire menu), based on their assigned role.

Tiles has a very basic role-based security: most of JSP tags (insertTemplate, insertAttribute, insertDefinition) have a "role"
attribute, where you can put comma-separated list of enabled roles (the user must be under at least one role).
These roles can be defined in XML files too.
If you need something more complicated, I think that your entry point might be the DefinitionsFactory:
http://tiles.apache.org/2.0/framework/tutorial/extension/points.html
However I think that you should move your rules outside of Tiles and load them separately.

If you have more questions on how to implement a DefinitionsFactory, feel free to ask here.

Antonio

P.S. I strongly suggest to migrate to, at least, Tiles 2.1.x: there are new features (like wildcards, EL expressions) that can help development a lot. Moreover, the API is cleaner.
*** WARNING : This message originates from the Internet ***

The Royal Bank of Scotland plc, Registered in Scotland No. 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB

Authorised and regulated by the Financial Services Authority.

This e-mail message is confidential and for use by the addressee only. If the message is received by anyone other than the addressee, please return the message to the sender by replying to it and then delete the message from your computer. Internet e-mails are not necessarily secure. The Royal Bank of Scotland plc does not accept responsibility for changes made to this message after it was sent.

Whilst all reasonable care has been taken to avoid the transmission of viruses, it is the responsibility of the recipient to ensure that the onward transmission, opening or use of this message and any attachments will not adversely affect its systems or data. No responsibility is accepted by The Royal Bank of Scotland plc in this regard and the recipient should carry out such virus and other checks as it considers appropriate.


Re: Issue with retrieving Tiles definitions in code

Posted by Antonio Petrelli <an...@gmail.com>.
2010/3/9 Gallagher, Jim (UK Europe Middle East & Group Functions,
Technology Services) <Ji...@rbs.co.uk>:
> This behaviour was available in Struts-Tiles, has it been removed from Tiles 2.0?

I think it was an unintended feature :-D

> The rules definition is, as you say, not designed to be rendered. It's purpose is to hold a list of security roles  - these roles are processed programmatically and this decides whether the user sees that menu item (or entire menu), based on their assigned role.

Tiles has a very basic role-based security: most of JSP tags
(insertTemplate, insertAttribute, insertDefinition) have a "role"
attribute, where you can put comma-separated list of enabled roles
(the user must be under at least one role).
These roles can be defined in XML files too.
If you need something more complicated, I think that your entry point
might be the DefinitionsFactory:
http://tiles.apache.org/2.0/framework/tutorial/extension/points.html
However I think that you should move your rules outside of Tiles and
load them separately.

If you have more questions on how to implement a DefinitionsFactory,
feel free to ask here.

Antonio

P.S. I strongly suggest to migrate to, at least, Tiles 2.1.x: there
are new features (like wildcards, EL expressions) that can help
development a lot. Moreover, the API is cleaner.

RE: Issue with retrieving Tiles definitions in code

Posted by "Gallagher, Jim (UK Europe Middle East & Group Functions, Technology Services)" <Ji...@rbs.co.uk>.
Thanks for your reply Antonio.

This behaviour was available in Struts-Tiles, has it been removed from Tiles 2.0?

The rules definition is, as you say, not designed to be rendered. It's purpose is to hold a list of security roles  - these roles are processed programmatically and this decides whether the user sees that menu item (or entire menu), based on their assigned role.

This functionality is used in our (very extensive) Branding & Security framework for Struts-Tiles, and I'd be keen to maintain it with only minimal change if possible. However, if it's not possible to recreate this in Tiles 2.0, I'd appreciate any suggestions as to how to achieve the objective.




                                 Regards,

                                         Jim

Jim Gallagher,
Core Web Security,
Group Technology Solutions,
Royal Bank of Scotland,
Parkgate Business Park,
Parkgate Street,
Dublin 8.
RBS Depot Code: DUB

ITS: 			7-4171-7167
External:		+353-1-648 7167 
Internet mail: 	jim.gallagher@rbs.co.uk
P Please don't print this e-mail unless you really need to.




-----Original Message-----
From: Antonio Petrelli [mailto:antonio.petrelli@gmail.com] 
Sent: 09 March 2010 11:11
To: users@tiles.apache.org
Subject: Re: Issue with retrieving Tiles definitions in code

2010/3/9 Gallagher, Jim (UK Europe Middle East & Group Functions, Technology Services) <Ji...@rbs.co.uk>:
> A rules definition is defined as follows:
>
>        <definition name="rule.menu.messaging.view">
>                <put-attribute name="type" value="one_role" />
>                <put-list-attribute name="roles">
>                        <add-attribute value="ROLE1" />
>                        <add-attribute value="ROLE2" />
>                        <add-attribute value="ROLE3" />
>                </put-list-attribute>
>        </definition>
>
> Ultimately I want to retrieve the rules definition, retrieve the roles specified and process them according to our own security standards here.
>
> Where it's falling down is that in the TilesMenuRuleControlPreparer class, I'm trying to retrieve the rules definition as follows:
>
>                        DefinitionManager definitionManager = new 
> DefinitionManager(
>                                        
> "org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG");
>
>                        Definition def = 
> definitionManager.getDefinition(name,
>                                        tilesRequestContext);
>
> This is failing with a NullPointerException - on debugging, I see that the Factory instance within the DefinitionManager is null.

This is normal, you are not using the correct tool.
DefinitionManager is a tool used by Tiles to define newly-created definitions, not to retrieve already stored ones.
However, there is a problem: you cannot get a definition using the Tiles API. You can only render it, and use the attributes in the template page. So I think we need to find a workaround.
The definition has no meaning without a template (its own, or inherited from an extended definition).
How do you want to use these "rules"?

Antonio
*** WARNING : This message originates from the Internet ***

The Royal Bank of Scotland plc, Registered in Scotland No. 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB

Authorised and regulated by the Financial Services Authority.

This e-mail message is confidential and for use by the addressee only. If the message is received by anyone other than the addressee, please return the message to the sender by replying to it and then delete the message from your computer. Internet e-mails are not necessarily secure. The Royal Bank of Scotland plc does not accept responsibility for changes made to this message after it was sent.

Whilst all reasonable care has been taken to avoid the transmission of viruses, it is the responsibility of the recipient to ensure that the onward transmission, opening or use of this message and any attachments will not adversely affect its systems or data. No responsibility is accepted by The Royal Bank of Scotland plc in this regard and the recipient should carry out such virus and other checks as it considers appropriate.


Re: Issue with retrieving Tiles definitions in code

Posted by Antonio Petrelli <an...@gmail.com>.
2010/3/9 Gallagher, Jim (UK Europe Middle East & Group Functions,
Technology Services) <Ji...@rbs.co.uk>:
> A rules definition is defined as follows:
>
>        <definition name="rule.menu.messaging.view">
>                <put-attribute name="type" value="one_role" />
>                <put-list-attribute name="roles">
>                        <add-attribute value="ROLE1" />
>                        <add-attribute value="ROLE2" />
>                        <add-attribute value="ROLE3" />
>                </put-list-attribute>
>        </definition>
>
> Ultimately I want to retrieve the rules definition, retrieve the roles specified and process them according to our own security standards here.
>
> Where it's falling down is that in the TilesMenuRuleControlPreparer class, I'm trying to retrieve the rules definition as follows:
>
>                        DefinitionManager definitionManager = new DefinitionManager(
>                                        "org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG");
>
>                        Definition def = definitionManager.getDefinition(name,
>                                        tilesRequestContext);
>
> This is failing with a NullPointerException - on debugging, I see that the Factory instance within the DefinitionManager is null.

This is normal, you are not using the correct tool.
DefinitionManager is a tool used by Tiles to define newly-created
definitions, not to retrieve already stored ones.
However, there is a problem: you cannot get a definition using the
Tiles API. You can only render it, and use the attributes in the
template page. So I think we need to find a workaround.
The definition has no meaning without a template (its own, or
inherited from an extended definition).
How do you want to use these "rules"?

Antonio

RE: Issue with retrieving Tiles definitions in code

Posted by "Gallagher, Jim (UK Europe Middle East & Group Functions, Technology Services)" <Ji...@rbs.co.uk>.
Thanks for your message. I'll try to explain more clearly: 

Page and menu definitions are stored in two files, pages.xml and menus.xml, which are referenced in the web.xml as follows:

	<servlet>
		<servlet-name>TilesServlet</servlet-name>
		<servlet-class>
			org.apache.tiles.web.startup.TilesServlet
		</servlet-class>
		<init-param>
			<param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
			<param-value>/WEB-INF/pages.xml,/WEB-INF/menus.xml</param-value>
		</init-param>
		<load-on-startup>2</load-on-startup>
	</servlet>

Page definitions consist of templated JSPs, plus a menu item e.g.

	<definition name="/menulayout"
		preparer="com.rbsg.application.cws.brand.jsf.XXXBrandPreparer"
		template="/templates/layout.jsp">
		<put-attribute name="banner" value="/banner.jsp" />
		<put-attribute name="title"
			value="XXXXX Message Application" />
		<put-attribute name="header" value="/header.jsp" />
		<put-attribute name="navigation" value="/navigation.jsp" />
		<put-attribute name="menu" value="nav.main" />
		<put-attribute name="footer" value="/footer.jsp" />
	</definition>

The menu item ("nav.main" above) consists of menu entries, plus a rules definition:

	<definition name="menu.messaging.createmessage"
		extends="menu.mainMenuLayout"
		preparer="com.rbsg.application.cws.web.menu.jsf.TilesMenuRuleControlPreparer">
		<put-attribute name="id" value="menu.messaging.createmessage" />
		<put-attribute name="title" value="Create message" />
		<put-attribute name="link" value="/createmessage.jsp" />
		<put-list-attribute name="rules">
			<add-attribute value="rule.menu.messaging.view" />
		</put-list-attribute>
	</definition>

All of these are read and processed by Tiles automatically & successfully. The preparer class TilesMenuRuleControlPreparer in the menu is supposed to do retrieve the rules definition ("rule.menu.messaging.view" in the above case), and process it according to our security rules. 

A rules definition is defined as follows:

	<definition name="rule.menu.messaging.view">
		<put-attribute name="type" value="one_role" />
		<put-list-attribute name="roles">
			<add-attribute value="ROLE1" />
			<add-attribute value="ROLE2" />
			<add-attribute value="ROLE3" />
		</put-list-attribute>
	</definition>

Ultimately I want to retrieve the rules definition, retrieve the roles specified and process them according to our own security standards here.

Where it's falling down is that in the TilesMenuRuleControlPreparer class, I'm trying to retrieve the rules definition as follows:

			DefinitionManager definitionManager = new DefinitionManager(
					"org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG");

			Definition def = definitionManager.getDefinition(name,
					tilesRequestContext);

This is failing with a NullPointerException - on debugging, I see that the Factory instance within the DefinitionManager is null.

I'm trying to find a way to refer to the definition files read in automatically, so I can retrieve the rules definitions from there.

I hope this explains it further - if not, please get back to me.

                                 Regards,

                                         Jim

Jim Gallagher,
Core Web Security,
Group Technology Solutions,
Royal Bank of Scotland,
Parkgate Business Park,
Parkgate Street,
Dublin 8.
RBS Depot Code: DUB

ITS: 			7-4171-7167
External:		+353-1-648 7167 
Internet mail: 	jim.gallagher@rbs.co.uk
P Please don't print this e-mail unless you really need to.




-----Original Message-----
From: Antonio Petrelli [mailto:antonio.petrelli@gmail.com] 
Sent: 09 March 2010 10:43
To: users@tiles.apache.org
Subject: Re: Issue with retrieving Tiles definitions in code

Can you explain what you need in a more abstract way?
What definition files are you reading?
How do you want to override the definitions defined there?
I would like to have a broader knowledge before I can help you.

Antonio

2010/3/9 Gallagher, Jim (UK Europe Middle East & Group Functions, Technology Services) <Ji...@rbs.co.uk>:
> Hi,
>
> I'm currently writing a web application using Java 5, Websphere 6.1, 
> JSF and Tiles 2.0.6 (versions mandated by organisation).
>
> I'm converting a multi-brand menu system from Struts-Tiles, and having 
> an issue when processing definitions. What I'm trying to achieve is:
>
> Define a DefinitionManager in the ViewPreparer for a given definition 
> Read another definition (stored in menus.xml, referenced in the 
> web.xml) into a Definition object, to process the rules contained 
> therein
>
> My problem is that I cannot see how to get a link to the correct 
> DefinitionsFactory that contains the default definitions read in at 
> application startup. I'd even settle for re-reading them, but cannot 
> find a way how to do that either without getting a reference to the 
> factory.
>
> Could anyone provide any assistance or advice? All constructive advice 
> gratefully received.
>
>
>                                 Regards,
>
>                                         Jim
>
> Jim Gallagher,
> Internet mail:  jim.gallagher@rbs.co.uk
>
>
>
>
>
> The Royal Bank of Scotland plc, Registered in Scotland No. 90312. 
> Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB
>
> Authorised and regulated by the Financial Services Authority.
>
> This e-mail message is confidential and for use by the addressee only. If the message is received by anyone other than the addressee, please return the message to the sender by replying to it and then delete the message from your computer. Internet e-mails are not necessarily secure. The Royal Bank of Scotland plc does not accept responsibility for changes made to this message after it was sent.
>
> Whilst all reasonable care has been taken to avoid the transmission of viruses, it is the responsibility of the recipient to ensure that the onward transmission, opening or use of this message and any attachments will not adversely affect its systems or data. No responsibility is accepted by The Royal Bank of Scotland plc in this regard and the recipient should carry out such virus and other checks as it considers appropriate.
>
>
*** WARNING : This message originates from the Internet ***

The Royal Bank of Scotland plc, Registered in Scotland No. 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB

Authorised and regulated by the Financial Services Authority.

This e-mail message is confidential and for use by the addressee only. If the message is received by anyone other than the addressee, please return the message to the sender by replying to it and then delete the message from your computer. Internet e-mails are not necessarily secure. The Royal Bank of Scotland plc does not accept responsibility for changes made to this message after it was sent.

Whilst all reasonable care has been taken to avoid the transmission of viruses, it is the responsibility of the recipient to ensure that the onward transmission, opening or use of this message and any attachments will not adversely affect its systems or data. No responsibility is accepted by The Royal Bank of Scotland plc in this regard and the recipient should carry out such virus and other checks as it considers appropriate.


Re: Issue with retrieving Tiles definitions in code

Posted by Antonio Petrelli <an...@gmail.com>.
Can you explain what you need in a more abstract way?
What definition files are you reading?
How do you want to override the definitions defined there?
I would like to have a broader knowledge before I can help you.

Antonio

2010/3/9 Gallagher, Jim (UK Europe Middle East & Group Functions,
Technology Services) <Ji...@rbs.co.uk>:
> Hi,
>
> I'm currently writing a web application using Java 5, Websphere 6.1, JSF
> and Tiles 2.0.6 (versions mandated by organisation).
>
> I'm converting a multi-brand menu system from Struts-Tiles, and having
> an issue when processing definitions. What I'm trying to achieve is:
>
> Define a DefinitionManager in the ViewPreparer for a given definition
> Read another definition (stored in menus.xml, referenced in the web.xml)
> into a Definition object, to process the rules contained therein
>
> My problem is that I cannot see how to get a link to the correct
> DefinitionsFactory that contains the default definitions read in at
> application startup. I'd even settle for re-reading them, but cannot
> find a way how to do that either without getting a reference to the
> factory.
>
> Could anyone provide any assistance or advice? All constructive advice
> gratefully received.
>
>
>                                 Regards,
>
>                                         Jim
>
> Jim Gallagher,
> Internet mail:  jim.gallagher@rbs.co.uk
>
>
>
>
>
> The Royal Bank of Scotland plc, Registered in Scotland No. 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB
>
> Authorised and regulated by the Financial Services Authority.
>
> This e-mail message is confidential and for use by the addressee only. If the message is received by anyone other than the addressee, please return the message to the sender by replying to it and then delete the message from your computer. Internet e-mails are not necessarily secure. The Royal Bank of Scotland plc does not accept responsibility for changes made to this message after it was sent.
>
> Whilst all reasonable care has been taken to avoid the transmission of viruses, it is the responsibility of the recipient to ensure that the onward transmission, opening or use of this message and any attachments will not adversely affect its systems or data. No responsibility is accepted by The Royal Bank of Scotland plc in this regard and the recipient should carry out such virus and other checks as it considers appropriate.
>
>