0
A
回答
2
感谢大家对这个问题的意见,用Johan Sjöberg
的建议,甚至stackoverflow
正在使用它;-),检查注销链接。
在模板
<a href="@{Secure.logout2(request.url)}">logout</a>
在Secure.java
我加入logout2
public static void logout2(String returnUrl) throws Throwable {
flash.put("returnUrl", returnUrl == null ? "/" : returnUrl);
logout();
}
和修改logout
public static void logout() throws Throwable {
session.clear();
response.removeCookie("rememberme");
Security.invoke("onDisconnected");
flash.success(Messages.get("secure.logout", "You have been successfully logged out"));
String returnUrl = flash.get("returnUrl");
redirect(returnUrl == null ? "/" : returnUrl);
}
8
(只是阐明allenskd的评论)
很大程度上取决于你的注销是如何实现的,但是如果它只是一个控制器或一个jsp,你不必将url传递给它。您可以使用referer标题。
String refererUrl = request.getHeader("referer")
2
已经找到其他的答案在这里不可接受(或只是不太符合我的方法),我ping通-距离,直到我来到了我喜欢的东西更好。下面是我所做的:
public class Security extends Secure.Security {
/* Overrides the same method from Secure.Security.
* I only needed to redirect back the home-page so I just
* hard-coded the redirect-url here; but you could also have
* directed your logout-link to #logout2(String url) where you do a
* flash#put() and then here do a flash#get() and redirect to
* to that url instead (see n002213f's answer for more detail;
* but I thought it bad-practice to do the other half of his
* answer -- directly modifying the #logout() method of the
* play#secure-module)
static void onDisconnected() {
redirect("/");
}
}
index.html:
(...) <a href="logout">Logout</a> (...)
所以这里所发生的是默认的播放#安全#注销()被调用,并在退出过程结束它触发安全#安全#onDisconnected - 这是覆盖并重定向到主页。这种方式发挥自己的内置安全性没有被绕过,所以你没有冒险打破你的安全性,你也不是直接修改play#secure-module代码,这意味着它在更新时不会发现自己处于泡菜,但你正在实现你的结果:没有被重定向到默认的播放#安全登录页面,而是直接回到主页。
如果有人使用Play更经验丰富!比我看到这个问题(或者如果我对其他解决方案的批评是没有根据的),我很乐意听到!
否则我认为这是实现目标的最优雅和最简单的方法。
相关问题
- 1. 注销重定向
- 2. cakephp注销重定向
- 3. ASP.Net LoginStatus注销重定向
- 4. Laravel 5.4注销重定向
- 5. 注销后Django重定向
- 6. 注销重定向错误
- 7. CXF关注重定向的网址
- 8. 无法重定向到注销页面
- 9. 为什么重定向到https注销?
- 10. 注销重定向到错误页面
- 11. 春季安全:重定向到URL以前注销
- 12. Google App Engine注销网址
- 13. 要停止一个重定向当登录网址结尾注销?下一= /帐号/注销/ Django中
- 14. 如何关注Google的“我感到幸运”重定向网址?
- 15. 将家庭网址重定向到网址+定位点
- 16. 重定向内置注销视图Django的全成注销
- 17. 注销时重定向并显示“您已成功注销!”
- 18. Facebook的注销按钮和重定向注销
- 19. 注销后删除头部位置重定向?q =注销
- 20. 重定向到j2me中的网址
- 21. RedirectPermanent未重定向到网址
- 22. 301重定向到更改的网址
- 23. 重定向非www到www网址
- 24. 重定向到包含网址,RedirectView的
- 25. 重定向到另一个网址
- 26. Ajax PHP重定向到一个网址
- 27. htaccess重定向非www到www网址
- 28. 防止重定向到根网址
- 29. Codeigniter htaccess重定向不重定向到所需的网址
- 30. 将表单重定向到当前浏览器网址(ATG)
您有需要注销的页面吗?那么,正如你所说的,让这些页面为请求添加一个url参数,并将其用于重定向。 – 2011-02-06 12:21:16
您还可以通过flash-javascipt桥将该URL存储在cookie中。 – kirilloid 2011-02-06 12:24:51