Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea26c0fcd7 | ||
|
|
9d5f0c05cb |
No files matched your search
@@ -10,11 +10,7 @@
|
||||
</parent>
|
||||
|
||||
<artifactId>crabc-admin</artifactId>
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.crabc</groupId>
|
||||
|
||||
@@ -3,7 +3,7 @@ server:
|
||||
port: 9377
|
||||
spring:
|
||||
application:
|
||||
name: crabc-admin
|
||||
name: crabc-api
|
||||
main:
|
||||
banner-mode: off
|
||||
jackson:
|
||||
|
||||
@@ -10,12 +10,6 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>crabc-core</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
||||
@@ -8,10 +8,11 @@ import cn.crabc.core.app.util.ApiThreadLocal;
|
||||
import cn.crabc.core.app.util.Result;
|
||||
import cn.crabc.core.datasource.constant.BaseConstant;
|
||||
import cn.crabc.core.datasource.enums.ErrorStatusEnum;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package cn.crabc.core.app.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@@ -16,7 +14,6 @@ import java.util.Date;
|
||||
@Setter
|
||||
@Getter
|
||||
public class BaseEntity implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package cn.crabc.core.app.exception;
|
||||
import cn.crabc.core.app.util.Result;
|
||||
import cn.crabc.core.datasource.exception.CustomException;
|
||||
import cn.crabc.core.spi.PluginException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package cn.crabc.core.app.filter;
|
||||
|
||||
import cn.crabc.core.app.util.ApiThreadLocal;
|
||||
import cn.crabc.core.app.util.UserThreadLocal;
|
||||
import jakarta.servlet.*;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.util.ContentCachingResponseWrapper;
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ import cn.crabc.core.app.util.SM3Util;
|
||||
import cn.crabc.core.datasource.enums.ErrorStatusEnum;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -72,13 +72,16 @@ public class AuthInterceptor implements HandlerInterceptor {
|
||||
try {
|
||||
// 应用列表
|
||||
List<BaseApp> appList = apiInfo.getAppList();
|
||||
|
||||
return switch (apiInfo.getAuthType().toUpperCase()) {
|
||||
case "APP_CODE" -> checkAppCode(request,response, appList);
|
||||
case "APP_KEY" -> checkAppKey(request,response, appList);
|
||||
case "APP_SECRET" -> checkSM3(request,response, appList);
|
||||
default -> true;
|
||||
};
|
||||
switch (apiInfo.getAuthType().toUpperCase()) {
|
||||
case "APP_CODE":
|
||||
return checkAppCode(request, response, appList);
|
||||
case "APP_KEY":
|
||||
return checkAppKey(request, response, appList);
|
||||
case "APP_SECRET":
|
||||
return checkSM3(request, response, appList);
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}catch (Exception e) {
|
||||
setErrorResponse(request,response,ErrorStatusEnum.API_UN_AUTH.getCode(),ErrorStatusEnum.API_UN_AUTH.getMassage());
|
||||
return false;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package cn.crabc.core.app.filter;
|
||||
|
||||
import jakarta.servlet.ReadListener;
|
||||
import jakarta.servlet.ServletInputStream;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletRequestWrapper;
|
||||
import javax.servlet.ReadListener;
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequestWrapper;
|
||||
import org.apache.tomcat.util.http.fileupload.IOUtils;
|
||||
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import cn.crabc.core.app.util.UserThreadLocal;
|
||||
import cn.crabc.core.datasource.enums.ErrorStatusEnum;
|
||||
import cn.crabc.core.datasource.exception.CustomException;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
+1
-2
@@ -11,15 +11,14 @@ import cn.crabc.core.datasource.driver.DataSourceManager;
|
||||
import cn.crabc.core.spi.bean.BaseDataSource;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
|
||||
@@ -3,7 +3,7 @@ package cn.crabc.core.app.util;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package cn.crabc.core.app.util;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.bouncycastle.crypto.digests.SM3Digest;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.Security;
|
||||
import java.util.HexFormat;
|
||||
|
||||
/**
|
||||
* 国密SM3加密工具类
|
||||
@@ -36,7 +36,7 @@ public class SM3Util {
|
||||
digest.update(bytes, 0, bytes.length);
|
||||
byte[] result = new byte[digest.getDigestSize()];
|
||||
digest.doFinal(result, 0);
|
||||
return HexFormat.of().formatHex(result);
|
||||
return new String(Hex.encodeHex(result));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,11 +10,6 @@
|
||||
</parent>
|
||||
|
||||
<artifactId>crabc-datasource</artifactId>
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -31,11 +26,6 @@
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>${spring-boot.mybatis.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
|
||||
+11
-2
@@ -73,9 +73,11 @@ public class JdbcDataSourceRouter extends AbstractRoutingDataSource {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (dataSource instanceof DruidDataSource druidDataSource) {
|
||||
if (dataSource instanceof DruidDataSource) {
|
||||
DruidDataSource druidDataSource = (DruidDataSource) dataSource;
|
||||
druidDataSource.close();
|
||||
} else if (dataSource instanceof HikariDataSource hikariDataSource) {
|
||||
} else if (dataSource instanceof HikariDataSource) {
|
||||
HikariDataSource hikariDataSource = (HikariDataSource) dataSource;
|
||||
hikariDataSource.close();
|
||||
}
|
||||
} finally {
|
||||
@@ -157,6 +159,13 @@ public class JdbcDataSourceRouter extends AbstractRoutingDataSource {
|
||||
}
|
||||
return connection;
|
||||
} catch (Exception e) {
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException closeException) {
|
||||
log.error("关闭连接时发生异常", closeException);
|
||||
}
|
||||
}
|
||||
log.error("数据源连接获取失败, dataSourceKey: {}", dataSourceKey, e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
+14
-6
@@ -62,23 +62,31 @@ public abstract class DefaultDataSourceDriver implements DataSourceDriver {
|
||||
|
||||
HikariDataSource dataSource = createHikariDataSource(ds, false);
|
||||
JdbcDataSourceRouter.setDataSource(datasourceId, dataSource);
|
||||
boolean initSuccess = false;
|
||||
// 连接池预热
|
||||
try (Connection conn = dataSource.getConnection()) {
|
||||
if (conn.isValid(1)) {
|
||||
initSuccess = true;
|
||||
log.debug("数据源初始化成功.");
|
||||
} else {
|
||||
log.error("数据源初始化失败.");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.error("Failed to warm up DataSource. Shutting down.", e);
|
||||
dataSource.close(); // 初始化失败,及时释放资源
|
||||
}
|
||||
if (oldDataSource != null){
|
||||
if (oldDataSource instanceof DruidDataSource) {
|
||||
((DruidDataSource) oldDataSource).close();
|
||||
} else if (oldDataSource instanceof HikariDataSource) {
|
||||
((HikariDataSource) oldDataSource).close();
|
||||
// 仅在初始化成功时才添加到路由池
|
||||
if (initSuccess) {
|
||||
JdbcDataSourceRouter.setDataSource(datasourceId, dataSource);
|
||||
// 关闭旧数据源
|
||||
if (oldDataSource != null){
|
||||
if (oldDataSource instanceof DruidDataSource) {
|
||||
((DruidDataSource) oldDataSource).close();
|
||||
} else if (oldDataSource instanceof HikariDataSource) {
|
||||
((HikariDataSource) oldDataSource).close();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dataSource.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,4 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>crabc-spi</artifactId>
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -1,140 +0,0 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.5.9</version>
|
||||
</parent>
|
||||
|
||||
<name>crabc-spring-boot-starter</name>
|
||||
<groupId>cn.crabc</groupId>
|
||||
<artifactId>crabc-spring-boot-starter</artifactId>
|
||||
<version>4.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
<description>Low code tools</description>
|
||||
<url>https://github.com/pingapi/crabc-api</url>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache License, Version 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<id>crabc</id>
|
||||
<name>crabc</name>
|
||||
<email>creabc@qq.com</email>
|
||||
</developer>
|
||||
</developers>
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.crabc</groupId>
|
||||
<artifactId>crabc-core</artifactId>
|
||||
<version>4.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>3.2.8</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.sonatype.central</groupId>
|
||||
<artifactId>central-publishing-maven-plugin</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<publishingServerId>central</publishingServerId>
|
||||
<autoPublish>true</autoPublish>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.3.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.2.5</version>
|
||||
</plugin>
|
||||
<!-- Javadoc plugin -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>ossrh</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>ossrh</id>
|
||||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>ossrh</id>
|
||||
<properties>
|
||||
<gpg.executable>gpg</gpg.executable>
|
||||
<gpg.passphrase>Crabc123</gpg.passphrase>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
</project>
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023, crabc.cn (creabc@qq.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.crabc.core.starter;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@MapperScan({"cn.crabc.core.*.mapper"})
|
||||
@ComponentScan("cn.crabc.core")
|
||||
@Configuration
|
||||
public class CrabcConfiguration {
|
||||
}
|
||||
-1
@@ -1 +0,0 @@
|
||||
cn.crabc.core.starter.CrabcConfiguration
|
||||
@@ -12,21 +12,19 @@
|
||||
<description>接口开发平台</description>
|
||||
<modules>
|
||||
<module>crabc-api</module>
|
||||
<!-- <module>crabc-spring-boot-starter</module>-->
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<!-- crabc 版本-->
|
||||
<revision>4.0.0</revision>
|
||||
<java.version>17</java.version>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<revision>2.9.0</revision>
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<spring-boot.version>3.5.9</spring-boot.version>
|
||||
<spring-boot.mybatis.version>3.0.5</spring-boot.mybatis.version>
|
||||
<mybatis-plus.version>3.5.15</mybatis-plus.version>
|
||||
<pagehelper.boot.version>2.1.1</pagehelper.boot.version>
|
||||
<spring-boot.druid.version>1.2.27</spring-boot.druid.version>
|
||||
<spring-boot.version>2.7.18</spring-boot.version>
|
||||
<spring-boot.mybatis.version>2.3.2</spring-boot.mybatis.version>
|
||||
<pagehelper.boot.version>2.1.0</pagehelper.boot.version>
|
||||
<spring-boot.druid.version>1.2.25</spring-boot.druid.version>
|
||||
<fastjson.version>2.0.49</fastjson.version>
|
||||
<jwt.version>0.12.5</jwt.version>
|
||||
<commons-pool2.version>2.12.0</commons-pool2.version>
|
||||
|
||||
Reference in new issue
Block a user