From d824675168f02b2b369f6db05fc8aa60a68c18e3 Mon Sep 17 00:00:00 2001 From: Hacker <721806280@qq.com> Date: Thu, 20 Jan 2022 06:32:39 +0000 Subject: [PATCH 1/2] update pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/util/WebUtils.java. --- .../java/com/pig4cloud/pig/common/core/util/WebUtils.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/util/WebUtils.java b/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/util/WebUtils.java index 2c9986e9..1b6117c0 100755 --- a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/util/WebUtils.java +++ b/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/util/WebUtils.java @@ -18,6 +18,7 @@ package com.pig4cloud.pig.common.core.util; import cn.hutool.core.codec.Base64; import cn.hutool.json.JSONUtil; +import com.pig4cloud.pig.common.core.constant.CommonConstants; import com.pig4cloud.pig.common.core.exception.CheckedException; import lombok.SneakyThrows; import lombok.experimental.UtilityClass; @@ -36,7 +37,6 @@ import javax.servlet.http.HttpServletResponse; import javax.validation.constraints.NotNull; import java.io.IOException; import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.util.Optional; @@ -143,7 +143,7 @@ public class WebUtils extends org.springframework.web.util.WebUtils { * @param contentType contentType */ public void renderJson(HttpServletResponse response, Object result, String contentType) { - response.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(CommonConstants.UTF8); response.setContentType(contentType); try (PrintWriter out = response.getWriter()) { out.append(JSONUtil.toJsonStr(result)); @@ -164,7 +164,7 @@ public class WebUtils extends org.springframework.web.util.WebUtils { } @SneakyThrows - public String getClientId(HttpServletRequest request) { + public String getClientId() { if (WebUtils.getRequest().isPresent()) { String header = WebUtils.getRequest().get().getHeader(HttpHeaders.AUTHORIZATION); return splitClient(header)[0]; @@ -173,7 +173,7 @@ public class WebUtils extends org.springframework.web.util.WebUtils { } @NotNull - private static String[] splitClient(String header) throws UnsupportedEncodingException { + private static String[] splitClient(String header) { if (header == null || !header.startsWith(BASIC_)) { throw new CheckedException("请求头中client信息为空"); } From e11f952ab77d304a9e6fad95bc43653f9a6dd95c Mon Sep 17 00:00:00 2001 From: Hacker <721806280@qq.com> Date: Thu, 20 Jan 2022 07:23:27 +0000 Subject: [PATCH 2/2] update PermissionService.java. --- .../common/security/component/PermissionService.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PermissionService.java b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PermissionService.java index 52d4240b..00227c8e 100755 --- a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PermissionService.java +++ b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PermissionService.java @@ -16,7 +16,7 @@ package com.pig4cloud.pig.common.security.component; -import cn.hutool.core.util.StrUtil; +import cn.hutool.core.util.ArrayUtil; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; @@ -32,12 +32,12 @@ import java.util.Collection; public class PermissionService { /** - * 判断接口是否有xxx:xxx权限 - * @param permission 权限 + * 判断接口是否有任意xxx,xxx权限 + * @param permissions 权限 * @return {boolean} */ - public boolean hasPermission(String permission) { - if (StrUtil.isBlank(permission)) { + public boolean hasPermission(String... permissions) { + if (ArrayUtil.isEmpty(permissions)) { return false; } Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); @@ -46,7 +46,7 @@ public class PermissionService { } Collection authorities = authentication.getAuthorities(); return authorities.stream().map(GrantedAuthority::getAuthority).filter(StringUtils::hasText) - .anyMatch(x -> PatternMatchUtils.simpleMatch(permission, x)); + .anyMatch(x -> PatternMatchUtils.simpleMatch(permissions, x)); } }