Mai*_*ein 6 java cookies playframework playframework-2.0
我试图通过cookie管理我的用户.这并不容易,因为绝对没有关于这个主题的文档.
在样本"zentask"的帮助下,我做了这个:
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;
}
Run Code Online (Sandbox Code Playgroud)
我这样使用它:
public static Result blank() throws Exception {
if (Secured.isAuthorized())
return ok(Secured.getUsername());
else
return ok(views.html.login.form.render(loginForm));
}
Run Code Online (Sandbox Code Playgroud)
现在我有几个问题/问题:
1.)Cookie不是dectypted,看起来总是一样.例如bdb7f592f9d54837995f816498c0474031d44c1a-username%3Akantaki
2.)Security.Authenticator类有什么作用?
3.)我认为通过cookie进行用户管理是一个非常普遍的问题,确实可以玩!2.0为我提供了完整的解决方案吗?或者至少有一些文件?
bie*_*ior 12
还有完整的堆栈authentication和authorization- Joscha Feth的Play Authenticate.(可在GitHub获得)
它结合了Java的即用型样本,它使用了securesocial+ Full Deadbolt 2(由Steve Chaloner)支持的概念.它有:
register和log in用户.roles和permissions(通过Deadbolt 2)其中有Java示例应用程序.您可以将其合并到您的应用中.
| 归档时间: |
|
| 查看次数: |
7808 次 |
| 最近记录: |