Java播放! 2 - 使用Cookie的用户管理 [英] Java Play! 2 - User management with cookies
问题描述
我想透过Cookie管理我的使用者。这不是那么容易,因为没有关于这个主题的文档。
I am trying to manage my user via cookie. It's not that easy because there is absolutely no documentation about this topic.
在示例zentask的帮助下,我做了:
With the help of the sample "zentask" I made this:
session("username", filledForm.field("username").value());
public class Secured{
public static Session getSession() {
return Context.current().session();
}
public static String getUsername() {
return getSession().get("username");
}
public static boolean isAuthorized() throws Exception {
String username = getUsername();
if (username == null)
return false;
long userCount = DatabaseConnect.getInstance().getDatastore()
.createQuery(User.class).field("username").equal(username)
.countAll();
if (userCount == 1)
return true;
return false;
}
我使用它像这样:
public static Result blank() throws Exception {
if (Secured.isAuthorized())
return ok(Secured.getUsername());
else
return ok(views.html.login.form.render(loginForm));
}
现在我有几个问题/问题:
Now I have several questions/problems:
-
1。)Cookie不受保护,并且总是看起来相同。例如bdb7f592f9d54837995f816498c0474031d44c1a-username%3Akantaki
1.) Cookie is not dectypted and always looks the same. eg bdb7f592f9d54837995f816498c0474031d44c1a-username%3Akantaki
2。)Security.Authenticator类是什么?
2.) What does the class Security.Authenticator do?
3。)我认为通过cookies的用户管理是一个很常见的问题,是打!2.0给我一个完整的解决方案?或者至少有一些文档吗?
3.) I think user management through cookies is a very common problem, does play!2.0 offer me a complete solution? Or is there at least some documentation?
推荐答案
认证
和授权
- Play Authenticate 由Joscha Feth。 (可从 GitHub 获得)
There is also full stack for authentication
and authorization
- Play Authenticate by Joscha Feth. (available at GitHub)
包含准备好使用示例for Java,其使用 securesocial
+ full Deadbolt 2 (由Steve Chaloner提供)支持。它有:注册
和的可能性
It incorporates ready-to-use sample for Java, which uses concepts of securesocial
+ full Deadbolt 2 (by Steve Chaloner) support. it has:
- 多语言支持(目前:英语,德语,波兰语)
- 可自定义的模板(也可用于信息电子邮件)
- 支持
roles
code> permissions (通过 Deadbolt 2 ) - 密码恢复支持
<
- built in possibility to
register
andlog in
users with e-mail, Google, Facebook, Foursquare, Twitter, OpenId and custom providers. - Multilanguage support (currently: English, German, Polish)
- Customisable templates (also for informational e-mails)
- Support for
roles
andpermissions
(via Deadbolt 2) - Password recovery support
有Java的示例应用程序。您可以将它合并到您的应用程式。
There is sample app for Java in it. You can incorporate it to your app.
这篇关于Java播放! 2 - 使用Cookie的用户管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!