相关疑难解决方法(0)

Java Play!2 - 使用cookie进行用户管理

我试图通过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为我提供了完整的解决方案吗?或者至少有一些文件?

java cookies playframework playframework-2.0

6
推荐指数
2
解决办法
7808
查看次数

标签 统计

cookies ×1

java ×1

playframework ×1

playframework-2.0 ×1