fix: 修复Token管理、代码生成模板及文档问题
This commit is contained in:
@@ -323,6 +323,7 @@ public class CodegenServiceImpl implements CodegenService {
|
||||
bindMap.put("entityKebab", entityKebab);
|
||||
bindMap.put("entityUpperSnake", entityUpperSnake);
|
||||
bindMap.put("businessName", genTable.getBusinessName());
|
||||
bindMap.put("entityComment", genTable.getBusinessName());
|
||||
bindMap.put("fieldConfigs", fieldConfigs);
|
||||
|
||||
boolean hasLocalDateTime = false;
|
||||
|
||||
@@ -168,18 +168,18 @@ public class RedisTokenManager implements TokenManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* 使访问令牌失效
|
||||
* Make access token invalid
|
||||
* <p>
|
||||
* Only deletes the current token, not all sessions for the user.
|
||||
* This ensures single-device logout doesn't affect other devices when allowMultiLogin=true.
|
||||
*
|
||||
* @param token 访问令牌
|
||||
* @param token Access token
|
||||
*/
|
||||
@Override
|
||||
public void invalidateToken(String token) {
|
||||
String cleanToken = cleanBearerPrefix(token);
|
||||
Object value = redisTemplate.opsForValue().get(formatTokenKey(cleanToken));
|
||||
if (value instanceof UserSession userSession) {
|
||||
Long userId = userSession.getUserId();
|
||||
invalidateUserSessions(userId);
|
||||
}
|
||||
// Only delete the current token, not all user sessions
|
||||
redisTemplate.delete(formatTokenKey(cleanToken));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.youlai.boot.system.model.vo.CurrentUserVO;
|
||||
import com.youlai.boot.system.model.vo.UserPageVO;
|
||||
import com.youlai.boot.system.model.vo.UserProfileVO;
|
||||
import com.youlai.boot.system.service.UserService;
|
||||
import com.youlai.boot.framework.security.token.TokenManager;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -54,6 +55,8 @@ import java.util.List;
|
||||
@RequiredArgsConstructor
|
||||
public class UserController {
|
||||
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
@Operation(summary = "用户列表")
|
||||
@@ -122,6 +125,10 @@ public class UserController {
|
||||
.eq(SysUser::getId, userId)
|
||||
.set(SysUser::getStatus, status)
|
||||
);
|
||||
// 用户禁用时立即失效其会话
|
||||
if (result && status == 0) {
|
||||
tokenManager.invalidateUserSessions(userId);
|
||||
}
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
|
||||
@@ -215,6 +215,14 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||
if (result) {
|
||||
// 刷新角色的权限缓存
|
||||
roleMenuService.refreshRolePermsCache(role.getCode());
|
||||
|
||||
// When role is disabled, invalidate sessions of all users with this role
|
||||
if (status == 0) {
|
||||
List<Long> userIds = userRoleService.listUserIdsByRoleId(roleId);
|
||||
for (Long userId : userIds) {
|
||||
tokenManager.invalidateUserSessions(userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user