ratcashdev / authenticroast

Automatically exported from code.google.com/p/authenticroast
1 stars 0 forks source link

Feature request for RequestHandler.java #1

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I would like to be able to set REQUEST_PATH_NOTE in RequestHandler to be
some default location like a homepage. Currently when I log out of my app I
am taken back to login page and REQUEST_PATH_NOTE is cleared. So if I try
to log back in it won't work because the authenticator doesn't know where
to forward the request to.

Something like setPathForRequest(String path) maybe?

Original issue reported on code.google.com by sash...@gmail.com on 4 Mar 2010 at 7:08

GoogleCodeExporter commented 9 years ago
Hi!

Do you use the LogoutManager from the Extras module? Or how exactly do you 
handle 
logging your users out?

With the LogoutManager, you could just overwrite getNextPath() to return some 
URL, or 
pass the URL as _to parameter, like: j_security_exit?_to=/path/to/front.html

If you are using your own authenticator, you could call 
manager.forward(request, 
"/path/to/front.html") right before returning ManageAction.Clear.

Does this fix your problem?
:-)

Original comment by aike.som...@gmail.com on 5 Mar 2010 at 3:46

GoogleCodeExporter commented 9 years ago
Thanks for the suggestion, but I think this would only solve my problem 
partially
because it will work on logout only. What if the user goes straight to the 
login page
without trying to access a restricted resource? Then there is no 
REQUEST_PATH_NOTE
set and I get IllegalStateException for redirecting to null. 

Original comment by sash...@gmail.com on 6 Mar 2010 at 1:49

GoogleCodeExporter commented 9 years ago
Here's an example of what that method might look like: 

public void setPathForRequest(AuthenticationRequest request, String path){
        String reqPath = path;
        String reqQuery = null;
        if(path != null && path.contains("?")){
            String[] qs = path.split("?");
            reqPath = qs[0];
            reqQuery = qs[1];
        }
        session(request).put(REQUEST_PATH_NOTE, reqPath);
        session(request).put(REQUEST_CONTEXT_NOTE,
request.getHttpServletRequest().getContextPath());
        session(request).put(REQUEST_QUERY_NOTE, reqQuery);
    }

Original comment by sash...@gmail.com on 6 Mar 2010 at 5:19

GoogleCodeExporter commented 9 years ago
I just committed a change to the FormAuthenticator which allows to specify a 
default 
page in case there is no original request. I believe it's the better place for 
such a 
change as the desired behavior is likely to change for other types of 
authentication.

You can simply overwrite getNextPath() to specify this. I do have some more 
changes in 
this regard planned, but that will have to wait since it involes some 
api-changes.

I hope this helps!
:-)

Original comment by aike.som...@gmail.com on 7 Mar 2010 at 12:52

GoogleCodeExporter commented 9 years ago
Thank you!

This works great! No need for me to set REQUEST_PATH_NOTE anymore. 

Regards,
Alex

Original comment by sash...@gmail.com on 8 Mar 2010 at 2:34