From a9ce4ede8fd0d1d01c2003fe033c9855c2176c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=98=95?= Date: Thu, 7 Mar 2024 17:00:01 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E6=9B=B4=E6=96=B0=E8=AF=AD=E6=B3=95?= =?UTF-8?q?=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../authentication/exception/CommonAuthException.java | 4 ++-- .../authentication/interceptor/RequestBodyFilter.java | 4 ++-- .../cs/authentication/misc/CasbinAuthorizeUtils.java | 10 ++++------ .../main/java/com/cf/cs/database/pojo/entity/Role.java | 9 +++++++-- .../cf/cs/restful/controller/CommonFrameworkApi.java | 6 ++---- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/cs-authentication/src/main/java/com/cf/cs/authentication/exception/CommonAuthException.java b/cs-authentication/src/main/java/com/cf/cs/authentication/exception/CommonAuthException.java index 06488c4..ac9a5ca 100644 --- a/cs-authentication/src/main/java/com/cf/cs/authentication/exception/CommonAuthException.java +++ b/cs-authentication/src/main/java/com/cf/cs/authentication/exception/CommonAuthException.java @@ -13,9 +13,9 @@ import org.springframework.security.core.AuthenticationException; @Getter @Setter public class CommonAuthException extends AuthenticationException { - private ErrorCode err; + private final ErrorCode err; - private String[] description; + private final String[] description; /** * Instantiates a new Common auth exception. diff --git a/cs-authentication/src/main/java/com/cf/cs/authentication/interceptor/RequestBodyFilter.java b/cs-authentication/src/main/java/com/cf/cs/authentication/interceptor/RequestBodyFilter.java index d4bfaf4..709e431 100644 --- a/cs-authentication/src/main/java/com/cf/cs/authentication/interceptor/RequestBodyFilter.java +++ b/cs-authentication/src/main/java/com/cf/cs/authentication/interceptor/RequestBodyFilter.java @@ -31,8 +31,8 @@ public class RequestBodyFilter implements Filter { public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { ServletRequest requestWrapper = null; - if (servletRequest instanceof HttpServletRequest) { - requestWrapper = new RequestBodyCacheWrapper((HttpServletRequest) servletRequest); + if (servletRequest instanceof HttpServletRequest httpServletRequest) { + requestWrapper = new RequestBodyCacheWrapper(httpServletRequest); } //获取请求中的流如何,将取出来的字符串,再次转换成流,然后把它放入到新request对象中 // 在chain.doFiler方法中传递新的request对象 diff --git a/cs-authentication/src/main/java/com/cf/cs/authentication/misc/CasbinAuthorizeUtils.java b/cs-authentication/src/main/java/com/cf/cs/authentication/misc/CasbinAuthorizeUtils.java index 31ba397..b16d76d 100644 --- a/cs-authentication/src/main/java/com/cf/cs/authentication/misc/CasbinAuthorizeUtils.java +++ b/cs-authentication/src/main/java/com/cf/cs/authentication/misc/CasbinAuthorizeUtils.java @@ -58,9 +58,9 @@ public class CasbinAuthorizeUtils { // 添加角色资源权限 roleResourceService.getRoleResourceByRoleId(role.getId()).forEach(k -> { e.addPermissionForUser(role.getName(), k.getResources().getPath(), k.getResources().getHttpMethod(), - k.getAuthorize() ? "allow" : "deny"); + Boolean.TRUE.equals(k.getAuthorize()) ? "allow" : "deny"); log.trace("++++++[{}, {}, {}: {}]", role.getName(), k.getResources().getPath(), - k.getResources().getHttpMethod(), k.getAuthorize() ? "allow" : "deny"); + k.getResources().getHttpMethod(), Boolean.TRUE.equals(k.getAuthorize()) ? "allow" : "deny"); }); // 缓存当前权限验证器 @@ -85,7 +85,7 @@ public class CasbinAuthorizeUtils { } // 角色被禁用 - if (!user.getRole().getAvailable()) { + if (Boolean.FALSE.equals(user.getRole().getAvailable())) { return false; } @@ -96,10 +96,8 @@ public class CasbinAuthorizeUtils { for (String s : e.getImplicitRolesForUser(user.getRole().getName())) { Enforcer se = CasbinAuthorizeUtils.ENFORCER_POOL.get(s); - if (s != null) { - if (se.enforce(s, url, httpMethod)) { + if (s != null && (se.enforce(s, url, httpMethod))) { return true; - } } } } diff --git a/cs-database/src/main/java/com/cf/cs/database/pojo/entity/Role.java b/cs-database/src/main/java/com/cf/cs/database/pojo/entity/Role.java index 25e3064..b6d43e3 100644 --- a/cs-database/src/main/java/com/cf/cs/database/pojo/entity/Role.java +++ b/cs-database/src/main/java/com/cf/cs/database/pojo/entity/Role.java @@ -9,6 +9,9 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import java.io.Serial; +import java.io.Serializable; + /** * 权限(Role)表实体类 * @@ -20,13 +23,15 @@ import lombok.NoArgsConstructor; @Table("rbac_role") @AllArgsConstructor @NoArgsConstructor -public class Role { +public class Role implements Serializable { + @Serial + private static final long serialVersionUID = -132325343L; /** * id */ @Schema(description = "id") @Id(keyType = KeyType.Auto) - private Long id; + private Long id; /** * 是否有效 */ diff --git a/cs-restful/src/main/java/com/cf/cs/restful/controller/CommonFrameworkApi.java b/cs-restful/src/main/java/com/cf/cs/restful/controller/CommonFrameworkApi.java index 3931d67..784f95d 100644 --- a/cs-restful/src/main/java/com/cf/cs/restful/controller/CommonFrameworkApi.java +++ b/cs-restful/src/main/java/com/cf/cs/restful/controller/CommonFrameworkApi.java @@ -38,9 +38,8 @@ public class CommonFrameworkApi { @EncryptionProtocol @DecryptionProtocol @PostMapping("/version") - @ResponseBody @OperationLogAnnotation(OperationModule = "通用模块", OperationType = "读取", OperationDesc = "获取当前系统版本信息") - public ProtocolResp getVersion() { + public ProtocolResp getVersion() { return ProtocolResp.result(VersionResp.builder() .version(VersionInfo.builder() .commitId(prgVer.getCommitId()) @@ -59,10 +58,9 @@ public class CommonFrameworkApi { * @return the version v 2 */ @GetMapping("/version") - @ResponseBody @EncryptionProtocol @OperationLogAnnotation(OperationModule = "通用模块", OperationType = "读取", OperationDesc = "获取当前系统版本信息") - public ProtocolResp getVersionV2() { + public ProtocolResp getVersionV2() { return ProtocolResp.result(VersionResp.builder() .version(VersionInfo.builder() .commitId(prgVer.getCommitId())