You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by dpmihai <dp...@yahoo.com> on 2012/06/18 15:48:00 UTC

Wicket 1.4 Remember Login WIth Cookie

Hi.

I have a wicket 1.4 application with a AuthenticatedWebSession with
authenticate(String username, String password) method. I use annotations to
allow for seeing some components : @AuthorizeAction(action = Action.RENDER,
roles = Roles.ADMIN) for example.

I want when user logs in to save a cookie and use that cookie to keep user
logged in for ever until he logs out.

I have my custom LoginPanel with user, password and remember checkbox. In
LoginPanel I use a LoginValidator like:
    @Override
    protected void onInitialize() {
    	super.onInitialize();
        getForm().add(new LoginValidator(username, password, remember));
    }

and in my LoginValidator, after a successful login, I do the following:

     if (remember.getConvertedInput()) {
	HttpServletResponse servletResponse = ((BufferedWebResponse) 
RequestCycle.get().getResponse()).getHttpServletResponse();
	Cookie c = new Cookie("userid", username);
	servletResponse.addCookie(c);
     }	

My cookie is created. But I do not know WHERE to read from
HttpServletRequest to see that a cookie exists and automatically login the
user if session expired. Any clues?



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-1-4-Remember-Login-WIth-Cookie-tp4650029.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Wicket 1.4 Remember Login WIth Cookie

Posted by dpmihai <dp...@yahoo.com>.
I made it by reading cookies in my AuthenticatedWebApplication in

        @Override				
	public Session newSession(Request request, Response response) {
		
		Session session = super.newSession(request, response);
		HttpServletRequest servletRequest = ((ServletWebRequest)
request).getHttpServletRequest();
		Cookie[] cookies = servletRequest.getCookies();
                .....
        }

and in the case a remember is needed i call sign-in.

PS. I know about SignInPanel, but I wanted a custom solution.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-1-4-Remember-Login-WIth-Cookie-tp4650029p4650038.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Wicket 1.4 Remember Login WIth Cookie

Posted by Martin Grigorov <mg...@apache.org>.
See wicket-examples project.
It has an example with rememberMe functionality.

On Mon, Jun 18, 2012 at 5:16 PM, dpmihai <dp...@yahoo.com> wrote:
> Hi.
>
> My problem is not how to read the cookie. I do not know WHERE to read it,
> because my authentication is done from LoginPanel / LoginValidator, and I do
> not want my LoginPanel to be shown anymore.
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-1-4-Remember-Login-WIth-Cookie-tp4650029p4650032.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



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

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


Re: Wicket 1.4 Remember Login WIth Cookie

Posted by dpmihai <dp...@yahoo.com>.
Hi.

My problem is not how to read the cookie. I do not know WHERE to read it,
because my authentication is done from LoginPanel / LoginValidator, and I do
not want my LoginPanel to be shown anymore.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-1-4-Remember-Login-WIth-Cookie-tp4650029p4650032.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Wicket 1.4 Remember Login WIth Cookie

Posted by Martin Grigorov <mg...@apache.org>.
CookieUtils (1.5+) is the new name of CookieValuePersister (until 1.4.x)

On Mon, Jun 18, 2012 at 5:09 PM, Thomas Götz <to...@decoded.de> wrote:
> Have a look at org.apache.wicket.util.cookies.CookieUtils#load(final String key).
>
> Cheers,
>   -Tom
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



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

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


Re: Wicket 1.4 Remember Login WIth Cookie

Posted by Thomas Götz <to...@decoded.de>.
Have a look at org.apache.wicket.util.cookies.CookieUtils#load(final String key).

Cheers,
   -Tom


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