【发布时间】:2015-09-17 00:03:03
【问题描述】:
我正在使用mysql 数据库和tomcat 服务器处理Spring 4 mvc 应用程序。
基本上,我正在创建一个 Spring rest 将被 Angular JS 使用。
注意:我没有使用Spring security
为了避免在clustered environment的情况下进行会话复制,我使用cookie方法。登录时,我正在生成one unique session id(using java UUID)并使用它创建一个cookie然后设置响应中的 cookie。此外,将该会话 ID 与任何用户数据一起存储在数据库中。
为了验证每个 REST API,我编写了一个 Spring interceptor,它将拦截每个 REST API 调用,进而检查请求中是否有 cookie。如果存在,我正在获取会话 id 值和使用它,进行数据库调用以检查它是否有效。注销时,我正在删除 cookie。
根据我上面的解释,我有几个问题:
1) Is my approach correct? or do you see any flaw in it.
2) Let me know if there is any other better method to achieve the same i.e. to avoid session replication.
3) Since, I am not using any HTTP session, how do I achieve something like session-timeout or do i even need it?
【问题讨论】:
标签: java session cookies spring-restcontroller spring-rest