升级支持Spring Cloud 2023+Spring Boot 3.2+JDK 17
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.macro.mall.common.api;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
|
||||
/**
|
||||
* 通用返回对象
|
||||
* Created by macro on 2019/4/19.
|
||||
@@ -121,4 +123,9 @@ public class CommonResult<T> {
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JSONUtil.toJsonStr(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
package com.macro.mall.common.config;
|
||||
|
||||
import com.macro.mall.common.domain.SwaggerProperties;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.*;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spi.service.contexts.SecurityContext;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.spring.web.plugins.WebFluxRequestHandlerProvider;
|
||||
import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Swagger基础配置
|
||||
* Created by macro on 2020/7/16.
|
||||
*/
|
||||
public abstract class BaseSwaggerConfig {
|
||||
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
SwaggerProperties swaggerProperties = swaggerProperties();
|
||||
Docket docket = new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo(swaggerProperties))
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage(swaggerProperties.getApiBasePackage()))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
if (swaggerProperties.isEnableSecurity()) {
|
||||
docket.securitySchemes(securitySchemes()).securityContexts(securityContexts());
|
||||
}
|
||||
return docket;
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo(SwaggerProperties swaggerProperties) {
|
||||
return new ApiInfoBuilder()
|
||||
.title(swaggerProperties.getTitle())
|
||||
.description(swaggerProperties.getDescription())
|
||||
.contact(new Contact(swaggerProperties.getContactName(), swaggerProperties.getContactUrl(), swaggerProperties.getContactEmail()))
|
||||
.version(swaggerProperties.getVersion())
|
||||
.build();
|
||||
}
|
||||
|
||||
private List<SecurityScheme> securitySchemes() {
|
||||
//设置请求头信息
|
||||
List<SecurityScheme> result = new ArrayList<>();
|
||||
ApiKey apiKey = new ApiKey("Authorization", "Authorization", "header");
|
||||
result.add(apiKey);
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<SecurityContext> securityContexts() {
|
||||
//设置需要登录认证的路径
|
||||
List<SecurityContext> result = new ArrayList<>();
|
||||
result.add(getContextByPath("/*/.*"));
|
||||
return result;
|
||||
}
|
||||
|
||||
private SecurityContext getContextByPath(String pathRegex) {
|
||||
return SecurityContext.builder()
|
||||
.securityReferences(defaultAuth())
|
||||
.forPaths(PathSelectors.regex(pathRegex))
|
||||
.build();
|
||||
}
|
||||
|
||||
private List<SecurityReference> defaultAuth() {
|
||||
List<SecurityReference> result = new ArrayList<>();
|
||||
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
|
||||
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
|
||||
authorizationScopes[0] = authorizationScope;
|
||||
result.add(new SecurityReference("Authorization", authorizationScopes));
|
||||
return result;
|
||||
}
|
||||
|
||||
public BeanPostProcessor generateBeanPostProcessor() {
|
||||
return new BeanPostProcessor() {
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) {
|
||||
customizeSpringfoxHandlerMappings(getHandlerMappings(bean));
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
private <T extends RequestMappingInfoHandlerMapping> void customizeSpringfoxHandlerMappings(List<T> mappings) {
|
||||
List<T> copy = mappings.stream()
|
||||
.filter(mapping -> mapping.getPatternParser() == null)
|
||||
.collect(Collectors.toList());
|
||||
mappings.clear();
|
||||
mappings.addAll(copy);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<RequestMappingInfoHandlerMapping> getHandlerMappings(Object bean) {
|
||||
try {
|
||||
Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings");
|
||||
field.setAccessible(true);
|
||||
return (List<RequestMappingInfoHandlerMapping>) field.get(bean);
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义Swagger配置
|
||||
*/
|
||||
public abstract SwaggerProperties swaggerProperties();
|
||||
|
||||
}
|
||||
@@ -32,9 +32,9 @@ public interface AuthConstant {
|
||||
String ADMIN_URL_PATTERN = "/mall-admin/**";
|
||||
|
||||
/**
|
||||
* Redis缓存权限规则key
|
||||
* Redis缓存权限规则(路径->资源)
|
||||
*/
|
||||
String RESOURCE_ROLES_MAP_KEY = "auth:resourceRolesMap";
|
||||
String PATH_RESOURCE_MAP = "auth:pathResourceMap";
|
||||
|
||||
/**
|
||||
* 认证信息Http请求头
|
||||
@@ -51,4 +51,14 @@ public interface AuthConstant {
|
||||
*/
|
||||
String USER_TOKEN_HEADER = "user";
|
||||
|
||||
/**
|
||||
* sa-token session中存储的会员信息
|
||||
*/
|
||||
String STP_MEMBER_INFO = "memberInfo";
|
||||
|
||||
/**
|
||||
* sa-token session中存储的后台管理员信息
|
||||
*/
|
||||
String STP_ADMIN_INFO = "adminInfo";
|
||||
|
||||
}
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
package com.macro.mall.common.domain;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* Swagger自定义配置
|
||||
* Created by macro on 2020/7/16.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Builder
|
||||
public class SwaggerProperties {
|
||||
/**
|
||||
* API文档生成基础路径
|
||||
*/
|
||||
private String apiBasePackage;
|
||||
/**
|
||||
* 是否要启用登录认证
|
||||
*/
|
||||
private boolean enableSecurity;
|
||||
/**
|
||||
* 文档标题
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 文档描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 文档版本
|
||||
*/
|
||||
private String version;
|
||||
/**
|
||||
* 文档联系人姓名
|
||||
*/
|
||||
private String contactName;
|
||||
/**
|
||||
* 文档联系人网址
|
||||
*/
|
||||
private String contactUrl;
|
||||
/**
|
||||
* 文档联系人邮箱
|
||||
*/
|
||||
private String contactEmail;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.macro.mall.common.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 登录用户信息
|
||||
* Created by macro on 2020/6/19.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@NoArgsConstructor
|
||||
public class UserDto {
|
||||
private Long id;
|
||||
private String username;
|
||||
private String password;
|
||||
private Integer status;
|
||||
private String clientId;
|
||||
private List<String> roles;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.macro.mall.common.dto;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @auther macrozheng
|
||||
* @description 权限框架中使用的用户信息封装类
|
||||
* @date 2024/1/30
|
||||
* @github https://github.com/macrozheng
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class UserDto {
|
||||
private Long id;
|
||||
private String username;
|
||||
private String clientId;
|
||||
private List<String> permissionList;
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.macro.mall.common.domain.WebLog;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import net.logstash.logback.marker.Markers;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
@@ -21,7 +21,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.ArrayList;
|
||||
@@ -63,9 +63,9 @@ public class WebLogAspect {
|
||||
Signature signature = joinPoint.getSignature();
|
||||
MethodSignature methodSignature = (MethodSignature) signature;
|
||||
Method method = methodSignature.getMethod();
|
||||
if (method.isAnnotationPresent(ApiOperation.class)) {
|
||||
ApiOperation log = method.getAnnotation(ApiOperation.class);
|
||||
webLog.setDescription(log.value());
|
||||
if (method.isAnnotationPresent(Operation.class)) {
|
||||
Operation log = method.getAnnotation(Operation.class);
|
||||
webLog.setDescription(log.summary());
|
||||
}
|
||||
long endTime = System.currentTimeMillis();
|
||||
String urlStr = request.getRequestURL().toString();
|
||||
|
||||
@@ -11,7 +11,10 @@
|
||||
<property name="LOG_FILE_PATH" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}/logs}"/>
|
||||
<!--LogStash访问host-->
|
||||
<springProperty name="LOG_STASH_HOST" scope="context" source="logstash.host" defaultValue="localhost"/>
|
||||
|
||||
<!--是否开启LogStash插件内部日志-->
|
||||
<springProperty name="ENABLE_INNER_LOG" scope="context" source="logstash.enableInnerLog" defaultValue="false"/>
|
||||
<!--配置不打印logback内部的状态信息,排查logback配置问题时可注释掉-->
|
||||
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
|
||||
<!--DEBUG日志输出到文件-->
|
||||
<appender name="FILE_DEBUG"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
@@ -64,6 +67,7 @@
|
||||
<level>DEBUG</level>
|
||||
</filter>
|
||||
<destination>${LOG_STASH_HOST}:4560</destination>
|
||||
<addDefaultStatusListener>${ENABLE_INNER_LOG}</addDefaultStatusListener>
|
||||
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
|
||||
<providers>
|
||||
<timestamp>
|
||||
@@ -86,12 +90,6 @@
|
||||
</pattern>
|
||||
</providers>
|
||||
</encoder>
|
||||
<!--当有多个LogStash服务时,设置访问策略为轮询-->
|
||||
<connectionStrategy>
|
||||
<roundRobin>
|
||||
<connectionTTL>5 minutes</connectionTTL>
|
||||
</roundRobin>
|
||||
</connectionStrategy>
|
||||
</appender>
|
||||
|
||||
<!--ERROR日志输出到LogStash-->
|
||||
@@ -102,6 +100,7 @@
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
<destination>${LOG_STASH_HOST}:4561</destination>
|
||||
<addDefaultStatusListener>${ENABLE_INNER_LOG}</addDefaultStatusListener>
|
||||
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
|
||||
<providers>
|
||||
<timestamp>
|
||||
@@ -124,17 +123,12 @@
|
||||
</pattern>
|
||||
</providers>
|
||||
</encoder>
|
||||
<!--当有多个LogStash服务时,设置访问策略为轮询-->
|
||||
<connectionStrategy>
|
||||
<roundRobin>
|
||||
<connectionTTL>5 minutes</connectionTTL>
|
||||
</roundRobin>
|
||||
</connectionStrategy>
|
||||
</appender>
|
||||
|
||||
<!--业务日志输出到LogStash-->
|
||||
<appender name="LOG_STASH_BUSINESS" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
|
||||
<destination>${LOG_STASH_HOST}:4562</destination>
|
||||
<addDefaultStatusListener>${ENABLE_INNER_LOG}</addDefaultStatusListener>
|
||||
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
|
||||
<providers>
|
||||
<timestamp>
|
||||
@@ -157,17 +151,12 @@
|
||||
</pattern>
|
||||
</providers>
|
||||
</encoder>
|
||||
<!--当有多个LogStash服务时,设置访问策略为轮询-->
|
||||
<connectionStrategy>
|
||||
<roundRobin>
|
||||
<connectionTTL>5 minutes</connectionTTL>
|
||||
</roundRobin>
|
||||
</connectionStrategy>
|
||||
</appender>
|
||||
|
||||
<!--接口访问记录日志输出到LogStash-->
|
||||
<appender name="LOG_STASH_RECORD" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
|
||||
<destination>${LOG_STASH_HOST}:4563</destination>
|
||||
<addDefaultStatusListener>${ENABLE_INNER_LOG}</addDefaultStatusListener>
|
||||
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
|
||||
<providers>
|
||||
<timestamp>
|
||||
@@ -187,12 +176,6 @@
|
||||
</pattern>
|
||||
</providers>
|
||||
</encoder>
|
||||
<!--当有多个LogStash服务时,设置访问策略为轮询-->
|
||||
<connectionStrategy>
|
||||
<roundRobin>
|
||||
<connectionTTL>5 minutes</connectionTTL>
|
||||
</roundRobin>
|
||||
</connectionStrategy>
|
||||
</appender>
|
||||
|
||||
<!--控制框架输出日志-->
|
||||
|
||||
Reference in New Issue
Block a user