Problem with infinite redirect

171 views
Skip to first unread message

Mike Grove

unread,
Sep 2, 2010, 1:48:03 PM9/2/10
to play-fr...@googlegroups.com
I have a controller which provides the basic functions for my site.

I'd like to make the authentication optional; if you want everything to be password protected, you tweak *something* and restart the application and boom, you've got to auth where you did not have to before.  I want to avoid having basically a duplicate project where my controllers are just annotated w/ Secure, I just want to introduce a new controller in front of my existing controllers that handles the auth.

My thought on how to do this was like this:

In my core module:
MasterController -> contains all the normal site functionality w/ a routes file that sends all the requests to the correct actions

In the secure module:
@With({Secure.class, MasterController.class})
SecureMasterController extends Controller -> combined with a routes file that duplicates the core routes, except everything is routed to the SecureMasterController rather than MasterController, eg:

# In the core routes:
GET     /                                       MasterController.home

# In the "secure" routes:
GET     /                                       SecureMasterController.home

Then in the SecureMasterController.home method, I'd just call MasterController.home and let it do the work now that the call was authenticated.

However, I get into an infinite redirect loop.

Is there a better way to do this, or a workaround for the infinite redirect loop?

Thanks.

Mike

Guillaume Bort

unread,
Sep 5, 2010, 1:58:52 PM9/5/10
to play-fr...@googlegroups.com
Probably because when you call the MasterController.home action Play
will issue a redirect.

Btw I think it is easier to fork the Secure module to make it
optional. Just add a test in the Before interceptor provided in the
Secure class.

> --
> You received this message because you are subscribed to the Google Groups
> "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to
> play-framewor...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/play-framework?hl=en.
>

--
Guillaume Bort, http://guillaume.bort.fr

For anything work-related, use g...@zenexity.fr; for everything else,
write guillau...@gmail.com

Mike Grove

unread,
Sep 7, 2010, 8:47:45 AM9/7/10
to play-fr...@googlegroups.com
On Sun, Sep 5, 2010 at 1:58 PM, Guillaume Bort <guillau...@gmail.com> wrote:
Probably because when you call the MasterController.home action Play
will issue a redirect.

Yes, this is exactly what happens, which was not all that surprising, but I was hoping there was some way to forward the request to another controller without having a redirect action involved. 

I've used a similar approach in the past to have controller inheritance, but the redirects were not a problem because everything was in a single module and with a single set of routes and the flow was handled correctly.  Having the same route in two modules I think is the main issue.
 

Btw I think it is easier to fork the Secure module to make it
optional. Just add a test in the Before interceptor provided in the
Secure class.

This was my last resort since I knew that would work, but I'd rather not fork the project if at all possible.

So if there's a workaround for passing a request from one controller to another without going through a redirect, that'd be great.

Cheers,

Mike
 

Bing Ran

unread,
Sep 7, 2010, 9:31:53 AM9/7/10
to play-fr...@googlegroups.com
It's a hack but if you want something q&d:
 
  play.classloading.enhancers.ControllersEnhancer.ControllerInstrumentation.initActionCall();
  AnotherController.action(...)

Mike Grove

unread,
Sep 7, 2010, 9:39:33 AM9/7/10
to play-fr...@googlegroups.com
On Tue, Sep 7, 2010 at 9:31 AM, Bing Ran <bing...@gmail.com> wrote:
It's a hack but if you want something q&d:
 
  play.classloading.enhancers.ControllersEnhancer.ControllerInstrumentation.initActionCall();

Yep, that in fact worked.  The request seems to have been passed successfully from the fronting security controller to the core controller which actually serves the content.

What does this do? And do I need to invoke stopActionCall after invoking the controller action?

Thanks for the tip!

Mike
 

Bing Ran

unread,
Sep 7, 2010, 10:25:42 AM9/7/10
to play-fr...@googlegroups.com
Sure, stopActionCall will be called automatically. So don't worry about that. These two methods basically turn on/of an internal flag to control automatic redirection.
 
Bing
Reply all
Reply to author
Forward
0 new messages