-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedisTokenManager.java
More file actions
49 lines (41 loc) · 1.24 KB
/
RedisTokenManager.java
File metadata and controls
49 lines (41 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.scity.pms.auth.infrastructure.token;
import com.scity.pms.auth.domain.login.LoginContext;
import com.scity.pms.auth.domain.login.LoginedUserResource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
/**
* {@code RedisTokenManager}
* Token manager, base on redis.
*
* @author Jackie Leung
* @version 1.0
* @since 1.0
*/
@Service("redisTokenManager")
public class RedisTokenManager implements TokenManager {
@Resource
private RedisTemplate<String, LoginedUserResource> redisTemplate;
@Override
public void put(LoginContext loginContext) {
redisTemplate.opsForValue().set(
loginContext.getKey(),
loginContext.getUserSource(),
loginContext.getCacheTime(),
TimeUnit.SECONDS
);
}
@Override
public void remove(String token) {
redisTemplate.delete(token);
}
@Override
public boolean verifyToken(String token) {
return redisTemplate.hasKey(token);
}
@Override
public LoginedUserResource userSources(String token) {
return redisTemplate.opsForValue().get(token);
}
}