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) <joost...@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-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to