Playframework Protected module does not redirect to source URL after login

Edited by:

I am running Ubuntu 10.04 and this problem occurs in Chrome (7.0.517.44), however everything works fine in Firefox.

It is very strange. I have another application in which redirectToOriginalUrl works fine in the "dev" mode in both browsers, but does not work in the "prod" mode (again in both browsers). Wow, I have no idea what is going on!

Problem:

I get the strangest error in Playframework (version 1.1.1), where redirectToOriginalURL does not work in the Secure module.

I have 2 Application.java controllers and NameC.java

The Application / index.html view displays a simple page with an action link in NameC.java (NameC.index ())

NameC.java is protected by @With annotation (Secure.class)

Here is the stream I expect. First, the user goes to the application home page. There they click on the link that will lead them to NameC.index. However, since NameC is protected by the Secure module, the user must be delivered to the login form (since they have not logged in yet), and after successful login, they should see the page presented by NameC.index

I get a registration form, but after a successful login, the user goes to Application.index. I tried putting the print expression in the Secure.redirectToOriginalURL () method, and it looks like the “url” does not exist in the flash area.

Here is my code:

Application.java

public class Application extends Controller { public static void index() { render(); } } 

Application /index.html

 <a href="@{NameC.index()}">Click here</a> 

NameC.java

 @With(Secure.class) public class NameC extends Controller { public static void index() { render(); } } 

HINT /index.html

 You should see this after a successful login. <a href="@{Secure.logout()}">logout</a> 

I am sure that I am missing something very simple ... can someone please help me figure out what I am missing.

0
source share
2 answers

The original URL must be stored in the flash area inside the login function. If you are using an unmodified version of the Secure module, there should be a line of code, for example:

 flash.keep("url"); 

Data stored in the flash area is available only for the next request, and then cleared. The contents of the flash memory area are not stored on the server, but in a cookie, so you should see a cookie called PLAY_FLASH containing the source URL if you examine the request using Firebug or similar. If for some reason there is no cookie, there is your problem.

Then your authenticate function should (after successful authentication) call the redirectToOriginalURL method, which tries to extract the original URL from the flash area (as you said) as follows:

 String url = flash.get("url"); 

If the URL is no longer available in the flash area, the most likely explanation is that between the login and authenticate requests, another request is executed to clear the stored value from the flash area. Again, Firebug will be easy to identify if this is the reason - just take a look at the Net tab to see all network traffic.

+3
source

redirectTo uses status 301. It should not work differently in any browser, but still. It can happen ...

0
source

Source: https://habr.com/ru/post/913563/


All Articles