Skip to content

Commit 7ecfcde

Browse files
committed
add resetToken
1 parent 1ff87ed commit 7ecfcde

File tree

14 files changed

+44
-20
lines changed

14 files changed

+44
-20
lines changed

example/example-application/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.36</version>
8+
<version>3.3.37</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-domain/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.36</version>
8+
<version>3.3.37</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-infra-flow/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.36</version>
8+
<version>3.3.37</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-infra-jpa/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.36</version>
8+
<version>3.3.37</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-server/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.36</version>
8+
<version>3.3.37</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</parent>
1818

1919
<artifactId>springboot-example</artifactId>
20-
<version>3.3.36</version>
20+
<version>3.3.37</version>
2121

2222
<name>springboot-example</name>
2323
<description>springboot-example project for Spring Boot</description>

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<groupId>com.codingapi.springboot</groupId>
1717
<artifactId>springboot-parent</artifactId>
18-
<version>3.3.36</version>
18+
<version>3.3.37</version>
1919

2020
<url>https://github.com/codingapi/springboot-framewrok</url>
2121
<name>springboot-parent</name>

springboot-starter-data-authorization/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>springboot-parent</artifactId>
9-
<version>3.3.36</version>
9+
<version>3.3.37</version>
1010
</parent>
1111

1212
<artifactId>springboot-starter-data-authorization</artifactId>

springboot-starter-data-fast/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-parent</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.36</version>
8+
<version>3.3.37</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

springboot-starter-flow/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>3.3.36</version>
9+
<version>3.3.37</version>
1010
</parent>
1111

1212
<name>springboot-starter-flow</name>

springboot-starter-security/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>3.3.36</version>
9+
<version>3.3.37</version>
1010
</parent>
1111

1212
<artifactId>springboot-starter-security</artifactId>

springboot-starter-security/src/main/java/com/codingapi/springboot/security/redis/RedisTokenGateway.java

+31-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.codingapi.springboot.security.gateway.Token;
55
import org.springframework.data.redis.core.RedisTemplate;
66

7+
import java.util.ArrayList;
78
import java.util.List;
89
import java.util.Set;
910
import java.util.UUID;
@@ -30,8 +31,14 @@ public Token create(String username, String iv, List<String> authorities, String
3031
return token;
3132
}
3233

33-
public Token parser(String sign) {
34-
String json = redisTemplate.opsForValue().get(sign);
34+
/**
35+
* 根据token获取用户信息
36+
*
37+
* @param token token
38+
* @return 用户信息
39+
*/
40+
public Token getToken(String token) {
41+
String json = redisTemplate.opsForValue().get(token);
3542
if (json == null) {
3643
return null;
3744
}
@@ -40,6 +47,7 @@ public Token parser(String sign) {
4047

4148
/**
4249
* 删除token
50+
*
4351
* @param token token
4452
*/
4553
public void removeToken(String token) {
@@ -48,33 +56,49 @@ public void removeToken(String token) {
4856

4957
/**
5058
* 重置token
59+
*
5160
* @param token token
5261
*/
53-
public void resetToken(Token token){
62+
public void resetToken(Token token) {
5463
redisTemplate.opsForValue().set(token.getToken(), token.toJson(), validTime, TimeUnit.MILLISECONDS);
5564
}
5665

5766
/**
5867
* 删除用户
68+
*
5969
* @param username 用户名
6070
*/
6171
public void removeUsername(String username) {
6272
Set<String> keys = redisTemplate.keys(username + ":*");
63-
if (keys != null && !keys.isEmpty()) {
73+
if (!keys.isEmpty()) {
6474
redisTemplate.delete(keys);
6575
}
6676
}
6777

78+
6879
/**
69-
* 自定义删除用户
80+
* 获取用户的所有token
81+
*
7082
* @param username 用户名
83+
* @return token列表
84+
*/
85+
public List<String> getTokensByUsername(String username) {
86+
Set<String> keys = redisTemplate.keys(username + ":*");
87+
return new ArrayList<>(keys);
88+
}
89+
90+
91+
/**
92+
* 自定义删除用户
93+
*
94+
* @param username 用户名
7195
* @param predicate 条件
7296
*/
7397
public void removeUsername(String username, Predicate<Token> predicate) {
7498
Set<String> keys = redisTemplate.keys(username + ":*");
75-
if (keys != null && !keys.isEmpty()) {
99+
if (!keys.isEmpty()) {
76100
for (String key : keys) {
77-
Token token = parser(key);
101+
Token token = getToken(key);
78102
if (token != null && predicate.test(token)) {
79103
redisTemplate.delete(key);
80104
}

springboot-starter-security/src/main/java/com/codingapi/springboot/security/redis/RedisTokenGatewayImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public Token create(String username, String iv, List<String> authorities, String
2020

2121
@Override
2222
public Token parser(String sign) {
23-
return redisTokenGateway.parser(sign);
23+
return redisTokenGateway.getToken(sign);
2424
}
2525

2626
}

springboot-starter/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.codingapi.springboot</groupId>
77
<artifactId>springboot-parent</artifactId>
8-
<version>3.3.36</version>
8+
<version>3.3.37</version>
99
</parent>
1010
<artifactId>springboot-starter</artifactId>
1111

0 commit comments

Comments
 (0)