From 0f263826b92f43b4595f02eb870334b1b1ac653a Mon Sep 17 00:00:00 2001 From: Zzm0809 <934230207@qq.com> Date: Tue, 30 Jan 2024 12:19:31 +0800 Subject: [PATCH 1/9] fix-token-error --- .../java/org/dinky/data/result/Result.java | 4 ++ .../dinky/interceptor/TenantInterceptor.java | 40 ++++++++++--------- .../dinky/service/impl/UserServiceImpl.java | 2 +- .../src/main/resources/application.yml | 20 ++-------- .../resources/i18n/messages_en_US.properties | 2 +- .../resources/i18n/messages_zh_CN.properties | 2 +- 6 files changed, 33 insertions(+), 37 deletions(-) diff --git a/dinky-admin/src/main/java/org/dinky/data/result/Result.java b/dinky-admin/src/main/java/org/dinky/data/result/Result.java index 97b6239874..e083e9a293 100644 --- a/dinky-admin/src/main/java/org/dinky/data/result/Result.java +++ b/dinky-admin/src/main/java/org/dinky/data/result/Result.java @@ -203,6 +203,10 @@ public static Result authorizeFailed(Status status) { return of(null, CodeEnum.AUTHORIZE_ERROR.getCode(), status.getMessage()); } + public static Result authorizeFailed(Status status, Object... args) { + return of(null, CodeEnum.AUTHORIZE_ERROR.getCode(), MessageFormat.format(status.getMessage(), args)); + } + public static Result authorizeFailed(String msg) { return of(null, CodeEnum.AUTHORIZE_ERROR.getCode(), msg); } diff --git a/dinky-admin/src/main/java/org/dinky/interceptor/TenantInterceptor.java b/dinky-admin/src/main/java/org/dinky/interceptor/TenantInterceptor.java index 427166721a..3386920c72 100644 --- a/dinky-admin/src/main/java/org/dinky/interceptor/TenantInterceptor.java +++ b/dinky-admin/src/main/java/org/dinky/interceptor/TenantInterceptor.java @@ -19,31 +19,30 @@ package org.dinky.interceptor; -import org.dinky.assertion.Asserts; -import org.dinky.context.TenantContextHolder; -import org.dinky.context.UserInfoContextHolder; -import org.dinky.data.dto.UserDTO; -import org.dinky.data.model.rbac.Tenant; - -import org.apache.commons.collections4.CollectionUtils; - +import cn.dev33.satoken.SaManager; +import cn.dev33.satoken.dao.SaTokenDao; +import cn.dev33.satoken.stp.StpLogic; +import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.lang.Opt; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; - import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.dinky.assertion.Asserts; +import org.dinky.context.TenantContextHolder; +import org.dinky.context.UserInfoContextHolder; +import org.dinky.data.dto.UserDTO; +import org.dinky.data.model.rbac.Tenant; import org.jetbrains.annotations.NotNull; import org.springframework.web.servlet.AsyncHandlerInterceptor; -import cn.dev33.satoken.SaManager; -import cn.dev33.satoken.stp.StpUtil; -import cn.hutool.core.lang.Opt; -import lombok.extern.slf4j.Slf4j; - -/** tenant interceptor */ +/** + * tenant interceptor + */ @Slf4j public class TenantInterceptor implements AsyncHandlerInterceptor { @@ -56,13 +55,18 @@ public boolean preHandle(HttpServletRequest request, @NotNull HttpServletRespons if (Asserts.isNotNull(cookies)) { for (Cookie cookie : cookies) { switch (cookie.getName()) { - case "satoken": + case "token": token = Opt.ofBlankAble(cookie.getValue()); - if (SaManager.getSaTokenDao().get("satoken:login:token:" + token.get()) != null) { + SaTokenDao saTokenDao = SaManager.getSaTokenDao(); + String keyTokenValue = StpUtil.getStpLogic().splicingKeyTokenValue(token.get()); + if (saTokenDao.get(keyTokenValue) != null) { isPass = true; } break; case "tenantId": + if (!StpUtil.isLogin()){ + return false; + } UserDTO userInfo = UserInfoContextHolder.get(StpUtil.getLoginIdAsInt()); if (Asserts.isNull(userInfo)) { StpUtil.logout(StpUtil.getLoginIdAsInt()); diff --git a/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java index 70ba9d97b9..5f8eaa356f 100644 --- a/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java @@ -180,7 +180,7 @@ public Result loginUser(LoginDTO loginDTO) { user = loginDTO.isLdapLogin() ? ldapLogin(loginDTO) : localLogin(loginDTO); } catch (AuthException e) { // Handle authentication exceptions and return the corresponding error status - return Result.authorizeFailed(e.getStatus() + e.getMessage()); + return Result.authorizeFailed(Status.USER_NOT_EXIST,loginDTO.getUsername()); } // Check if the user is enabled diff --git a/dinky-admin/src/main/resources/application.yml b/dinky-admin/src/main/resources/application.yml index 21e68271f8..dac1afe9d8 100644 --- a/dinky-admin/src/main/resources/application.yml +++ b/dinky-admin/src/main/resources/application.yml @@ -44,22 +44,9 @@ spring: max-file-size: 524288000 max-request-size: 524288000 - - # By default, memory cache metadata information is used, - # dinky supports redis cache, if necessary, please change simple to redis, and open the following redis connection configuration - # Sub-configuration items can be opened or customized as needed - cache: - type: simple - # If type is configured as redis, this item can be configured as needed, note: Pay attention to the indentation of this configuration item - # redis: - # # Whether to cache empty values, save the default - # cache-null-values: false - # # Cache expiration time, default 24 hours - # time-to-live: 86400 - - ########################################################## Redis配置 ########################################################## - # If sa-token needs to rely on redis, please open the redis configuration and depend on pom.xml and dinky-admin/pom.xml, and configure redis connection information in application.yml - # note: pay attention to the indentation of this configuration item +########################################################## Redis配置 ########################################################## +# If sa-token needs to rely on redis, please open the redis configuration and depend on pom.xml and dinky-admin/pom.xml, and configure redis connection information in application.yml +# note: pay attention to the indentation of this configuration item # redis: # host: localhost # port: 6379 @@ -147,6 +134,7 @@ sa-token: # is read header is-read-header: true token-name: token + is-read-cookie: true ################################################################################################################# ################################################# knife4j Config ################################################ diff --git a/dinky-common/src/main/resources/i18n/messages_en_US.properties b/dinky-common/src/main/resources/i18n/messages_en_US.properties index d2e23628ef..36b2053f28 100644 --- a/dinky-common/src/main/resources/i18n/messages_en_US.properties +++ b/dinky-common/src/main/resources/i18n/messages_en_US.properties @@ -34,7 +34,7 @@ test.msg.job.log.url=Click to view the exception log for this task user.assign.role.success=User Assign Role Success global.params.check.error.value=Field: {0}, Illegal Value: {1} change.password.success=Change Password Success -user.not.exist=User Not Exist +user.not.exist=User:{0} Not Exist refresh.success=Refresh Successfully ds.get.node.list.error=Get Node List Error ldap.default.tenant.nofound=The LDAP default tenant does not exist diff --git a/dinky-common/src/main/resources/i18n/messages_zh_CN.properties b/dinky-common/src/main/resources/i18n/messages_zh_CN.properties index b2e99064b4..6faee5782e 100644 --- a/dinky-common/src/main/resources/i18n/messages_zh_CN.properties +++ b/dinky-common/src/main/resources/i18n/messages_zh_CN.properties @@ -34,7 +34,7 @@ test.msg.job.log.url=点击查看该任务的异常日志 user.assign.role.success=用户分配角色成功 global.params.check.error.value=字段: {0}, 不合法的值: {1} change.password.success=修改密码成功 -user.not.exist=用户不存在 +user.not.exist=用户:{0} 不存在 refresh.success=刷新成功 ds.get.node.list.error=节点获取失败 ldap.default.tenant.nofound=LDAP默认租户不存在 From 5bbbe2c52b3acb234384658e7d58d498d9b48696 Mon Sep 17 00:00:00 2001 From: Zzm0809 Date: Tue, 30 Jan 2024 04:20:30 +0000 Subject: [PATCH 2/9] Spotless Apply --- .../dinky/interceptor/TenantInterceptor.java | 30 +++++++++++-------- .../dinky/service/impl/UserServiceImpl.java | 2 +- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/dinky-admin/src/main/java/org/dinky/interceptor/TenantInterceptor.java b/dinky-admin/src/main/java/org/dinky/interceptor/TenantInterceptor.java index 3386920c72..330509e29f 100644 --- a/dinky-admin/src/main/java/org/dinky/interceptor/TenantInterceptor.java +++ b/dinky-admin/src/main/java/org/dinky/interceptor/TenantInterceptor.java @@ -19,27 +19,31 @@ package org.dinky.interceptor; -import cn.dev33.satoken.SaManager; -import cn.dev33.satoken.dao.SaTokenDao; -import cn.dev33.satoken.stp.StpLogic; -import cn.dev33.satoken.stp.StpUtil; -import cn.hutool.core.lang.Opt; +import org.dinky.assertion.Asserts; +import org.dinky.context.TenantContextHolder; +import org.dinky.context.UserInfoContextHolder; +import org.dinky.data.dto.UserDTO; +import org.dinky.data.model.rbac.Tenant; + +import org.apache.commons.collections4.CollectionUtils; + import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; + import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.CollectionUtils; -import org.dinky.assertion.Asserts; -import org.dinky.context.TenantContextHolder; -import org.dinky.context.UserInfoContextHolder; -import org.dinky.data.dto.UserDTO; -import org.dinky.data.model.rbac.Tenant; + import org.jetbrains.annotations.NotNull; import org.springframework.web.servlet.AsyncHandlerInterceptor; +import cn.dev33.satoken.SaManager; +import cn.dev33.satoken.dao.SaTokenDao; +import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.lang.Opt; +import lombok.extern.slf4j.Slf4j; + /** * tenant interceptor */ @@ -64,7 +68,7 @@ public boolean preHandle(HttpServletRequest request, @NotNull HttpServletRespons } break; case "tenantId": - if (!StpUtil.isLogin()){ + if (!StpUtil.isLogin()) { return false; } UserDTO userInfo = UserInfoContextHolder.get(StpUtil.getLoginIdAsInt()); diff --git a/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java index 5f8eaa356f..10ffc88ac1 100644 --- a/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java @@ -180,7 +180,7 @@ public Result loginUser(LoginDTO loginDTO) { user = loginDTO.isLdapLogin() ? ldapLogin(loginDTO) : localLogin(loginDTO); } catch (AuthException e) { // Handle authentication exceptions and return the corresponding error status - return Result.authorizeFailed(Status.USER_NOT_EXIST,loginDTO.getUsername()); + return Result.authorizeFailed(Status.USER_NOT_EXIST, loginDTO.getUsername()); } // Check if the user is enabled From c48d7662aadcfd986db6c09c07837db29ad2babb Mon Sep 17 00:00:00 2001 From: Zzm0809 <934230207@qq.com> Date: Tue, 30 Jan 2024 12:28:30 +0800 Subject: [PATCH 3/9] fix-token-error --- .../dinky/service/impl/LdapServiceImpl.java | 2 +- .../dinky/service/impl/UserServiceImpl.java | 38 +++++++++---------- .../dinky/data/exception/AuthException.java | 6 +++ 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/dinky-admin/src/main/java/org/dinky/service/impl/LdapServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/impl/LdapServiceImpl.java index d71d6a7533..7be4bd2921 100644 --- a/dinky-admin/src/main/java/org/dinky/service/impl/LdapServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/impl/LdapServiceImpl.java @@ -73,7 +73,7 @@ public User authenticate(LoginDTO loginDTO) throws AuthException { if (result.size() == 0) { log.info(String.format( "No results found for search, base: '%s'; filter: '%s'", configuration.getLdapBaseDn(), filter)); - throw new AuthException(Status.USER_NOT_EXIST); + throw new AuthException(Status.USER_NOT_EXIST,loginDTO.getUsername()); } else if (result.size() > 1) { log.error(String.format( "IncorrectResultSize, base: '%s'; filter: '%s'", configuration.getLdapBaseDn(), filter)); diff --git a/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java index 5f8eaa356f..b188896ab6 100644 --- a/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java @@ -19,6 +19,20 @@ package org.dinky.service.impl; +import cn.dev33.satoken.secure.SaSecureUtil; +import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.RandomUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReentrantLock; +import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; import org.dinky.assertion.Asserts; import org.dinky.context.RowLevelPermissionsContext; import org.dinky.context.TenantContextHolder; @@ -55,27 +69,9 @@ import org.dinky.service.UserRoleService; import org.dinky.service.UserService; import org.dinky.service.UserTenantService; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.locks.ReentrantLock; -import java.util.stream.Collectors; - import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; - -import cn.dev33.satoken.secure.SaSecureUtil; -import cn.dev33.satoken.stp.StpUtil; -import cn.hutool.core.date.DateTime; -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.RandomUtil; -import cn.hutool.core.util.StrUtil; -import lombok.RequiredArgsConstructor; - /** * UserServiceImpl * @@ -141,7 +137,7 @@ public Boolean modifyUser(User user) { public Result modifyPassword(ModifyPasswordDTO modifyPasswordDTO) { User user = getById(modifyPasswordDTO.getId()); if (Asserts.isNull(user)) { - return Result.failed(Status.USER_NOT_EXIST); + return Result.authorizeFailed(Status.USER_NOT_EXIST, modifyPasswordDTO.getUsername()); } if (!Asserts.isEquals(SaSecureUtil.md5(modifyPasswordDTO.getPassword()), user.getPassword())) { return Result.failed(Status.USER_OLD_PASSWORD_INCORRECT); @@ -180,7 +176,7 @@ public Result loginUser(LoginDTO loginDTO) { user = loginDTO.isLdapLogin() ? ldapLogin(loginDTO) : localLogin(loginDTO); } catch (AuthException e) { // Handle authentication exceptions and return the corresponding error status - return Result.authorizeFailed(Status.USER_NOT_EXIST,loginDTO.getUsername()); + return Result.authorizeFailed(Status.USER_NOT_EXIST, loginDTO.getUsername()); } // Check if the user is enabled @@ -247,7 +243,7 @@ private User localLogin(LoginDTO loginDTO) throws AuthException { User user = getUserByUsername(loginDTO.getUsername()); if (Asserts.isNull(user)) { // User doesn't exist - throw new AuthException(Status.USER_NOT_EXIST); + throw new AuthException(Status.USER_NOT_EXIST,loginDTO.getUsername()); } String userPassword = user.getPassword(); diff --git a/dinky-common/src/main/java/org/dinky/data/exception/AuthException.java b/dinky-common/src/main/java/org/dinky/data/exception/AuthException.java index 839fbe1631..0db384f7df 100644 --- a/dinky-common/src/main/java/org/dinky/data/exception/AuthException.java +++ b/dinky-common/src/main/java/org/dinky/data/exception/AuthException.java @@ -19,6 +19,7 @@ package org.dinky.data.exception; +import java.text.MessageFormat; import org.dinky.data.enums.Status; import lombok.Data; @@ -42,4 +43,9 @@ public AuthException(Throwable cause, Status status) { super(status.getMessage(), cause); this.status = status; } + + public AuthException(Status status ,Object... args) { + super(MessageFormat.format(status.getMessage(), args)); + this.status = status; + } } From 2a691542e812744563df2d36d42a31bc5e4dbea3 Mon Sep 17 00:00:00 2001 From: Zzm0809 Date: Tue, 30 Jan 2024 04:29:36 +0000 Subject: [PATCH 4/9] Spotless Apply --- .../dinky/service/impl/LdapServiceImpl.java | 2 +- .../dinky/service/impl/UserServiceImpl.java | 34 +++++++++++-------- .../dinky/data/exception/AuthException.java | 5 +-- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/dinky-admin/src/main/java/org/dinky/service/impl/LdapServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/impl/LdapServiceImpl.java index 7be4bd2921..0175b3d37c 100644 --- a/dinky-admin/src/main/java/org/dinky/service/impl/LdapServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/impl/LdapServiceImpl.java @@ -73,7 +73,7 @@ public User authenticate(LoginDTO loginDTO) throws AuthException { if (result.size() == 0) { log.info(String.format( "No results found for search, base: '%s'; filter: '%s'", configuration.getLdapBaseDn(), filter)); - throw new AuthException(Status.USER_NOT_EXIST,loginDTO.getUsername()); + throw new AuthException(Status.USER_NOT_EXIST, loginDTO.getUsername()); } else if (result.size() > 1) { log.error(String.format( "IncorrectResultSize, base: '%s'; filter: '%s'", configuration.getLdapBaseDn(), filter)); diff --git a/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java index b188896ab6..0983bbb01f 100644 --- a/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java @@ -19,20 +19,6 @@ package org.dinky.service.impl; -import cn.dev33.satoken.secure.SaSecureUtil; -import cn.dev33.satoken.stp.StpUtil; -import cn.hutool.core.date.DateTime; -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.RandomUtil; -import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.locks.ReentrantLock; -import java.util.stream.Collectors; -import lombok.RequiredArgsConstructor; import org.dinky.assertion.Asserts; import org.dinky.context.RowLevelPermissionsContext; import org.dinky.context.TenantContextHolder; @@ -69,9 +55,27 @@ import org.dinky.service.UserRoleService; import org.dinky.service.UserService; import org.dinky.service.UserTenantService; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReentrantLock; +import java.util.stream.Collectors; + import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; + +import cn.dev33.satoken.secure.SaSecureUtil; +import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.RandomUtil; +import cn.hutool.core.util.StrUtil; +import lombok.RequiredArgsConstructor; + /** * UserServiceImpl * @@ -243,7 +247,7 @@ private User localLogin(LoginDTO loginDTO) throws AuthException { User user = getUserByUsername(loginDTO.getUsername()); if (Asserts.isNull(user)) { // User doesn't exist - throw new AuthException(Status.USER_NOT_EXIST,loginDTO.getUsername()); + throw new AuthException(Status.USER_NOT_EXIST, loginDTO.getUsername()); } String userPassword = user.getPassword(); diff --git a/dinky-common/src/main/java/org/dinky/data/exception/AuthException.java b/dinky-common/src/main/java/org/dinky/data/exception/AuthException.java index 0db384f7df..e8aa68b702 100644 --- a/dinky-common/src/main/java/org/dinky/data/exception/AuthException.java +++ b/dinky-common/src/main/java/org/dinky/data/exception/AuthException.java @@ -19,9 +19,10 @@ package org.dinky.data.exception; -import java.text.MessageFormat; import org.dinky.data.enums.Status; +import java.text.MessageFormat; + import lombok.Data; /** @@ -44,7 +45,7 @@ public AuthException(Throwable cause, Status status) { this.status = status; } - public AuthException(Status status ,Object... args) { + public AuthException(Status status, Object... args) { super(MessageFormat.format(status.getMessage(), args)); this.status = status; } From d31284f5fc56173d5b4dee6a9d9bba1a8d40c82b Mon Sep 17 00:00:00 2001 From: Zzm0809 <934230207@qq.com> Date: Tue, 30 Jan 2024 12:31:51 +0800 Subject: [PATCH 5/9] format --- .../dinky/service/impl/LdapServiceImpl.java | 2 +- .../dinky/service/impl/UserServiceImpl.java | 34 +++++++++++-------- .../dinky/data/exception/AuthException.java | 5 +-- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/dinky-admin/src/main/java/org/dinky/service/impl/LdapServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/impl/LdapServiceImpl.java index 7be4bd2921..0175b3d37c 100644 --- a/dinky-admin/src/main/java/org/dinky/service/impl/LdapServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/impl/LdapServiceImpl.java @@ -73,7 +73,7 @@ public User authenticate(LoginDTO loginDTO) throws AuthException { if (result.size() == 0) { log.info(String.format( "No results found for search, base: '%s'; filter: '%s'", configuration.getLdapBaseDn(), filter)); - throw new AuthException(Status.USER_NOT_EXIST,loginDTO.getUsername()); + throw new AuthException(Status.USER_NOT_EXIST, loginDTO.getUsername()); } else if (result.size() > 1) { log.error(String.format( "IncorrectResultSize, base: '%s'; filter: '%s'", configuration.getLdapBaseDn(), filter)); diff --git a/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java index b188896ab6..0983bbb01f 100644 --- a/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java @@ -19,20 +19,6 @@ package org.dinky.service.impl; -import cn.dev33.satoken.secure.SaSecureUtil; -import cn.dev33.satoken.stp.StpUtil; -import cn.hutool.core.date.DateTime; -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.RandomUtil; -import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.locks.ReentrantLock; -import java.util.stream.Collectors; -import lombok.RequiredArgsConstructor; import org.dinky.assertion.Asserts; import org.dinky.context.RowLevelPermissionsContext; import org.dinky.context.TenantContextHolder; @@ -69,9 +55,27 @@ import org.dinky.service.UserRoleService; import org.dinky.service.UserService; import org.dinky.service.UserTenantService; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReentrantLock; +import java.util.stream.Collectors; + import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; + +import cn.dev33.satoken.secure.SaSecureUtil; +import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.RandomUtil; +import cn.hutool.core.util.StrUtil; +import lombok.RequiredArgsConstructor; + /** * UserServiceImpl * @@ -243,7 +247,7 @@ private User localLogin(LoginDTO loginDTO) throws AuthException { User user = getUserByUsername(loginDTO.getUsername()); if (Asserts.isNull(user)) { // User doesn't exist - throw new AuthException(Status.USER_NOT_EXIST,loginDTO.getUsername()); + throw new AuthException(Status.USER_NOT_EXIST, loginDTO.getUsername()); } String userPassword = user.getPassword(); diff --git a/dinky-common/src/main/java/org/dinky/data/exception/AuthException.java b/dinky-common/src/main/java/org/dinky/data/exception/AuthException.java index 0db384f7df..e8aa68b702 100644 --- a/dinky-common/src/main/java/org/dinky/data/exception/AuthException.java +++ b/dinky-common/src/main/java/org/dinky/data/exception/AuthException.java @@ -19,9 +19,10 @@ package org.dinky.data.exception; -import java.text.MessageFormat; import org.dinky.data.enums.Status; +import java.text.MessageFormat; + import lombok.Data; /** @@ -44,7 +45,7 @@ public AuthException(Throwable cause, Status status) { this.status = status; } - public AuthException(Status status ,Object... args) { + public AuthException(Status status, Object... args) { super(MessageFormat.format(status.getMessage(), args)); this.status = status; } From 75bd3e78826e341fa1321b5dbf040a71ef9f052f Mon Sep 17 00:00:00 2001 From: Zzm0809 <934230207@qq.com> Date: Tue, 30 Jan 2024 12:36:21 +0800 Subject: [PATCH 6/9] fix-token-error --- .../src/main/resources/application.yml | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/dinky-admin/src/main/resources/application.yml b/dinky-admin/src/main/resources/application.yml index dac1afe9d8..1b43bd530c 100644 --- a/dinky-admin/src/main/resources/application.yml +++ b/dinky-admin/src/main/resources/application.yml @@ -89,21 +89,8 @@ mybatis-plus: ################################################################################################################# ################################################# SMS Config #################################################### ################################################################################################################# -#sms: -# # Whether to enable SMS -# config-type: sql_config -# is-print: false -# sql: -# # The database connection information -# url: ${spring.datasource.url} -# username: ${spring.datasource.username} -# password: ${spring.datasource.password} -# driver-class-name: ${spring.datasource.driver-class-name} -# table-name: dinky_alert_instance -# supplier-field-name: manufacturers -# config-name: params -# start-name: enabled -# is-start: 1 +sms: + is-print: false @@ -144,8 +131,7 @@ knife4j: setting: language: en -sms: - is-print: false + ################################################################################################################# ################################################# Crypto Config ################################################# From 0bd0ad100e66b006e8c1e9e5591ac692e0f1452b Mon Sep 17 00:00:00 2001 From: Zzm0809 <934230207@qq.com> Date: Tue, 30 Jan 2024 13:01:07 +0800 Subject: [PATCH 7/9] added env --- dinky-admin/src/main/resources/application-pgsql.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dinky-admin/src/main/resources/application-pgsql.yml b/dinky-admin/src/main/resources/application-pgsql.yml index 8a1ebb9e34..eff2bdf64a 100644 --- a/dinky-admin/src/main/resources/application-pgsql.yml +++ b/dinky-admin/src/main/resources/application-pgsql.yml @@ -17,7 +17,8 @@ spring: datasource: - username: postgres - password: dinky + username: ${POSTGRES_USER:dinky} + password: ${POSTGRES_PASSWORD:dinky} driver-class-name: org.postgresql.Driver - url: jdbc:postgresql://localhost:5432/dinky?stringtype=unspecified \ No newline at end of file + # The POSTGRES_ADDR variable is not officially provided. If you use docker, please manually add an env to support it. + url: jdbc:postgresql://${POSTGRES_ADDR:localhost:5432}/${POSTGRES_DB:dinky}?stringtype=unspecified \ No newline at end of file From 1db6530e00453fb69ea5590635e305b0f50a0c75 Mon Sep 17 00:00:00 2001 From: Zzm0809 <934230207@qq.com> Date: Tue, 30 Jan 2024 13:23:55 +0800 Subject: [PATCH 8/9] fix npe --- .../java/org/dinky/service/impl/UserServiceImpl.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java index 0983bbb01f..23b562ebf4 100644 --- a/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java @@ -75,6 +75,7 @@ import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.StrUtil; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; /** * UserServiceImpl @@ -83,6 +84,7 @@ */ @Service @RequiredArgsConstructor +@Slf4j public class UserServiceImpl extends SuperServiceImpl implements UserService { private static final String DEFAULT_PASSWORD = "123456"; @@ -464,8 +466,14 @@ public List getUserListByTenantId(int id) { userTenantService.list(new LambdaQueryWrapper().eq(UserTenant::getTenantId, id)); userTenants.forEach(userTenant -> { User user = getById(userTenant.getUserId()); - user.setTenantAdminFlag(userTenant.getTenantAdminFlag()); - userList.add(user); + if (!Asserts.isNull(user)) { + user.setTenantAdminFlag(userTenant.getTenantAdminFlag()); + userList.add(user); + } else { + log.error( + "Unable to obtain user information, the user may have been deleted, please contact the administrator to verify, userId:[{}]", + userTenant.getUserId()); + } }); return userList; } From 9874f4f94e1c8c2f652c24845fb4754fdf77df16 Mon Sep 17 00:00:00 2001 From: Zzm0809 <934230207@qq.com> Date: Tue, 30 Jan 2024 13:25:57 +0800 Subject: [PATCH 9/9] fix actions --- .github/workflows/pr-reviewer-assign.yml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/.github/workflows/pr-reviewer-assign.yml b/.github/workflows/pr-reviewer-assign.yml index ffdae85ac5..53dbc3fc0c 100644 --- a/.github/workflows/pr-reviewer-assign.yml +++ b/.github/workflows/pr-reviewer-assign.yml @@ -22,14 +22,4 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} pr-emoji: '+1, rocket' reviewers: 'zackyoungh,gaoyan1998,Zzm0809,aiwenmo' - review-creator: false - - - - name: Add project - if: "github.event_name == 'pull_request_target'" - uses: alex-page/github-project-automation-plus@v0.8.1 - with: - project: Dinky Roadmap - column: RoadMap - repo-token: ${{ secrets.GITHUB_TOKEN }} - action: add + review-creator: false \ No newline at end of file