修改相关资源路径
This commit is contained in:
@@ -14,7 +14,7 @@ FROM eclipse-temurin:17-jre-alpine
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# 复制部署结构:bin/ libs/ etc/
|
# 复制部署结构:bin/ libs/ etc/
|
||||||
COPY --from=builder /app/src/main/scripts/start.sh bin/start.sh
|
COPY --from=builder /app/scripts/start.sh bin/start.sh
|
||||||
COPY --from=builder /app/target/libs/ libs/
|
COPY --from=builder /app/target/libs/ libs/
|
||||||
COPY --from=builder /app/src/main/resources/application.yml etc/application.yml
|
COPY --from=builder /app/src/main/resources/application.yml etc/application.yml
|
||||||
COPY --from=builder /app/src/main/resources/logback.xml etc/logback.xml
|
COPY --from=builder /app/src/main/resources/logback.xml etc/logback.xml
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<!-- bin/start.sh(0755 可执行) -->
|
<!-- bin/start.sh(0755 可执行) -->
|
||||||
<files>
|
<files>
|
||||||
<file>
|
<file>
|
||||||
<source>src/main/scripts/start.sh</source>
|
<source>scripts/start.sh</source>
|
||||||
<outputDirectory>bin</outputDirectory>
|
<outputDirectory>bin</outputDirectory>
|
||||||
<fileMode>0755</fileMode>
|
<fileMode>0755</fileMode>
|
||||||
</file>
|
</file>
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
<!-- logs/ 空目录占位 -->
|
<!-- logs/ 空目录占位 -->
|
||||||
<fileSet>
|
<fileSet>
|
||||||
<directory>src/main/assembly/empty-logs</directory>
|
<directory>assembly/empty-logs</directory>
|
||||||
<outputDirectory>logs</outputDirectory>
|
<outputDirectory>logs</outputDirectory>
|
||||||
</fileSet>
|
</fileSet>
|
||||||
</fileSets>
|
</fileSets>
|
||||||
@@ -11,7 +11,7 @@ services:
|
|||||||
- "5432:5432"
|
- "5432:5432"
|
||||||
volumes:
|
volumes:
|
||||||
- postgres_data:/var/lib/postgresql/data
|
- postgres_data:/var/lib/postgresql/data
|
||||||
- ./sql/init.sql:/docker-entrypoint-initdb.d/init.sql
|
- ./src/main/resources/sql/init.sql:/docker-entrypoint-initdb.d/init.sql
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD-SHELL", "pg_isready -U label -d label_db"]
|
test: ["CMD-SHELL", "pg_isready -U label -d label_db"]
|
||||||
interval: 10s
|
interval: 10s
|
||||||
|
|||||||
12
pom.xml
12
pom.xml
@@ -132,6 +132,14 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<excludes>
|
||||||
|
<exclude>sql/**</exclude>
|
||||||
|
</excludes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
<!-- 薄 jar:仅打包编译后的 class,输出到 target/libs/ -->
|
<!-- 薄 jar:仅打包编译后的 class,输出到 target/libs/ -->
|
||||||
<plugin>
|
<plugin>
|
||||||
@@ -178,7 +186,7 @@
|
|||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<descriptors>
|
<descriptors>
|
||||||
<descriptor>src/main/assembly/distribution.xml</descriptor>
|
<descriptor>assembly/distribution.xml</descriptor>
|
||||||
</descriptors>
|
</descriptors>
|
||||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||||
<appendAssemblyId>false</appendAssemblyId>
|
<appendAssemblyId>false</appendAssemblyId>
|
||||||
@@ -188,4 +196,4 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
package com.label.common.context;
|
|
||||||
|
|
||||||
import com.label.common.auth.TokenPrincipal;
|
|
||||||
|
|
||||||
public final class UserContext {
|
|
||||||
private static final ThreadLocal<TokenPrincipal> PRINCIPAL = new ThreadLocal<>();
|
|
||||||
|
|
||||||
public static void set(TokenPrincipal principal) {
|
|
||||||
PRINCIPAL.set(principal);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TokenPrincipal get() {
|
|
||||||
return PRINCIPAL.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void clear() {
|
|
||||||
PRINCIPAL.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
private UserContext() {
|
|
||||||
throw new UnsupportedOperationException("Utility class");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -14,7 +14,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import com.label.annotation.RequireRole;
|
import com.label.annotation.RequireRole;
|
||||||
import com.label.common.auth.TokenPrincipal;
|
import com.label.common.auth.TokenPrincipal;
|
||||||
import com.label.common.context.CompanyContext;
|
import com.label.common.context.CompanyContext;
|
||||||
import com.label.common.context.UserContext;
|
|
||||||
import com.label.common.result.Result;
|
import com.label.common.result.Result;
|
||||||
import com.label.service.RedisService;
|
import com.label.service.RedisService;
|
||||||
import com.label.util.RedisUtil;
|
import com.label.util.RedisUtil;
|
||||||
@@ -79,7 +78,6 @@ public class AuthInterceptor implements HandlerInterceptor {
|
|||||||
@Override
|
@Override
|
||||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
|
||||||
Object handler, Exception ex) {
|
Object handler, Exception ex) {
|
||||||
UserContext.clear();
|
|
||||||
CompanyContext.clear();
|
CompanyContext.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +123,6 @@ public class AuthInterceptor implements HandlerInterceptor {
|
|||||||
|
|
||||||
private void bindPrincipal(HttpServletRequest request, TokenPrincipal principal) {
|
private void bindPrincipal(HttpServletRequest request, TokenPrincipal principal) {
|
||||||
CompanyContext.set(principal.getCompanyId());
|
CompanyContext.set(principal.getCompanyId());
|
||||||
UserContext.set(principal);
|
|
||||||
request.setAttribute("__token_principal__", principal);
|
request.setAttribute("__token_principal__", principal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ spring:
|
|||||||
application:
|
application:
|
||||||
name: label-backend
|
name: label-backend
|
||||||
datasource:
|
datasource:
|
||||||
url: ${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/labeldb}
|
url: ${SPRING_DATASOURCE_URL:jdbc:postgresql://39.107.112.174:5432/labeldb}
|
||||||
username: ${SPRING_DATASOURCE_USERNAME:postgres}
|
username: ${SPRING_DATASOURCE_USERNAME:postgres}
|
||||||
password: ${SPRING_DATASOURCE_PASSWORD:}
|
password: ${SPRING_DATASOURCE_PASSWORD:postgres!Pw}
|
||||||
driver-class-name: org.postgresql.Driver
|
driver-class-name: org.postgresql.Driver
|
||||||
hikari:
|
hikari:
|
||||||
maximum-pool-size: 20
|
maximum-pool-size: 20
|
||||||
@@ -16,9 +16,9 @@ spring:
|
|||||||
|
|
||||||
data:
|
data:
|
||||||
redis:
|
redis:
|
||||||
host: ${SPRING_DATA_REDIS_HOST:localhost}
|
host: ${SPRING_DATA_REDIS_HOST:39.107.112.174}
|
||||||
port: ${SPRING_DATA_REDIS_PORT:6379}
|
port: ${SPRING_DATA_REDIS_PORT:6379}
|
||||||
password: ${SPRING_DATA_REDIS_PASSWORD:}
|
password: ${SPRING_DATA_REDIS_PASSWORD:jsti@2024}
|
||||||
timeout: 5000ms
|
timeout: 5000ms
|
||||||
lettuce:
|
lettuce:
|
||||||
pool:
|
pool:
|
||||||
@@ -54,9 +54,9 @@ mybatis-plus:
|
|||||||
id-type: auto
|
id-type: auto
|
||||||
|
|
||||||
rustfs:
|
rustfs:
|
||||||
endpoint: ${RUSTFS_ENDPOINT:http://localhost:9000}
|
endpoint: ${RUSTFS_ENDPOINT:http://39.107.112.174:9000}
|
||||||
access-key: ${RUSTFS_ACCESS_KEY:admin}
|
access-key: ${RUSTFS_ACCESS_KEY:admin}
|
||||||
secret-key: ${RUSTFS_SECRET_KEY:local-secret-key}
|
secret-key: ${RUSTFS_SECRET_KEY:your_strong_password}
|
||||||
region: us-east-1
|
region: us-east-1
|
||||||
|
|
||||||
ai-service:
|
ai-service:
|
||||||
@@ -64,7 +64,7 @@ ai-service:
|
|||||||
timeout: 30000
|
timeout: 30000
|
||||||
|
|
||||||
auth:
|
auth:
|
||||||
enabled: true
|
enabled: false
|
||||||
mock-company-id: 1
|
mock-company-id: 1
|
||||||
mock-user-id: 1
|
mock-user-id: 1
|
||||||
mock-role: ADMIN
|
mock-role: ADMIN
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import com.label.annotation.RequireAuth;
|
|||||||
import com.label.annotation.RequireRole;
|
import com.label.annotation.RequireRole;
|
||||||
import com.label.common.auth.TokenPrincipal;
|
import com.label.common.auth.TokenPrincipal;
|
||||||
import com.label.common.context.CompanyContext;
|
import com.label.common.context.CompanyContext;
|
||||||
import com.label.common.context.UserContext;
|
|
||||||
import com.label.interceptor.AuthInterceptor;
|
import com.label.interceptor.AuthInterceptor;
|
||||||
import com.label.service.RedisService;
|
import com.label.service.RedisService;
|
||||||
import com.label.util.RedisUtil;
|
import com.label.util.RedisUtil;
|
||||||
@@ -22,6 +21,7 @@ import java.lang.reflect.Method;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@@ -36,7 +36,6 @@ class AuthInterceptorTest {
|
|||||||
@AfterEach
|
@AfterEach
|
||||||
void tearDown() {
|
void tearDown() {
|
||||||
CompanyContext.clear();
|
CompanyContext.clear();
|
||||||
UserContext.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -62,7 +61,6 @@ class AuthInterceptorTest {
|
|||||||
assertThat(principal.getUserId()).isEqualTo(10L);
|
assertThat(principal.getUserId()).isEqualTo(10L);
|
||||||
assertThat(principal.getRole()).isEqualTo("ADMIN");
|
assertThat(principal.getRole()).isEqualTo("ADMIN");
|
||||||
assertThat(CompanyContext.get()).isEqualTo(20L);
|
assertThat(CompanyContext.get()).isEqualTo(20L);
|
||||||
assertThat(UserContext.get()).isSameAs(principal);
|
|
||||||
verify(redisService).expire(RedisUtil.tokenKey("valid-token"), 7200L);
|
verify(redisService).expire(RedisUtil.tokenKey("valid-token"), 7200L);
|
||||||
verify(redisService).expire(RedisUtil.userSessionsKey(10L), 7200L);
|
verify(redisService).expire(RedisUtil.userSessionsKey(10L), 7200L);
|
||||||
}
|
}
|
||||||
@@ -118,16 +116,21 @@ class AuthInterceptorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("请求完成后清理用户和公司 ThreadLocal")
|
@DisplayName("UserContext 已被移除,避免重复维护用户 ThreadLocal")
|
||||||
void afterCompletionClearsContexts() throws Exception {
|
void userContextClassShouldBeRemoved() {
|
||||||
|
assertThatThrownBy(() -> Class.forName("com.label.common.context.UserContext"))
|
||||||
|
.isInstanceOf(ClassNotFoundException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("请求完成后清理公司 ThreadLocal")
|
||||||
|
void afterCompletionClearsCompanyContext() throws Exception {
|
||||||
CompanyContext.set(20L);
|
CompanyContext.set(20L);
|
||||||
UserContext.set(new TokenPrincipal(10L, "ADMIN", 20L, "admin", "token"));
|
|
||||||
|
|
||||||
interceptor.afterCompletion(new MockHttpServletRequest(), new MockHttpServletResponse(),
|
interceptor.afterCompletion(new MockHttpServletRequest(), new MockHttpServletResponse(),
|
||||||
handler("adminOnly"), null);
|
handler("adminOnly"), null);
|
||||||
|
|
||||||
assertThat(CompanyContext.get()).isEqualTo(-1L);
|
assertThat(CompanyContext.get()).isEqualTo(-1L);
|
||||||
assertThat(UserContext.get()).isNull();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HandlerMethod handler(String methodName) throws NoSuchMethodException {
|
private static HandlerMethod handler(String methodName) throws NoSuchMethodException {
|
||||||
|
|||||||
Reference in New Issue
Block a user