Skip to content

Commit 949bbb4

Browse files
committed
feat(auth): add refresh token module
Assisted-by: Codex
1 parent cbd7aad commit 949bbb4

98 files changed

Lines changed: 5763 additions & 351 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

continew-auth-refresh/pom.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>top.continew.admin</groupId>
8+
<artifactId>continew-admin</artifactId>
9+
<version>${revision}</version>
10+
</parent>
11+
12+
<artifactId>continew-auth-refresh</artifactId>
13+
<packaging>jar</packaging>
14+
15+
<name>${project.artifactId}</name>
16+
<description>认证会话模块(Refresh Token、会话轮换和 Access Token 绑定)</description>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>${project.groupId}</groupId>
21+
<artifactId>continew-common</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-aop</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-test</artifactId>
30+
<scope>test</scope>
31+
</dependency>
32+
</dependencies>
33+
</project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package top.continew.admin.auth.api;
18+
19+
/** 校验 Access Token 是否仍绑定有效认证会话。 */
20+
public interface AccessSessionValidator {
21+
22+
boolean isInvalid(String accessToken);
23+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package top.continew.admin.auth.api;
18+
19+
/**
20+
* 认证会话安全策略锁的目标。
21+
*
22+
* @author luoqiz
23+
*/
24+
public record AuthPolicyLockTarget(Type type, String key) {
25+
26+
public static AuthPolicyLockTarget client(String clientId) {
27+
return new AuthPolicyLockTarget(Type.CLIENT, clientId);
28+
}
29+
30+
public static AuthPolicyLockTarget tenant(Long tenantId) {
31+
return new AuthPolicyLockTarget(Type.TENANT, String.valueOf(tenantId));
32+
}
33+
34+
public static AuthPolicyLockTarget user(Long userId) {
35+
return new AuthPolicyLockTarget(Type.USER, String.valueOf(userId));
36+
}
37+
38+
public enum Type {
39+
USER,
40+
TENANT,
41+
CLIENT
42+
}
43+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package top.continew.admin.auth.api;
18+
19+
import java.util.Collection;
20+
21+
/**
22+
* 将业务方法参数解析为认证会话策略锁目标。
23+
*
24+
* <p>实现由 system 或 tenant 插件提供,认证会话模块不引用任何业务 Mapper。</p>
25+
*
26+
* @author luoqiz
27+
*/
28+
public interface AuthPolicyLockTargetResolver {
29+
30+
Collection<AuthPolicyLockTarget> resolve(Object[] args);
31+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package top.continew.admin.auth.api;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
/**
25+
* 在数据库事务开始前获取认证策略写锁。
26+
*
27+
* <p>标记会改变登录资格或会话策略的项目业务方法,统一约束分布式锁与数据库事务的
28+
* 顺序,避免登录/刷新路径的“Redis 锁→数据库”与管理路径的“数据库→Redis 锁”互锁。</p>
29+
*
30+
* @author luoqiz
31+
*/
32+
@Target(ElementType.METHOD)
33+
@Retention(RetentionPolicy.RUNTIME)
34+
public @interface AuthPolicyWriteLocked {
35+
36+
/** 由业务模块实现的锁目标解析器。 */
37+
Class<? extends AuthPolicyLockTargetResolver> value();
38+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package top.continew.admin.auth.api;
18+
19+
/**
20+
* 认证会话常量。
21+
*
22+
* @author luoqiz
23+
*/
24+
public final class AuthSessionConstants {
25+
26+
/** Access Token 中绑定 Refresh Session ID 的声明名称。 */
27+
public static final String SESSION_ID_CLAIM = "sid";
28+
29+
private AuthSessionConstants() {
30+
}
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package top.continew.admin.auth.api;
18+
19+
/**
20+
* 认证会话撤销通知器。
21+
*
22+
* @author luoqiz
23+
*/
24+
public interface AuthSessionRevocationNotifier {
25+
26+
/**
27+
* 通知所有实时连接撤销指定登录会话。
28+
*
29+
* @param sessionId Refresh Session ID
30+
*/
31+
void notifyRevoked(String sessionId);
32+
}

0 commit comments

Comments
 (0)