You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Inge Solvoll <in...@gmail.com> on 2008/09/12 11:52:33 UTC

T5: Access control dispatcher not working

Hi!

I've implemented my own version of the dispatcher pattern from the wiki

http://wiki.apache.org/tapestry/Tapestry5HowToCreateADispatcher
http://wiki.apache.org/tapestry/Tapestry5HowToCreateADispatcher2

I'm redirecting to our Struts login page through my custom made StrutsLink
that works. I'm actually redirected to the correct login, but the requested
tapestry 5 page is run first... Obviously I don't want that. I expected that
when I return false from the dispatch method, the requested page is skipped.
Am I wrong?



My code:

public class AccessController implements Dispatcher {

  private ApplicationStateManager asm;

  public AccessController(ApplicationStateManager asm) {
    this.asm = asm;
  }

  public boolean dispatch(Request request, Response response) throws
IOException {
    boolean canAccess = false;

    if (asm.exists(User.class)) {
      canAccess = true;
    }
    else {
      User userInSession = (User)
request.getSession(true).getAttribute(GlobalKeys.SESSION_USER);
      if (userInSession != null) {
        asm.set(User.class, userInSession);
        canAccess = true;
      }
    }

    if (!canAccess) {

      request.getSession(true).setAttribute("requestedPath",
request.getPath());

      response.sendRedirect(new StrutsLink(request, "/login.do"));
    }

    return false;
  }
}

Re: T5: Access control dispatcher not working

Posted by Inge Solvoll <in...@gmail.com>.
Ahh! RTFM. Thank you for not yelling :)

On Fri, Sep 12, 2008 at 11:55 AM, Hugo Palma <hu...@gmail.com> wrote:

> Actually it's the other way around.
> You should return true from the dispatch method when you want to redirect.
>
> The javadoc for the dispatch method states:
> "@return true if a response was delivered, false if the servlet container
> should be allowed to handle the request"
>
>
> Inge Solvoll wrote:
>
>> Hi!
>>
>> I've implemented my own version of the dispatcher pattern from the wiki
>>
>> http://wiki.apache.org/tapestry/Tapestry5HowToCreateADispatcher
>> http://wiki.apache.org/tapestry/Tapestry5HowToCreateADispatcher2
>>
>> I'm redirecting to our Struts login page through my custom made StrutsLink
>> that works. I'm actually redirected to the correct login, but the
>> requested
>> tapestry 5 page is run first... Obviously I don't want that. I expected
>> that
>> when I return false from the dispatch method, the requested page is
>> skipped.
>> Am I wrong?
>>
>>
>>
>> My code:
>>
>> public class AccessController implements Dispatcher {
>>
>>  private ApplicationStateManager asm;
>>
>>  public AccessController(ApplicationStateManager asm) {
>>    this.asm = asm;
>>  }
>>
>>  public boolean dispatch(Request request, Response response) throws
>> IOException {
>>    boolean canAccess = false;
>>
>>    if (asm.exists(User.class)) {
>>      canAccess = true;
>>    }
>>    else {
>>      User userInSession = (User)
>> request.getSession(true).getAttribute(GlobalKeys.SESSION_USER);
>>      if (userInSession != null) {
>>        asm.set(User.class, userInSession);
>>        canAccess = true;
>>      }
>>    }
>>
>>    if (!canAccess) {
>>
>>      request.getSession(true).setAttribute("requestedPath",
>> request.getPath());
>>
>>      response.sendRedirect(new StrutsLink(request, "/login.do"));
>>    }
>>
>>    return false;
>>  }
>> }
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5: Access control dispatcher not working

Posted by Hugo Palma <hu...@gmail.com>.
Actually it's the other way around.
You should return true from the dispatch method when you want to redirect.

The javadoc for the dispatch method states:
"@return true if a response was delivered, false if the servlet 
container should be allowed to handle the request"

Inge Solvoll wrote:
> Hi!
>
> I've implemented my own version of the dispatcher pattern from the wiki
>
> http://wiki.apache.org/tapestry/Tapestry5HowToCreateADispatcher
> http://wiki.apache.org/tapestry/Tapestry5HowToCreateADispatcher2
>
> I'm redirecting to our Struts login page through my custom made StrutsLink
> that works. I'm actually redirected to the correct login, but the requested
> tapestry 5 page is run first... Obviously I don't want that. I expected that
> when I return false from the dispatch method, the requested page is skipped.
> Am I wrong?
>
>
>
> My code:
>
> public class AccessController implements Dispatcher {
>
>   private ApplicationStateManager asm;
>
>   public AccessController(ApplicationStateManager asm) {
>     this.asm = asm;
>   }
>
>   public boolean dispatch(Request request, Response response) throws
> IOException {
>     boolean canAccess = false;
>
>     if (asm.exists(User.class)) {
>       canAccess = true;
>     }
>     else {
>       User userInSession = (User)
> request.getSession(true).getAttribute(GlobalKeys.SESSION_USER);
>       if (userInSession != null) {
>         asm.set(User.class, userInSession);
>         canAccess = true;
>       }
>     }
>
>     if (!canAccess) {
>
>       request.getSession(true).setAttribute("requestedPath",
> request.getPath());
>
>       response.sendRedirect(new StrutsLink(request, "/login.do"));
>     }
>
>     return false;
>   }
> }
>
>   

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