You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Sam Zilverberg <sa...@gmail.com> on 2011/03/24 16:25:25 UTC

how to direct from servlet to login page and then back to servlet?

I've got a servlet that serves files.
It's mounted on /files/* and has a WicketSessionFilter on that same path so
it has access to the wicket session.

When a user accesses /files/?id=1 the servlet checks that the wicket session
exists, that the user is logged in and some other logic then serves the file
to the user.
When a user is not logged in, and say comes to this url from a link in an
email, I'd like the servlet to send him to the login page, then after
providing credentials I'd like to return to the original url so the file
will be served.

What is the best way to accomplish this?

So far I tried to redirect like this:
servlet:
response.redirect(contextPath + "/login?destination=files/?id=" + id)
login page after login success:
if (destination != null)   getRequestCycle().setRequestTarget(new
RedirectRequestTarget(destination));
but this failed because the request was redirected twice and it is not
allowed.

I also tried to forward the request but failed.

Any help would be appreciated!

Re: how to direct from servlet to login page and then back to servlet?

Posted by Zilvinas Vilutis <ci...@gmail.com>.
You can use spring security for filtering the URL patterns...

Žilvinas Vilutis

Mobile:   (+370) 652 38353
E-mail:   cikasfm@gmail.com



On Thu, Mar 24, 2011 at 9:37 AM, Sam Zilverberg <sa...@gmail.com> wrote:
> This works but the url doesn't change in the browser to /reports/?id=1, it
> stays as login/destination=...
>
> I'm thinking of reimplementing this as a wicket page with page params.
> any other thought on how to implement this kind of functionality with
> servlet/wicket login page?
>

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


Re: how to direct from servlet to login page and then back to servlet?

Posted by Sam Zilverberg <sa...@gmail.com>.
This works but the url doesn't change in the browser to /reports/?id=1, it
stays as login/destination=...

I'm thinking of reimplementing this as a wicket page with page params.
any other thought on how to implement this kind of functionality with
servlet/wicket login page?

Re: how to direct from servlet to login page and then back to servlet?

Posted by Martin Grigorov <mg...@apache.org>.
Try with "throw new RedirectToUrlException(destination)" instead of setting
new RequestTarget

On Thu, Mar 24, 2011 at 4:25 PM, Sam Zilverberg <sa...@gmail.com>wrote:

> I've got a servlet that serves files.
> It's mounted on /files/* and has a WicketSessionFilter on that same path so
> it has access to the wicket session.
>
> When a user accesses /files/?id=1 the servlet checks that the wicket
> session
> exists, that the user is logged in and some other logic then serves the
> file
> to the user.
> When a user is not logged in, and say comes to this url from a link in an
> email, I'd like the servlet to send him to the login page, then after
> providing credentials I'd like to return to the original url so the file
> will be served.
>
> What is the best way to accomplish this?
>
> So far I tried to redirect like this:
> servlet:
> response.redirect(contextPath + "/login?destination=files/?id=" + id)
> login page after login success:
> if (destination != null)   getRequestCycle().setRequestTarget(new
> RedirectRequestTarget(destination));
> but this failed because the request was redirected twice and it is not
> allowed.
>
> I also tried to forward the request but failed.
>
> Any help would be appreciated!
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>