我正在开发 Restful Web Service using Jersey在我的 Android, iPhone
之间应用程序和 MySQL。我也用 Hibernate
将数据映射到数据库。
我有一个 sessionId( key )。它是在用户登录系统时生成的。
在 User
类(class):
public Session daoCreateSession() {
if (session == null) {
session = new Session(this);
} else {
session.daoUpdate();
}
return session;
}
在 Session
类(class):Session(User user) {
this.key = UUID.randomUUID().toString();
this.user = user;
this.date = new Date();
}
void daoUpdate() {
this.key = UUID.randomUUID().toString();
this.date = new Date();
}
当用户成功登录系统时,我将此 sessionId 发送到移动应用客户端。然后当我想根据登录用户从数据库中获取一些信息时,我检查了这个 Session key作为身份验证 in the REST Services
对于每个请求。例如用户参与的项目列表,我使用
client.GET(SERVER_ADDRESS/project/get/{SessionID})
client.GET(SERVER_ADDRESS/project/get/{username})
的插图.如果它不是有效的 session key ,我会将 403 禁止代码发送回客户端。
你也可以看看here
问题是我不确定我的方法。你怎么看
cons
在考虑 Jersey 和移动应用程序的这种方法中?我还是不知道
Session key
就我而言,方法是个好主意。
最佳答案
如果你想使用 SessionId 那么它应该有一个验证时间,像这样:
private static final int MINUTES = 90;
public boolean isValid() {
return System.currentTimeMillis() - date.getTime() < 1000 * 60 * MINUTES;
}
关于spring - 使用 Jersey 的 RESTful Web 服务的 session 管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12150076/