登录后,Playframework的安全模块未重定向到原始网址 [英] Playframework's Secure module is not redirecting to the original url after login

查看:88
本文介绍了登录后,Playframework的安全模块未重定向到原始网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行Ubuntu 10.04,Chrome(7.0.517.44)上似乎出现了此问题,但是,在Firefox上一切正常.

这非常奇怪.我有另一个应用程序,其中redirectToOriginalUrl在两个浏览器的开发"模式下均能正常工作,但在生产"模式下(同样在两个浏览器上)均无法工作.哇,我不知道发生了什么!

问题:

我在Playframework(版本1.1.1)中遇到了最奇怪的错误,其中redirectToOriginalURL在安全"模块中不起作用.

I am getting the strangest error with Playframework (version 1.1.1), where the redirectToOriginalURL is not working in the Secure module.

我有2个控制器Application.java和NameC.java

I have 2 controllers Application.java and NameC.java

视图Application/index.html显示一个简单页面,其中包含指向NameC.java(NameC.index())中的动作的链接

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

NameC.java使用@With(Secure.class)注释进行保护

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

这是我期望的流程.首先,用户进入应用程序主页.他们在那里单击链接,将其带到NameC.index.但是,由于NameC受安全模块保护,因此应该将用户带到登录表单(因为他们尚未登录),并且在成功登录后,他们应该看到NameC.index呈现的页面

Here is the flow I am expecting. First the user goes to the application home page. There they click on the link which would take them to NameC.index. However, since NameC is protected with the Secure module, the user should be taken to the login form (since they are not yet logged in), and upon successful login, they should see the page rendered by NameC.index

我获得了登录表单,但是成功登录后,用户被带到Application.index,我尝试将打印语句放入Secure.redirectToOriginalURL()方法中,并且好像"url"在Flash作用域中不存在

I get the login form, but upon successful login, the user is taken to Application.index I tried putting a print statement in Secure.redirectToOriginalURL() method, and it seems like the "url" does not exist in flash scope.

这是我的代码:

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();
    }
}

NameC/index.html

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

我确信我缺少一些非常基本的东西.有人可以帮我弄清楚我所缺少的东西吗.

I am sure I am missing something very basic... can anyone please help me figure out what I am missing.

推荐答案

原始URL应该存储在login函数内的Flash作用域中.如果您运行的是安全模块的未修改版本,则应该有如下代码行:

The original URL should be stored in the flash scope within the login function. If you are running an unmodified version of the Secure module, there should be a line of code like this:

flash.keep("url");

存储在闪存作用域中的数据仅可用于下一个请求,然后将其清除. Flash作用域的内容未存储在服务器中,而是存储在cookie中,因此,如果您也使用Firebug或类似工具调查请求,则应该能够看到一个名为PLAY_FLASH的cookie,其中包含原始URL.如果由于某种原因不存在Cookie,则说明您有问题.

Data stored in flash scope is only available for the next request, then it is cleared. Contents of the flash scope are not stored in the server but in a cookie, so you should be able to see a cookie named PLAY_FLASH containing your original URL if you investigate the request with Firebug or similar too. If, for some reason, the cookie is not present, there is your problem.

接下来,您的authenticate函数应(在成功通过身份验证后)调用redirectToOriginalURL方法,该方法尝试从Flash作用域(如您所说的)中检索原始URL,如下所示:

Next, your authenticate function should (upon successful authentication) call the redirectToOriginalURL method which tries to retrieve the original URL from the flash scope (as you said) like this:

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

如果URL在Flash作用域中不再可用,则最可能的解释是在loginauthenticate请求之间提出了另一个请求,从而从Flash作用域中清除了存储的值.再次,Firebug会很容易地揭示这是否是原因-只需查看网络"标签即可查看正在发生的所有网络流量.

If the URL is no longer available in the flash scope, most likely explanation is that another request has been made in between the login and authenticate requests, clearing the stored value from the flash scope. Again, Firebug will easily reveal if this is the reason - just have a look at the Net tab to see all network traffic taking place.

这篇关于登录后,Playframework的安全模块未重定向到原始网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆