提交 | 用户 | 时间
|
1ac2bc
|
1 |
package cn.stylefeng.guns.sys.core.auth.cache.impl; |
懒 |
2 |
|
|
3 |
import cn.stylefeng.guns.base.auth.model.LoginUser; |
|
4 |
import cn.stylefeng.guns.sys.core.auth.cache.SessionManager; |
|
5 |
import org.springframework.stereotype.Component; |
|
6 |
|
|
7 |
import java.util.Map; |
|
8 |
import java.util.concurrent.ConcurrentHashMap; |
|
9 |
|
|
10 |
/** |
|
11 |
* 基于内存的会话管理 |
|
12 |
* |
|
13 |
* @author fengshuonan |
|
14 |
* @date 2019-09-28-14:43 |
|
15 |
*/ |
|
16 |
@Component |
|
17 |
public class DefaultSessionManager implements SessionManager { |
|
18 |
|
|
19 |
private Map<String, LoginUser> caches = new ConcurrentHashMap<>(); |
|
20 |
|
|
21 |
@Override |
|
22 |
public void createSession(String token, LoginUser loginUser) { |
|
23 |
caches.put(SESSION_PREFIX + token, loginUser); |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
public LoginUser getSession(String token) { |
|
28 |
return caches.get(SESSION_PREFIX + token); |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
public void removeSession(String token) { |
|
33 |
caches.remove(SESSION_PREFIX + token); |
|
34 |
} |
|
35 |
|
|
36 |
@Override |
|
37 |
public boolean haveSession(String token) { |
|
38 |
return caches.containsKey(SESSION_PREFIX + token); |
|
39 |
} |
|
40 |
} |