You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Joost Schouten (ml)" <jo...@jsportal.com> on 2009/09/22 17:09:12 UTC

Obtaining a reference to the component tree of a page while Dispatching

Hi,

I am looking for a way to get a hold of all components Class'es on a 
page while in a dispatcher. I want to know if any of the components on 
the page are annotated with my custom @SecuredContent annotation but 
have no clue how to figure out what components are loaded on a page when 
I only have access to the page.

through the ComponentClassResolver I can find my Class of the page but 
here I don't have access to the Components. Should I use the PagePool to 
have a look? I'm not quite sure what implications this might have if I 
do this on every request to a page.

Looking forward to some tricks and tips.

Cheers,
Joost

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Obtaining a reference to the component tree of a page while Dispatching

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Tue, 22 Sep 2009 14:38:35 -0300, Joost Schouten (ml)  
<jo...@jsportal.com> escreveu:

> Thiago,

Hi!

> Thanks for your quick response.

I had working code to show, so it was easy to be quick. :P

> Security checking on the page level is all fine and works great. It is  
> good to see that my implementation overlaps yours a lot. (Difference is  
> that I don't use the setMeta, but check for the annotation in the  
> Dispatcher itself)

The advantage of using the approach I proposed is that changes in the  
annotations reflect immediately (live class reloading), while checking  
directly in the class would make page annotation changes to be in effect  
just after a restart.

> I was hoping to be able to actually annotate a component and reject page  
> access based on the most restricting annotated component on the page.

I guess you would need to forget about dispatchers and implement a  
ComponentClassTransformWorker that adds a method to the annotated  
component that does the checks you need and throw an exception if needed.  
Your error page would handle this situation and probably show some message  
to your users.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Obtaining a reference to the component tree of a page while Dispatching

Posted by "Joost Schouten (ml)" <jo...@jsportal.com>.
Thiago,

Thanks for your quick response. Security checking on the page level is 
all fine and works great. It is good to see that my implementation 
overlaps yours a lot. (Difference is that I don't use the setMeta, but 
check for the annotation in the Dispatcher itself)

I was hoping to be able to actually annotate a component and reject page 
access based on the most restricting annotated component on the page.

I'll keep trying. any further pointers would be appreciated.

Thanks,
Joost

Thiago H. de Paula Figueiredo wrote:
> Em Tue, 22 Sep 2009 12:09:12 -0300, Joost Schouten (ml) 
> <jo...@jsportal.com> escreveu:
>
>> Hi,
>
> Hi!
>
>> I am looking for a way to get a hold of all components Class'es on a 
>> page while in a dispatcher. I want to know if any of the components 
>> on the page are annotated with my custom @SecuredContent annotation 
>> but have no clue how to figure out what components are loaded on a 
>> page when I only have access to the page.
>
> I don't know how you would get the component tree.
> But, if the annotation was in a page, I would implement a 
> ComponentClassTransformer. This is an example that I hope it gives you 
> a clue:
>
> public class TapestrySecurityWorker implements 
> ComponentClassTransformWorker {
>     public void transform(ClassTransformation transformation, 
> MutableComponentModel model) {
>         if (transformation.getAnnotation(NeedsLoggedInUser.class) != 
> null) {
>             
> model.setMeta(TapestrySecurityConstants.NEEDS_LOGGED_IN_USER_METADATA_KEY, 
> "true");
>         }
>     }
> }
>
> The important trick here is the MutableComponentModel.setMeta() 
> method. Then, in a dispatcher, I can check the meta information:
>
> String pageName = extractPageName(request);
>
> if (pageName != null) {
>
>     final ComponentModel pageModel = 
> componentModelSource.getPageModel(pageName);
>     final String loggedInMetaValue = 
> pageModel.getMeta(TapestrySecurityConstants.NEEDS_LOGGED_IN_USER_METADATA_KEY); 
>
>      ...
>
> }
>
> private String extractPageName(Request request) {
>
>     String pageName = null;
>
>     final ComponentEventRequestParameters componentEventParameters = 
> linkEncoder.decodeComponentEventRequest(request);
>
>     if (componentEventParameters != null) {
>         pageName = componentEventParameters.getContainingPageName();
>     }
>
>     if (pageName == null) {
>
>         final PageRenderRequestParameters pageRenderParameters = 
> linkEncoder.decodePageRenderRequest(request);
>
>         if (pageRenderParameters != null) {
>             pageName = pageRenderParameters.getLogicalPageName();
>         }
>
>     }
>
>     return pageName;
>
> }
>
> linkEncoder is an instance of the ComponentEventLinkEncoder service.
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Obtaining a reference to the component tree of a page while Dispatching

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Tue, 22 Sep 2009 12:09:12 -0300, Joost Schouten (ml)  
<jo...@jsportal.com> escreveu:

> Hi,

Hi!

> I am looking for a way to get a hold of all components Class'es on a  
> page while in a dispatcher. I want to know if any of the components on  
> the page are annotated with my custom @SecuredContent annotation but  
> have no clue how to figure out what components are loaded on a page when  
> I only have access to the page.

I don't know how you would get the component tree.
But, if the annotation was in a page, I would implement a  
ComponentClassTransformer. This is an example that I hope it gives you a  
clue:

public class TapestrySecurityWorker implements  
ComponentClassTransformWorker {
	public void transform(ClassTransformation transformation,  
MutableComponentModel model) {
		if (transformation.getAnnotation(NeedsLoggedInUser.class) != null) {
			model.setMeta(TapestrySecurityConstants.NEEDS_LOGGED_IN_USER_METADATA_KEY,  
"true");
		}
	}
}

The important trick here is the MutableComponentModel.setMeta() method.  
Then, in a dispatcher, I can check the meta information:

String pageName = extractPageName(request);

if (pageName != null) {

	final ComponentModel pageModel =  
componentModelSource.getPageModel(pageName);
	final String loggedInMetaValue =  
pageModel.getMeta(TapestrySecurityConstants.NEEDS_LOGGED_IN_USER_METADATA_KEY);
  	...

}

private String extractPageName(Request request) {

	String pageName = null;

	final ComponentEventRequestParameters componentEventParameters =  
linkEncoder.decodeComponentEventRequest(request);

	if (componentEventParameters != null) {
		pageName = componentEventParameters.getContainingPageName();
	}

	if (pageName == null) {

		final PageRenderRequestParameters pageRenderParameters =  
linkEncoder.decodePageRenderRequest(request);

		if (pageRenderParameters != null) {
			pageName = pageRenderParameters.getLogicalPageName();
		}

	}

	return pageName;

}

linkEncoder is an instance of the ComponentEventLinkEncoder service.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org