feat(boot/ssw-admin): 从 jnpf 7.0 源创建 ssw-admin 模块 (6.2→7.0 升级)
- 来源: jnpf/jnpf-java-boot/jnpf-admin/ @ 2bf6be8cda (7.0.0-RELEASE, 2026-07-21) - 包改名: jnpf.* → ssw.* (10 个 java 文件 + SswAdminApplication) - artifactId: jnpf-admin → ssw-admin, mainClass 同改 - parent: ssw-boot:7.0.0-RELEASE (项目自建 parent, 同步升) - deps: 18 jnpf-*-controller + ssw-common-controller + jnpf-common-ai-core - resources: yml 从 6.2 拷过来 + DB 名 j62→j7 + 用 7.0 源 application.yml/application-dev.yml 全替换 (含完整 config.* placeholders) - jnpf-common-all + parent poms 走本地 maven 仓 (87+25 jars 预 install) - SswLLMClient 重写适配 7.0 AI API: - 6.2 AiService/AiEntity 整类删除 (base_ai 表驱动) - 7.0 用 AiProperties + SpringContext 读 yml (spring.cloud.ai.openai.*) - spring.cloud.ai.openai 配置加在 application-dev.yml (env 占位 SSW_LLM_API_KEY) - AuthFilter: import jnpf.util.GatewayUtil → ssw.util.GatewayUtil (我们自己重命名的) - GatewayUtil: 加 import jnpf.util.UserProvider - GatewayUtil + scanBasePackages 加 'ssw' (旧 patch 含义继承, 7.0 框架不再自带 ssw 扫描) - 认证: `--add-opens java.base/*=ALL-UNNAMED` (Java 21 必须) - 启动耗时 ~120s, 端口 30000, DB=j7, Redis=jnpf-redis - mvn package → boot/ssw-admin/target/ssw-admin-7.0.0-RELEASE.jar (367M fat jar) (配套 patch doc: dacli/docs/web-patches/_ssw-admin-creation-from-jnpf-7.0.md 旧 patch _jnpf-admin-scanBasePackages-ssw.md 已标 superseded)
This commit is contained in:
1 parent
db43e57f1d
commit
bb66dffba8
11 files changed
+1070
No files matched your search
@@ -0,0 +1,272 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>ssw-boot</artifactId>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<version>7.0.0-RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>ssw-admin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<!--打包WAR包删除注释-->
|
||||
<!--<packaging>war</packaging>-->
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-file-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- ssw 业务层 (项目自有, 跨 ssw-common-controller 入口) -->
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>ssw-common-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<!-- v7.0 升级 (2026-07-31): ssw-tdd3 模块目录空, 不再依赖 ssw-tdd3-biz (无 jar).
|
||||
历史保留: 6.2 boot/jnpf-admin 引过 ssw-tdd3-biz (no-spa-page 网站后端业务包), 7.0 跟随目录删除一起断引. -->
|
||||
<!-- <dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>ssw-tdd3-biz</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency> -->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-extend-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-system-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-scheduletask-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-message-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-permission-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-visualdev-base-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-visualdev-onlinedev-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-visualdev-generater-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-visualdev-portal-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-visualdata-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-exception</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-oauth-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-example-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-app-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-flowable-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-common-i18n</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 单点登录相关依赖-Start -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.jnpf</groupId>-->
|
||||
<!-- <artifactId>jnpf-sso-starter-all</artifactId>-->
|
||||
<!-- <version>${project.version}</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- 单点登录(用户信息拉取)相关依赖 -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.jnpf</groupId>-->
|
||||
<!-- <artifactId>jnpf-sso-connector</artifactId>-->
|
||||
<!-- <version>${project.version}</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- 单点登录(用户信息推送)相关依赖 -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.jnpf</groupId>-->
|
||||
<!-- <artifactId>jnpf-sso-pull</artifactId>-->
|
||||
<!-- <version>${project.version}</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- 单点登录相关依赖-End -->
|
||||
|
||||
<!--打包WAR包删除注释-->
|
||||
<!--<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>-->
|
||||
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<activation>
|
||||
<jdk>[17,)</jdk>
|
||||
</activation>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-ai-v3-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<id>boot3</id>
|
||||
</profile>
|
||||
<profile>
|
||||
<activation>
|
||||
<jdk>(,17)</jdk>
|
||||
</activation>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.jnpf</groupId>
|
||||
<artifactId>jnpf-ai-v2-controller</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<id>boot2</id>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>default-package</id>
|
||||
<activation>
|
||||
<jdk>[,]</jdk>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- ... -->
|
||||
<!--打包WAR包注释插件-->
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<mainClass>ssw.SswAdminApplication</mainClass>
|
||||
<layout>ZIP</layout>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- ... -->
|
||||
<!--打包WAR包删除注释-->
|
||||
<!--<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>3.3.2</version>
|
||||
<configuration>
|
||||
<warSourceExcludes>src/main/resources/**</warSourceExcludes>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</configuration>
|
||||
</plugin>-->
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>external-package</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- 复制依赖到外部目录 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-dependencies</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${external-lib-out-path}</outputDirectory>
|
||||
<overWriteReleases>true</overWriteReleases>
|
||||
<overWriteSnapshots>true</overWriteSnapshots>
|
||||
<overWriteIfNewer>true</overWriteIfNewer>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<!--启动类path-->
|
||||
<mainClass>ssw.SswAdminApplication</mainClass>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>${external-lib-start-path}</classpathPrefix>
|
||||
</manifest>
|
||||
<manifestEntries>
|
||||
<!--如果不指定,classpath 可能会找不到,加载资源有问题-->
|
||||
<Class-Path>.</Class-Path>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
@@ -0,0 +1,28 @@
|
||||
package ssw;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.x.file.storage.spring.EnableFileStorage;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JNPF开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 引迈信息技术有限公司
|
||||
* @date 2021/3/15 17:12
|
||||
*/
|
||||
@Slf4j
|
||||
@SpringBootApplication(scanBasePackages = {"jnpf","ssw"}, exclude = {DataSourceAutoConfiguration.class})
|
||||
@EnableFileStorage
|
||||
public class SswAdminApplication extends SpringBootServletInitializer {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication springApplication = new SpringApplication(SswAdminApplication.class);
|
||||
springApplication.run(args);
|
||||
log.error("SswAdmin启动完成");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package ssw.aop;
|
||||
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import cn.dev33.satoken.router.SaRouter;
|
||||
import jnpf.base.UserInfo;
|
||||
import jnpf.config.ConfigValueUtil;
|
||||
import jnpf.database.util.TenantDataSourceUtil;
|
||||
import jnpf.properties.GatewayWhite;
|
||||
import jnpf.util.StringUtil;
|
||||
import jnpf.util.TenantHolder;
|
||||
import jnpf.util.UserProvider;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JNPF开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 引迈信息技术有限公司
|
||||
* @date 2021/3/15 17:12
|
||||
*/
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
@Order(1)
|
||||
@RequiredArgsConstructor
|
||||
public class DataSourceBindAspect {
|
||||
|
||||
private final ConfigValueUtil configValueUtil;
|
||||
|
||||
private final GatewayWhite gatewayWhite;
|
||||
|
||||
@Pointcut("within(jnpf.*.controller.* || jnpf.controller.*)")
|
||||
public void bindDataSource() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* NoDataSourceBind 不需要绑定数据库的注解
|
||||
*/
|
||||
@Around("bindDataSource() && !@annotation(jnpf.util.NoDataSourceBind)")
|
||||
public Object doAroundService(ProceedingJoinPoint pjp) throws Throwable {
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
if (StringUtil.isEmpty(TenantHolder.getDatasourceId())) {
|
||||
String url = null;
|
||||
try {
|
||||
url = SaHolder.getRequest().getRequestPath();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
if (url != null) {
|
||||
// 白名单接口不传Token, 不检查租户信息, 要查询数据库需要手动切换租户
|
||||
boolean isWhiteUrl = SaRouter.isMatch(gatewayWhite.getExcludeUrl(), url) || SaRouter.isMatch(
|
||||
gatewayWhite.getWhiteUrl(), url);
|
||||
if (!isWhiteUrl) {
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
log.error("未检测到租户信息, Tenant: {}, URL: {}, TOKEN: {}", userInfo.getTenantId(), url,
|
||||
userInfo.getToken());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return pjp.proceed();
|
||||
}
|
||||
return pjp.proceed();
|
||||
}
|
||||
|
||||
/**
|
||||
* NoDataSourceBind 不需要绑定数据库的注解 清除租户信息
|
||||
*
|
||||
*/
|
||||
@Around("bindDataSource() && @annotation(jnpf.util.NoDataSourceBind)")
|
||||
public Object doAroundService2(ProceedingJoinPoint pjp) throws Throwable {
|
||||
//Filter中提前设置租户信息, 清除租户信息
|
||||
TenantDataSourceUtil.clearLocalTenantInfo();
|
||||
return pjp.proceed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package ssw.aop;
|
||||
|
||||
import jnpf.config.ConfigValueUtil;
|
||||
import jnpf.constant.MsgCode;
|
||||
import jnpf.exception.DataException;
|
||||
import jnpf.util.PdfUtil;
|
||||
import jnpf.util.XSSEscape;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.x.file.storage.core.FileInfo;
|
||||
import org.dromara.x.file.storage.core.UploadPretreatment;
|
||||
import org.dromara.x.file.storage.core.aspect.DeleteAspectChain;
|
||||
import org.dromara.x.file.storage.core.aspect.DownloadAspectChain;
|
||||
import org.dromara.x.file.storage.core.aspect.DownloadThAspectChain;
|
||||
import org.dromara.x.file.storage.core.aspect.ExistsAspectChain;
|
||||
import org.dromara.x.file.storage.core.aspect.FileStorageAspect;
|
||||
import org.dromara.x.file.storage.core.aspect.UploadAspectChain;
|
||||
import org.dromara.x.file.storage.core.platform.FileStorage;
|
||||
import org.dromara.x.file.storage.core.recorder.FileRecorder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class MyFileAspect implements FileStorageAspect {
|
||||
|
||||
private final ConfigValueUtil configValueUtil;
|
||||
|
||||
@Override
|
||||
public FileInfo uploadAround(UploadAspectChain chain, FileInfo fileInfo, UploadPretreatment pre,
|
||||
FileStorage fileStorage, FileRecorder fileRecorder) {
|
||||
checkFilePath(fileInfo);
|
||||
if (configValueUtil.isCheckFilePdf()) {
|
||||
try {
|
||||
String ext = fileInfo.getExt();
|
||||
if ("pdf".equalsIgnoreCase(ext)) {
|
||||
log.error("检测PDF文件");
|
||||
if (PdfUtil.containsJavaScript(pre.getFileWrapper().getInputStream())) {
|
||||
throw new DataException(MsgCode.FA053.get());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("PDF文档解析失败: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
return FileStorageAspect.super.uploadAround(chain, fileInfo, pre, fileStorage, fileRecorder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteAround(DeleteAspectChain chain, FileInfo fileInfo, FileStorage fileStorage,
|
||||
FileRecorder fileRecorder) {
|
||||
checkFilePath(fileInfo);
|
||||
return FileStorageAspect.super.deleteAround(chain, fileInfo, fileStorage, fileRecorder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsAround(ExistsAspectChain chain, FileInfo fileInfo, FileStorage fileStorage) {
|
||||
checkFilePath(fileInfo);
|
||||
return FileStorageAspect.super.existsAround(chain, fileInfo, fileStorage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadAround(DownloadAspectChain chain, FileInfo fileInfo, FileStorage fileStorage,
|
||||
Consumer<InputStream> consumer) {
|
||||
checkFilePath(fileInfo);
|
||||
FileStorageAspect.super.downloadAround(chain, fileInfo, fileStorage, consumer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadThAround(DownloadThAspectChain chain, FileInfo fileInfo, FileStorage fileStorage,
|
||||
Consumer<InputStream> consumer) {
|
||||
checkFilePath(fileInfo);
|
||||
FileStorageAspect.super.downloadThAround(chain, fileInfo, fileStorage, consumer);
|
||||
}
|
||||
|
||||
private void checkFilePath(FileInfo fileInfo) {
|
||||
//处理特殊文件名
|
||||
fileInfo.setPath(XSSEscape.escapePath(fileInfo.getPath()));
|
||||
fileInfo.setFilename(XSSEscape.escapePath(fileInfo.getFilename()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package ssw.aop;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
|
||||
public interface PermissionAdminBase {
|
||||
|
||||
/**
|
||||
* 管理者权限判断
|
||||
*
|
||||
*/
|
||||
static Object permissionCommon(ProceedingJoinPoint pjp) throws Throwable {
|
||||
|
||||
// 是否是管理员
|
||||
return pjp.proceed();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package ssw.aop;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 角色操作权限
|
||||
*
|
||||
* @author JNPF开发平台组 YanYu
|
||||
* @version V3.2.0
|
||||
* @copyright 引迈信息技术有限公司
|
||||
* @date 2022/2/10
|
||||
*/
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
public class PermissionRoleAspect implements PermissionAdminBase {
|
||||
|
||||
/**
|
||||
* 分级管理切点
|
||||
*/
|
||||
@Pointcut("within(jnpf.*.controller.*) && @annotation(jnpf.annotation.RolePermission)")
|
||||
public void pointcut() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 分级管理切点
|
||||
*
|
||||
* @param pjp
|
||||
* @return
|
||||
* @throws Throwable
|
||||
*/
|
||||
@Around("pointcut()")
|
||||
public Object around(ProceedingJoinPoint pjp) throws Throwable {
|
||||
return PermissionAdminBase.permissionCommon(pjp);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
package ssw.aop;
|
||||
|
||||
import cn.hutool.http.useragent.UserAgent;
|
||||
import cn.hutool.http.useragent.UserAgentUtil;
|
||||
import jnpf.annotation.HandleLog;
|
||||
import jnpf.base.UserInfo;
|
||||
import jnpf.config.ConfigValueUtil;
|
||||
import jnpf.entity.LogEntity;
|
||||
import jnpf.enums.LogSortEnum;
|
||||
import jnpf.service.LogService;
|
||||
import jnpf.util.IpUtil;
|
||||
import jnpf.util.JsonUtil;
|
||||
import jnpf.util.RandomUtil;
|
||||
import jnpf.util.ServletUtil;
|
||||
import jnpf.util.TenantHolder;
|
||||
import jnpf.util.ThreadPoolExecutorUtil;
|
||||
import jnpf.util.UserProvider;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.Signature;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author JNPF开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 引迈信息技术有限公司
|
||||
* @date 2021/3/15 17:12
|
||||
*/
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
@Order(2)
|
||||
@RequiredArgsConstructor
|
||||
public class RequestLogAspect {
|
||||
|
||||
private final ConfigValueUtil configValueUtil;
|
||||
|
||||
private final LogService logService;
|
||||
|
||||
@Pointcut("within(jnpf.*.controller.* || jnpf.controller.*)")// && !within(jnpf.controller.UtilsController)
|
||||
public void requestLog() {
|
||||
|
||||
}
|
||||
|
||||
@Around("requestLog()")
|
||||
public Object doAroundService(ProceedingJoinPoint pjp) throws Throwable {
|
||||
long startTime = System.currentTimeMillis();
|
||||
Object obj = pjp.proceed();
|
||||
if (ServletUtil.getRequest() == null) {
|
||||
return obj;
|
||||
}
|
||||
long costTime = System.currentTimeMillis() - startTime;
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
if (userInfo.getUserId() != null && (!configValueUtil.isMultiTenancy()
|
||||
|| TenantHolder.getLocalTenantCache() != null)) {
|
||||
// 得到请求参数
|
||||
Object[] args = pjp.getArgs();
|
||||
Signature signature = pjp.getSignature();
|
||||
printLog(userInfo, costTime, obj, args, signature);
|
||||
try {
|
||||
// 判断是否需要操作日志
|
||||
MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
|
||||
// 得到请求方法
|
||||
Method method = methodSignature.getMethod();
|
||||
HandleLog methodAnnotation = method.getAnnotation(HandleLog.class);
|
||||
if (methodAnnotation != null) {
|
||||
String moduleName = methodAnnotation.moduleName();
|
||||
handleLog(userInfo, costTime, obj, moduleName, args, signature);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("记录操作日志发生错误:{}", e.getMessage());
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求日志
|
||||
*
|
||||
*/
|
||||
private void printLog(UserInfo userInfo, long costTime, Object obj, Object[] args, Signature signature) {
|
||||
LogEntity entity = new LogEntity();
|
||||
entity.setId(RandomUtil.uuId());
|
||||
entity.setType(LogSortEnum.REQUEST.getCode());
|
||||
entity.setUserId(userInfo.getUserId());
|
||||
entity.setUserName(userInfo.getUserName() + "/" + userInfo.getUserAccount());
|
||||
//请求耗时
|
||||
entity.setRequestDuration((int) costTime);
|
||||
entity.setRequestUrl(ServletUtil.getRequest().getServletPath());
|
||||
entity.setRequestMethod(ServletUtil.getRequest().getMethod());
|
||||
String ipAddr = IpUtil.getIpAddr();
|
||||
entity.setIpAddress(ipAddr);
|
||||
entity.setIpAddressName(IpUtil.getIpCity(ipAddr));
|
||||
entity.setCreatorTime(new Date());
|
||||
UserAgent userAgent = UserAgentUtil.parse(ServletUtil.getUserAgent());
|
||||
if (userAgent != null) {
|
||||
entity.setPlatForm(userAgent.getPlatform().getName() + " " + userAgent.getOsVersion());
|
||||
entity.setBrowser(userAgent.getBrowser().getName() + " " + userAgent.getVersion());
|
||||
}
|
||||
String declaringTypeName = signature.getDeclaringTypeName();
|
||||
String name = signature.getName();
|
||||
entity.setRequestTarget(declaringTypeName + "." + name);
|
||||
entity.setJsons(obj + "");
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (Object o : args) {
|
||||
// 如果是MultipartFile则为导入
|
||||
if (o instanceof MultipartFile) {
|
||||
stringBuilder.append("{\"originalFilename\":\"")
|
||||
.append(((MultipartFile) o).getOriginalFilename())
|
||||
.append("\",");
|
||||
stringBuilder.append("\"contentType\":\"").append(((MultipartFile) o).getContentType()).append("\",");
|
||||
stringBuilder.append("\"name\":\"").append(((MultipartFile) o).getName()).append("\",");
|
||||
stringBuilder.append("\"resource\":\"").append(((MultipartFile) o).getResource()).append("\",");
|
||||
stringBuilder.append("\"size\":\"").append(((MultipartFile) o).getSize()).append("\"}");
|
||||
}
|
||||
}
|
||||
if (stringBuilder.length() > 0) {
|
||||
entity.setRequestParam(stringBuilder.toString());
|
||||
} else {
|
||||
entity.setRequestParam(JsonUtil.getObjectToString(args));
|
||||
}
|
||||
ThreadPoolExecutorUtil.getExecutor().execute(() -> logService.save(entity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加操作日志
|
||||
*
|
||||
* @param userInfo 用户信息
|
||||
* @param costTime 操作耗时
|
||||
* @param obj 请求结果
|
||||
* @param moduleName 模块名称
|
||||
* @param args 请求参数
|
||||
*/
|
||||
private void handleLog(UserInfo userInfo, long costTime, Object obj, String moduleName, Object[] args,
|
||||
Signature signature) {
|
||||
LogEntity entity = new LogEntity();
|
||||
entity.setId(RandomUtil.uuId());
|
||||
entity.setType(LogSortEnum.OPERATE.getCode());
|
||||
entity.setUserId(userInfo.getUserId());
|
||||
entity.setUserName(userInfo.getUserName() + "/" + userInfo.getUserAccount());
|
||||
//请求耗时
|
||||
entity.setRequestDuration((int) costTime);
|
||||
entity.setRequestMethod(ServletUtil.getRequest().getMethod());
|
||||
entity.setRequestUrl(ServletUtil.getRequest().getServletPath());
|
||||
String ipAddr = IpUtil.getIpAddr();
|
||||
entity.setIpAddress(ipAddr);
|
||||
entity.setIpAddressName(IpUtil.getIpCity(ipAddr));
|
||||
entity.setCreatorTime(new Date());
|
||||
// 请求设备
|
||||
UserAgent userAgent = UserAgentUtil.parse(ServletUtil.getUserAgent());
|
||||
if (userAgent != null) {
|
||||
entity.setPlatForm(userAgent.getPlatform().getName() + " " + userAgent.getOsVersion());
|
||||
entity.setBrowser(userAgent.getBrowser().getName() + " " + userAgent.getVersion());
|
||||
}
|
||||
// 操作模块
|
||||
entity.setModuleName(moduleName);
|
||||
String declaringTypeName = signature.getDeclaringTypeName();
|
||||
String name = signature.getName();
|
||||
entity.setRequestTarget(declaringTypeName + "." + name);
|
||||
// 操作记录
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (Object o : args) {
|
||||
// 如果是MultipartFile则为导入
|
||||
if (o instanceof MultipartFile) {
|
||||
stringBuilder.append("{\"originalFilename\":\"")
|
||||
.append(((MultipartFile) o).getOriginalFilename())
|
||||
.append("\",");
|
||||
stringBuilder.append("\"contentType\":\"").append(((MultipartFile) o).getContentType()).append("\",");
|
||||
stringBuilder.append("\"name\":\"").append(((MultipartFile) o).getName()).append("\",");
|
||||
stringBuilder.append("\"resource\":\"").append(((MultipartFile) o).getResource()).append("\",");
|
||||
stringBuilder.append("\"size\":\"").append(((MultipartFile) o).getSize()).append("\"}");
|
||||
}
|
||||
}
|
||||
if (stringBuilder.length() > 0) {
|
||||
entity.setRequestParam(stringBuilder.toString());
|
||||
} else {
|
||||
entity.setRequestParam(JsonUtil.getObjectToString(args));
|
||||
}
|
||||
entity.setJsons(obj + "");
|
||||
ThreadPoolExecutorUtil.getExecutor().execute(() -> logService.save(entity));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package ssw.constant;
|
||||
|
||||
/**
|
||||
* 分级管理常量
|
||||
*
|
||||
* @author JNPF开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 引迈信息技术有限公司(<a href="https://www.jnpfsoft.com">...</a>)
|
||||
* @date 2021-11-01
|
||||
*/
|
||||
public class PermissionConstant {
|
||||
|
||||
/**
|
||||
* 创建方法
|
||||
*/
|
||||
public static final String METHOD_CREATE = "create";
|
||||
|
||||
/**
|
||||
* 编辑方法
|
||||
*/
|
||||
public static final String METHOD_UPDATE = "update";
|
||||
|
||||
/**
|
||||
* 删除方法
|
||||
*/
|
||||
public static final String METHOD_DELETE = "delete";
|
||||
|
||||
/**
|
||||
* 更新状态
|
||||
*/
|
||||
public static final String METHOD_DISABLE = "disable";
|
||||
|
||||
/**
|
||||
* 创建方法
|
||||
*/
|
||||
public static final String METHOD_CREATE_DEPARTMENT = "createDepartment";
|
||||
|
||||
/**
|
||||
* 编辑方法
|
||||
*/
|
||||
public static final String METHOD_UPDATE_DEPARTMENT = "updateDepartment";
|
||||
|
||||
/**
|
||||
* 删除方法
|
||||
*/
|
||||
public static final String METHOD_DELETE_DEPARTMENT = "deleteDepartment";
|
||||
|
||||
/**
|
||||
* 保存方法
|
||||
*/
|
||||
public static final String METHOD_SAVE = "save";
|
||||
|
||||
public static final String METHOD_SAVE_BATCH = "saveBatch";
|
||||
|
||||
/**
|
||||
* 修改用户密码
|
||||
*/
|
||||
public static final String METHOD_MODIFY_PW = "modifyPassword";
|
||||
|
||||
/**
|
||||
* 拼接方法名
|
||||
*/
|
||||
public static final String GET_METHOD_CREATE = "Add";
|
||||
|
||||
public static final String GET_METHOD_UPDATE = "Edit";
|
||||
|
||||
public static final String GET_METHOD_DELETE = "Delete";
|
||||
|
||||
public static final String GET_METHOD_SELECT = "Select";
|
||||
|
||||
public static final String GET_METHOD_THIS = "getThisLayer";
|
||||
|
||||
public static final String GET_METHOD_SUB = "getSubLayer";
|
||||
|
||||
/**
|
||||
* 解除绑定方法
|
||||
*/
|
||||
public static final String METHOD_DELETE_SOCIALS = "deleteSocials";
|
||||
|
||||
private PermissionConstant() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package ssw.filter;
|
||||
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.dev33.satoken.filter.SaFilterAuthStrategy;
|
||||
import cn.dev33.satoken.filter.SaServletFilter;
|
||||
import cn.dev33.satoken.router.SaRouter;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.util.SaResult;
|
||||
import jnpf.base.ActionResultCode;
|
||||
import jnpf.constant.MsgCode;
|
||||
import jnpf.consts.AuthConsts;
|
||||
import jnpf.properties.GatewayWhite;
|
||||
import jnpf.util.Constants;
|
||||
import jnpf.util.DesUtil;
|
||||
import ssw.util.GatewayUtil;
|
||||
import jnpf.util.IpUtil;
|
||||
import jnpf.util.StringUtil;
|
||||
import jnpf.util.UserProvider;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 网关验证token
|
||||
*
|
||||
* @author JNPF开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 引迈信息技术有限公司(<a href="https://www.jnpfsoft.com">...</a>)
|
||||
* @date 2021-03-24
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class AuthFilter {
|
||||
|
||||
private final GatewayWhite gatewayWhite;
|
||||
|
||||
private final SaFilterAuthStrategy defaultBeforeAuthStrategy;
|
||||
|
||||
public static String getIpAddr() {
|
||||
return IpUtil.getIpAddr();
|
||||
}
|
||||
|
||||
// 注册 Sa-Token全局过滤器
|
||||
@Bean
|
||||
public SaServletFilter getSaReactorFilter() {
|
||||
return new SaServletFilter()
|
||||
// 拦截地址
|
||||
.addInclude("/**").setExcludeList(gatewayWhite.getExcludeUrl())
|
||||
// 鉴权方法:每次访问进入
|
||||
.setAuth(obj -> {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("请求路径: {}", SaHolder.getRequest().getRequestPath());
|
||||
}
|
||||
//拦截路径
|
||||
SaRouter.match(gatewayWhite.getBlockUrl()).match(o -> {
|
||||
//禁止访问URL 排除白名单
|
||||
String ip = getIpAddr();
|
||||
for (String o1 : gatewayWhite.getWhiteIp()) {
|
||||
if (ip.startsWith(o1)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
log.info("非白名单IP访问限制接口:{}, {}", SaHolder.getRequest().getRequestPath(), ip);
|
||||
return false;
|
||||
}).back(MsgCode.AD101.get());
|
||||
//白名单不拦截
|
||||
SaRouter.match(gatewayWhite.getWhiteUrl()).stop();
|
||||
//内部请求不拦截
|
||||
SaRouter.match(t -> {
|
||||
String innerToken = SaHolder.getRequest().getHeader(AuthConsts.INNER_TOKEN_KEY);
|
||||
return UserProvider.isValidInnerToken(innerToken);
|
||||
}).stop();
|
||||
// AppSecret校验
|
||||
SaRouter.match(gatewayWhite.getAppSecretUrl()).check(() -> {
|
||||
String innerToken = SaHolder.getRequest().getHeader(Constants.AUTHORIZATION);
|
||||
try {
|
||||
if (StringUtil.isNotEmpty(innerToken) && innerToken.toLowerCase()
|
||||
.startsWith(AuthConsts.TOKEN_PREFIX_SP)) {
|
||||
innerToken = innerToken.substring(AuthConsts.TOKEN_PREFIX_SP.length());
|
||||
}
|
||||
DesUtil.aesOrDecode(innerToken, false, true);
|
||||
} catch (Exception e) {
|
||||
throw NotLoginException.newInstance(null, null, MsgCode.SYS125.get(), null);
|
||||
}
|
||||
}).stop();
|
||||
// 登录校验 -- 拦截所有路由
|
||||
SaRouter.match("/**", r -> {
|
||||
StpUtil.checkLogin();
|
||||
GatewayUtil.renewToken(StpUtil.getTokenValue());
|
||||
}).stop();
|
||||
}).setError(e -> {
|
||||
SaHolder.getResponse().addHeader("Content-Type", "application/json; charset=utf-8");
|
||||
if (e instanceof NotLoginException) {
|
||||
return SaResult.error(ActionResultCode.SESSIONOVERDUE.getMessage())
|
||||
.setCode(ActionResultCode.SESSIONOVERDUE.getCode());
|
||||
}
|
||||
log.error(e.getMessage(), e);
|
||||
return SaResult.error(MsgCode.AD102.get()).setCode(ActionResultCode.EXCEPTION.getCode());
|
||||
})
|
||||
// 前置函数:在每次认证函数之前执行
|
||||
.setBeforeAuth(defaultBeforeAuthStrategy);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package ssw.filter;
|
||||
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import cn.dev33.satoken.context.model.SaRequest;
|
||||
import cn.dev33.satoken.context.model.SaResponse;
|
||||
import cn.dev33.satoken.filter.SaFilterAuthStrategy;
|
||||
import cn.dev33.satoken.router.SaRouter;
|
||||
import jnpf.properties.MvcSecurityProperties;
|
||||
import jnpf.util.Constants;
|
||||
import jnpf.util.IpUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.CorsConfigurationSource;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* mvc配置
|
||||
*
|
||||
* @author JNPF开发平台组
|
||||
* @version V5.0.0
|
||||
* @copyright 引迈信息技术有限公司(<a href="https://www.jnpfsoft.com">...</a>)
|
||||
* @date 2025-01-21
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@RequiredArgsConstructor
|
||||
public class MvcSecurityConfig {
|
||||
|
||||
private static final String DOMAIN_FORMAT = "%s://%s";
|
||||
|
||||
private final MvcSecurityProperties mvcSecurityProperties;
|
||||
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
// 允许发送凭据
|
||||
config.setAllowCredentials(true);
|
||||
//允许任意域名跨域访问接口
|
||||
config.setAllowedOrigins(mvcSecurityProperties.getCors().getAllowedOrigins());
|
||||
config.setAllowedOriginPatterns(mvcSecurityProperties.getCors().getAllowedOriginPatterns());
|
||||
// 允许所有头部信息
|
||||
config.setAllowedHeaders(mvcSecurityProperties.getCors().getAllowedHeaders());
|
||||
// 允许所有请求方法
|
||||
config.setAllowedMethods(mvcSecurityProperties.getCors().getAllowedMethods());
|
||||
// 应用于所有路径
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
return new MyCorsFilter(source);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public SaFilterAuthStrategy defaultBeforeAuthStrategy() {
|
||||
CorsConfiguration csrfConfiguration;
|
||||
if (!mvcSecurityProperties.getCsrfOrigins().isEmpty() || !mvcSecurityProperties.getCsrfOriginsPatterns()
|
||||
.isEmpty()) {
|
||||
csrfConfiguration = new CorsConfiguration();
|
||||
csrfConfiguration.setAllowedOrigins(mvcSecurityProperties.getCsrfOrigins());
|
||||
csrfConfiguration.setAllowedOriginPatterns(mvcSecurityProperties.getCsrfOriginsPatterns());
|
||||
} else {
|
||||
csrfConfiguration = null;
|
||||
}
|
||||
return obj -> {
|
||||
SaRequest request = SaHolder.getRequest();
|
||||
// ---------- 设置跨域响应头 ----------
|
||||
SaResponse response = SaHolder.getResponse();
|
||||
if (!ObjectUtils.isEmpty(mvcSecurityProperties.getHeaders().getServerName())) {
|
||||
response.setServer(mvcSecurityProperties.getHeaders().getServerName());
|
||||
}
|
||||
if (!ObjectUtils.isEmpty(mvcSecurityProperties.getHeaders().getXFrameOptions())
|
||||
&& !MvcSecurityProperties.XFrameOptionsMode.DISABLED.equals(
|
||||
mvcSecurityProperties.getHeaders().getXFrameOptions())) {
|
||||
response.setHeader(MvcSecurityProperties.HEADER_XFRAME_OPTIONS,
|
||||
mvcSecurityProperties.getHeaders().getXFrameOptions().getMode());
|
||||
}
|
||||
if (!ObjectUtils.isEmpty(mvcSecurityProperties.getHeaders().getXXssProtection())
|
||||
&& !MvcSecurityProperties.XXssProtectionMode.DISABLED.equals(
|
||||
mvcSecurityProperties.getHeaders().getXXssProtection())) {
|
||||
response.setHeader(MvcSecurityProperties.HEADER_XSS_PROTECTION,
|
||||
mvcSecurityProperties.getHeaders().getXXssProtection().getMode());
|
||||
}
|
||||
if (!ObjectUtils.isEmpty(mvcSecurityProperties.getHeaders().getXContentTypeOptions())
|
||||
&& !MvcSecurityProperties.XContentTypeOptions.DISABLED.equals(
|
||||
mvcSecurityProperties.getHeaders().getXContentTypeOptions())) {
|
||||
response.setHeader(MvcSecurityProperties.HEADER_CONTENT_TYPE_OPTIONS,
|
||||
mvcSecurityProperties.getHeaders().getXContentTypeOptions().getMode());
|
||||
}
|
||||
|
||||
if (csrfConfiguration != null) {
|
||||
String referer = request.getHeader("referer");
|
||||
if (!ObjectUtils.isEmpty(referer)) {
|
||||
URI uri = URI.create(referer);
|
||||
String refererDomain = String.format(DOMAIN_FORMAT, uri.getScheme(), uri.getAuthority());
|
||||
String allowOrign = csrfConfiguration.checkOrigin(refererDomain);
|
||||
if (ObjectUtils.isEmpty(allowOrign)) {
|
||||
log.error("Reject CSRF Request: {}, {}, {}, {}", request.getRequestPath(), referer,
|
||||
IpUtil.getIpAddr(), request.getHeader(Constants.AUTHORIZATION));
|
||||
response.setStatus(HttpStatus.FORBIDDEN.value());
|
||||
SaRouter.back("Invalid CSRF Request");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Order(-110)
|
||||
public static class MyCorsFilter extends CorsFilter {
|
||||
|
||||
public MyCorsFilter(CorsConfigurationSource configSource) {
|
||||
super(configSource);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package ssw.util;
|
||||
|
||||
import cn.hutool.cache.CacheUtil;
|
||||
import cn.hutool.cache.impl.TimedCache;
|
||||
import jnpf.util.UserProvider;
|
||||
|
||||
/**
|
||||
* 网关工具类
|
||||
*/
|
||||
public class GatewayUtil {
|
||||
|
||||
private static final long TIMEOUT = 1000L * 60;
|
||||
|
||||
private static TimedCache<String, Integer> renewLimit = null;
|
||||
|
||||
static {
|
||||
renewLimit = CacheUtil.newTimedCache(TIMEOUT);
|
||||
// 一分钟清理一次无用数据
|
||||
renewLimit.schedulePrune(TIMEOUT);
|
||||
}
|
||||
|
||||
private GatewayUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 同一个TOKEN一分钟内只会续期一次
|
||||
*/
|
||||
public static void renewToken(String token) {
|
||||
if (renewLimit.containsKey(token)) {
|
||||
return;
|
||||
}
|
||||
UserProvider.renewTimeout(token);
|
||||
renewLimit.put(token, 0);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user