diff --git a/backend/app/src/main/java/io/metersphere/config/MybatisConfig.java b/backend/app/src/main/java/io/metersphere/config/MybatisConfig.java index e208c7c194..8bc081d586 100644 --- a/backend/app/src/main/java/io/metersphere/config/MybatisConfig.java +++ b/backend/app/src/main/java/io/metersphere/config/MybatisConfig.java @@ -1,21 +1,45 @@ package io.metersphere.config; +import com.fit2cloud.quartz.anno.QuartzDataSource; +import com.github.pagehelper.PageInterceptor; +import com.zaxxer.hikari.HikariDataSource; import io.metersphere.sdk.interceptor.MybatisInterceptor; +import io.metersphere.sdk.interceptor.UserDesensitizationInterceptor; import io.metersphere.sdk.util.CompressUtils; import io.metersphere.sdk.util.MybatisInterceptorConfig; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; import org.springframework.transaction.annotation.EnableTransactionManagement; +import javax.sql.DataSource; import java.util.ArrayList; import java.util.List; +import java.util.Properties; @Configuration @MapperScan(basePackages = {"io.metersphere.*.mapper"}, sqlSessionFactoryRef = "sqlSessionFactory") @EnableTransactionManagement public class MybatisConfig { + @Bean + @ConditionalOnMissingBean + public PageInterceptor pageInterceptor() { + PageInterceptor pageInterceptor = new PageInterceptor(); + Properties properties = new Properties(); + properties.setProperty("helperDialect", "mysql"); + properties.setProperty("rowBoundsWithCount", "true"); + properties.setProperty("reasonable", "true"); + properties.setProperty("offsetAsPageNum", "true"); + properties.setProperty("pageSizeZero", "true"); + pageInterceptor.setProperties(properties); + return pageInterceptor; + } + @Bean @ConditionalOnMissingBean public MybatisInterceptor dbInterceptor() { @@ -30,4 +54,34 @@ public class MybatisConfig { return interceptor; } + @Bean + public UserDesensitizationInterceptor userDesensitizationInterceptor() { + return new UserDesensitizationInterceptor(); + } + + + @Bean + @Primary + @ConfigurationProperties(prefix = "spring.datasource.hikari") + public DataSource dataSource(DataSourceProperties properties) { + return DataSourceBuilder.create(properties.getClassLoader()).type(HikariDataSource.class) + .driverClassName(properties.determineDriverClassName()) + .url(properties.determineUrl()) + .username(properties.determineUsername()) + .password(properties.determinePassword()) + .build(); + } + + @Bean + @ConfigurationProperties(prefix = "spring.datasource.quartz.hikari") + @QuartzDataSource + public DataSource quartzDataSource(DataSourceProperties properties) { + return DataSourceBuilder.create(properties.getClassLoader()).type(HikariDataSource.class) + .driverClassName(properties.determineDriverClassName()) + .url(properties.determineUrl()) + .username(properties.determineUsername()) + .password(properties.determinePassword()) + .build(); + } + } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/interceptor/UserDesensitizationInterceptor.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/interceptor/UserDesensitizationInterceptor.java new file mode 100644 index 0000000000..396414373e --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/interceptor/UserDesensitizationInterceptor.java @@ -0,0 +1,59 @@ +package io.metersphere.sdk.interceptor; + +import io.metersphere.domain.User; +import org.apache.ibatis.cache.CacheKey; +import org.apache.ibatis.executor.Executor; +import org.apache.ibatis.mapping.BoundSql; +import org.apache.ibatis.mapping.MappedStatement; +import org.apache.ibatis.plugin.*; +import org.apache.ibatis.session.ResultHandler; +import org.apache.ibatis.session.RowBounds; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +/** + * 用户 password 字段脱敏 + */ +@Intercepts({ + @Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}), + @Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class}), +}) +public class UserDesensitizationInterceptor implements Interceptor { + + @Override + public Object intercept(Invocation invocation) throws Throwable { + Object returnValue = invocation.proceed(); + Object result = returnValue; + if (returnValue instanceof ArrayList) { + List list = new ArrayList<>(); + boolean isDecrypted = false; + for (Object val : (ArrayList) returnValue) { + if (val instanceof User) { + isDecrypted = true; + ((User) val).setPassword(null); + list.add(val); + } + } + if (isDecrypted) { + result = list; + } + } else { + if (result instanceof User) { + ((User) result).setPassword(null); + } + } + return result; + } + + + @Override + public Object plugin(Object target) { + return Plugin.wrap(target, this); + } + + @Override + public void setProperties(Properties properties) { + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5a3c83b479..cc9f19b6cb 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ 3.x 17 - 2.7.18 + 2.7.22 1.5.0 1.11.0 1.5.3 @@ -30,7 +30,7 @@ 5.3.2 1.5 1.0.7 - 3.20.0 + 3.20.1 5.1.0 3.0.1 0.10.2