You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Hauke <ha...@gmx.net> on 2011/04/17 11:13:11 UTC
Access Page-object in ComponentRequestFilter
Hello,
I have implemented a ComponentRequestFilter that takes care of
access-control within my Tapestry5 Application. It checks if access to
the requested page is restricted to one or more roles, if thats the case
and the user is not yet logged in it redirects to the Login-page:
... // set forward after login
Link link = renderLinkSource.createPageRenderLink(Login.class);
response.sendRedirect(link);
return true;
Now that works as expected, but i want to say to the Login-page where to
redirect after authentication is done. At the moment I am writing an
attribute to the Session:
HttpSession session =
this.requestGlobals.getHTTPServletRequest().getSession();
session.setAttribute(KEY_FORWARD_CLASS, requestedPage.getClass());
... // redirect to login
When the Login-page has its work done, it looks in the session if this
attribute is present and redirects using it as an Eventmethod-response.
I think it would be much more consitent if I could pass the forward
using a simple Setter-method of the Login-page:
Login login = (Login) componentSource.getPage(Login.class); //
throws ClassCastException
login.setForward(requestPage.getClass()); // the property that is
set must be @Persistent!
Link link = renderLinkSource.createPageRenderLink(Login.class);
response.sendRedirect(link);
return true;
But it can't be done this way because I am not able to obtain an
Instance of my Login-page in the ComponentRequestFilter. In another Page
i could use the @InjectPage-Annotation. So my Question is:
Is there an Alternative to the @InjectPage-Annotation? And if thats the
case, should it be done this way?
If have looked through the Tapestry5-API but could not find a solution,
so any help is appreciated.
Re: Access Page-object in ComponentRequestFilter
Posted by Taha Hafeez <ta...@gmail.com>.
Hi Hauke,
Can't you do this in your ComponentRequestFilter
pageRenderLinkSource.createPageLink(Login.class,
requestGlobals.getActivePageName());
response.disableCompression();
response.sendRedirect(link.toAbsoluteURI());
and later in the page you can do this
@Persist(PersistenceConstants.FLASH)
private String url;
void onActivate(String url){
if(url == null){
this.url = url;
}
}
Object onSubmitFromLoginForm() {
if (loginService.login(userName, password)) {
return (url == null || url.trim().equals("")) ? "Index" : url;
}
loginForm.recordError("Invalid user-name or password");
return this;
}
regards
Taha
On Sun, Apr 17, 2011 at 2:43 PM, Hauke <ha...@gmx.net> wrote:
> Hello,
>
> I have implemented a ComponentRequestFilter that takes care of
> access-control within my Tapestry5 Application. It checks if access to the
> requested page is restricted to one or more roles, if thats the case and the
> user is not yet logged in it redirects to the Login-page:
>
> ... // set forward after login
> Link link = renderLinkSource.createPageRenderLink(Login.class);
> response.sendRedirect(link);
> return true;
>
>
> Now that works as expected, but i want to say to the Login-page where to
> redirect after authentication is done. At the moment I am writing an
> attribute to the Session:
>
> HttpSession session =
> this.requestGlobals.getHTTPServletRequest().getSession();
> session.setAttribute(KEY_FORWARD_CLASS, requestedPage.getClass());
> ... // redirect to login
>
>
> When the Login-page has its work done, it looks in the session if this
> attribute is present and redirects using it as an Eventmethod-response.
> I think it would be much more consitent if I could pass the forward using a
> simple Setter-method of the Login-page:
>
> Login login = (Login) componentSource.getPage(Login.class); //
> throws ClassCastException
> login.setForward(requestPage.getClass()); // the property that is
> set must be @Persistent!
> Link link = renderLinkSource.createPageRenderLink(Login.class);
> response.sendRedirect(link);
> return true;
>
>
> But it can't be done this way because I am not able to obtain an Instance
> of my Login-page in the ComponentRequestFilter. In another Page i could use
> the @InjectPage-Annotation. So my Question is:
> Is there an Alternative to the @InjectPage-Annotation? And if thats the
> case, should it be done this way?
>
> If have looked through the Tapestry5-API but could not find a solution, so
> any help is appreciated.
>