-
Notifications
You must be signed in to change notification settings - Fork 442
feat(system/client): 添加双token认证配置 #212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| -- liquibase formatted sql | ||
|
|
||
| -- changeset luoqiz:4.2.0-1 | ||
| -- comment sys_client 客户端表更新 | ||
| -- sys_client 添加双token列 | ||
| ALTER TABLE `sys_client` | ||
| ADD COLUMN `is_enable_refresh_token` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否启用refresh token (true: 启用; false: 禁用)' AFTER `timeout`, | ||
| ADD COLUMN `refresh_token_timeout` bigint NULL DEFAULT 2592000 COMMENT 'Refresh token有效期(单位:秒; 值必须大于0,否则取token的有效时长)' AFTER `is_enable_refresh_token`; | ||
|
|
||
| -- 初始化客户端数据 | ||
| INSERT INTO `sys_client` | ||
| (`id`, `client_id`, `client_type`, `auth_type`, `active_timeout`, `timeout`, `status`, `create_user`, `create_time`, | ||
| `is_enable_refresh_token`, `refresh_token_timeout`) | ||
| VALUES (2, 'ef51c9a3e9046c4f2ea45142c8a8344b', 'XCX', '["ACCOUNT", "EMAIL", "PHONE", "SOCIAL"]', 1800, 86400, 1, 1, | ||
| NOW(), b'1', 2592000); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| -- liquibase formatted sql | ||
|
|
||
| -- changeset luoqiz:4.2.0-1 | ||
| -- comment sys_client 客户端表更新 | ||
| -- sys_client 添加双token列 | ||
| ALTER TABLE "public"."sys_client" | ||
| ADD COLUMN "is_enable_refresh_token" bool NOT NULL DEFAULT false, | ||
| ADD COLUMN "refresh_token_timeout" int8 DEFAULT 2592000; | ||
|
|
||
| COMMENT | ||
| ON COLUMN "public"."sys_client"."is_enable_refresh_token" IS '是否启用refresh token (true: 启用; false: 禁用)'; | ||
|
|
||
| COMMENT | ||
| ON COLUMN "public"."sys_client"."refresh_token_timeout" IS 'Refresh token有效期(单位:秒; 值必须大于0,否则取token的有效时长)'; | ||
|
|
||
| -- 初始化客户端数据 | ||
| INSERT INTO "sys_client" | ||
| ("id", "client_id", "client_type", "auth_type", "active_timeout", "timeout", "status", "create_user", "create_time", | ||
| "is_enable_refresh_token", "refresh_token_timeout") | ||
| VALUES (2, 'ef51c9a3e9046c4f2ea45142c8a8344b', 'XCX', '["ACCOUNT", "EMAIL", "PHONE", "SOCIAL"]', 1800, 86400, 1, 1, | ||
| NOW(), true, 2592000); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,6 @@ | |
|
|
||
| package top.continew.admin.auth; | ||
|
|
||
| import cn.dev33.satoken.stp.StpUtil; | ||
| import cn.dev33.satoken.stp.parameter.SaLoginParameter; | ||
| import cn.dev33.satoken.stp.parameter.enums.SaLogoutMode; | ||
| import cn.dev33.satoken.stp.parameter.enums.SaReplacedRange; | ||
|
|
@@ -25,6 +24,7 @@ | |
| import jakarta.servlet.http.HttpServletRequest; | ||
| import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
| import org.springframework.stereotype.Component; | ||
| import top.continew.admin.auth.constant.AuthConstants; | ||
| import top.continew.admin.auth.model.req.LoginReq; | ||
| import top.continew.admin.auth.model.resp.LoginResp; | ||
| import top.continew.admin.common.context.RoleContext; | ||
|
|
@@ -46,6 +46,7 @@ | |
| import top.continew.starter.extension.tenant.util.TenantUtils; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
|
|
@@ -136,13 +137,11 @@ protected LoginResp authenticate(UserDO user, ClientResp client) { | |
| userContext.setClientId(client.getClientId()); | ||
| userContext.setTenantId(tenantId); | ||
| // 登录并缓存用户信息 | ||
| StpUtil.login(userContext.getId(), loginParameter.setExtraData(BeanUtil | ||
| .beanToMap(new UserExtraContext(ServletUtils.getRequest())))); | ||
| Map<String, Object> extraData = BeanUtil.beanToMap(new UserExtraContext(ServletUtils.getRequest())); | ||
| extraData.put(AuthConstants.LOGIN_USER, userContext); | ||
| loginParameter.setExtraData(extraData); | ||
| UserContextHolder.setContext(userContext); | ||
| return LoginResp.builder() | ||
| .token(StpUtil.getTokenValue()) | ||
| .tenantId(TenantContextHolder.isTenantEnabled() ? TenantContextHolder.getTenantId() : null) | ||
| .build(); | ||
| return LoginHandler.buildLoginResp(loginParameter, userContext, client); | ||
|
Comment on lines
+140
to
+144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# 确认 Sa-Token 的序列化器配置,判断 getExtra 取出的实际类型
rg -nP --type=java -C3 'SaJsonTemplate|SaSerializerTemplate|sa-token.*serializer'
rg -nP --type=yaml -C3 'sa-token|satoken'Repository: continew-org/continew-admin Length of output: 3762 🏁 Script executed: # Find AuthServiceImpl and check refreshToken method
fd -type f -name "AuthServiceImpl.java" | head -5Repository: continew-org/continew-admin Length of output: 242 🏁 Script executed: # Find UserContext class definition
fd -type f -name "UserContext.java" | head -5Repository: continew-org/continew-admin Length of output: 242 🏁 Script executed: # Check Sa-Token version and serializer configuration in pom.xml
rg -nP --type=xml 'sa-token|satoken' | head -20Repository: continew-org/continew-admin Length of output: 343 🏁 Script executed: # Check for Sa-Token serializer configuration in Java code
rg -nP --type=java 'SaSerializerTemplate|SaJsonTemplate|setJsonSerializer|parseToken' | head -20Repository: continew-org/continew-admin Length of output: 446 🏁 Script executed: # Look for refreshToken implementation and the cast operation
rg -nP --type=java -A5 'refreshToken.*LoginParameter' | head -30Repository: continew-org/continew-admin Length of output: 53 🏁 Script executed: # Read AuthServiceImpl.java around line 136-142 for refreshToken
find . -name "AuthServiceImpl.java" -exec cat -n {} \; | sed -n '130,150p'Repository: continew-org/continew-admin Length of output: 1157 🏁 Script executed: # Find UserContext class
find . -name "UserContext.java" -exec cat -n {} \;Repository: continew-org/continew-admin Length of output: 4868 🏁 Script executed: # Find UserExtraContext class
find . -name "UserExtraContext.java" -exec cat -n {} \;Repository: continew-org/continew-admin Length of output: 2618 🏁 Script executed: # Check Sa-Token dependency version and check for serializer configuration
cat continew-common/pom.xml | grep -A2 -B2 "sa-token"Repository: continew-org/continew-admin Length of output: 249 🏁 Script executed: # Look for AbstractLoginHandler.java to verify lines 140-144
find . -name "AbstractLoginHandler.java" -exec cat -n {} \;Repository: continew-org/continew-admin Length of output: 7798 🏁 Script executed: # Find SaTempUtil or check for custom Sa-Token serializer configuration
find . -name "*SaTempUtil*" -o -name "*satoken*" -type f | grep -i java | head -10Repository: continew-org/continew-admin Length of output: 53 🏁 Script executed: # Search for Sa-Token configuration/customization in the starter package
find . -path "*/continew-starter-auth-satoken/*" -name "*.java" | head -20Repository: continew-org/continew-admin Length of output: 53 🏁 Script executed: # Check if there's any custom JSON deserialization for LoginParameter
rg -nP --type=java "JsonDeserializer|@JsonDeserialize|readValue.*SaLoginParameter" | head -20Repository: continew-org/continew-admin Length of output: 53 🏁 Script executed: # Check continew pom.xml for sa-token version specification
find . -name "pom.xml" -exec grep -l "sa-token" {} \; | xargs grep -A5 "sa-token"Repository: continew-org/continew-admin Length of output: 325
代码在 此外,将完整的 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package top.continew.admin.auth.model.resp; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import lombok.Data; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.experimental.SuperBuilder; | ||
|
|
||
| /** | ||
| * 双token模式 | ||
| */ | ||
| @Data | ||
| @SuperBuilder | ||
| @EqualsAndHashCode(callSuper = true) | ||
| public class DoubleTokenLoginResp extends LoginResp { | ||
|
|
||
| /** | ||
| * 访问令牌 | ||
| */ | ||
| @Schema(description = "访问令牌", example = "eyJ0eXAiOiJlV1QiLCJhbGciqiJIUzI1NiJ9.eyJsb2dpblR5cGUiOiJsb29pbiIsImxvZ2luSWQiOjEsInJuU3RyIjoiSjd4SUljYnU5cmNwU09vQ3Uyc1ND1BYYTYycFRjcjAifQ.KUPOYm-2wfuLUSfEEAbpGE527fzmkAJG7sMNcQ0pUZ8") | ||
| private String accessToken; | ||
|
|
||
| /** | ||
| * 刷新令牌 | ||
| */ | ||
| @Schema(description = "刷新令牌", example = "12a5c5e1f87d4b4db614c6229c2c8916") | ||
| private String refreshToken; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * 访问令牌有效时长(秒) | ||
| */ | ||
| @Schema(description = "访问令牌有效时长(秒)", example = "1800") | ||
| private Long accessExpiresIn; | ||
|
|
||
| /** | ||
| * 刷新令牌有效时长(秒) | ||
| */ | ||
| @Schema(description = "刷新令牌有效时长(秒)", example = "2592000") | ||
| private Long refreshExpiresIn; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package top.continew.admin.auth.model.resp; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import lombok.Data; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.experimental.SuperBuilder; | ||
|
|
||
| /** | ||
| * 单token模式,只有访问的token | ||
| */ | ||
| @Data | ||
| @SuperBuilder | ||
| @EqualsAndHashCode(callSuper = true) | ||
| public class SingleTokenLoginResp extends LoginResp { | ||
|
|
||
| /** | ||
| * 访问令牌 | ||
| */ | ||
| @Schema(description = "访问令牌", example = "eyJ0eXAiOiJlV1QiLCJhbGciqiJIUzI1NiJ9.eyJsb2dpblR5cGUiOiJsb29pbiIsImxvZ2luSWQiOjEsInJuU3RyIjoiSjd4SUljYnU5cmNwU09vQ3Uyc1ND1BYYTYycFRjcjAifQ.KUPOYm-2wfuLUSfEEAbpGE527fzmkAJG7sMNcQ0pUZ8") | ||
| private String token; | ||
|
|
||
| /** | ||
| * 有效时长(秒) | ||
| */ | ||
| @Schema(description = "有效时长(秒)", example = "8600") | ||
| private Long expiresIn; | ||
|
|
||
| } | ||
|
luoqiz marked this conversation as resolved.
|
||
Uh oh!
There was an error while loading. Please reload this page.