This is an automated email from the ASF dual-hosted git repository.
nicholasjiang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-webui.git
The following commit(s) were added to refs/heads/main by this push:
new d3f3994b [Improvement] Introduce interceptor.exclude.path.patterns to
exclude path patterns for configurer interceptor (#397)
d3f3994b is described below
commit d3f3994b0bbce8e70e9c2bc92cfeb8e5978136f3
Author: silenceland <[email protected]>
AuthorDate: Sat Jun 15 12:15:46 2024 +0800
[Improvement] Introduce interceptor.exclude.path.patterns to exclude path
patterns for configurer interceptor (#397)
---
.../web/server/configrue/SaTokenConfigurer.java | 9 +++--
.../src/main/resources/application.yml | 7 ++++
.../server/configurer/SaTokenConfigurerTests.java | 46 ++++++++++++++++++++++
.../src/test/resources/application.yml | 5 +++
4 files changed, 64 insertions(+), 3 deletions(-)
diff --git
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/SaTokenConfigurer.java
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/SaTokenConfigurer.java
index d0ca067a..2f8311a5 100644
---
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/SaTokenConfigurer.java
+++
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/SaTokenConfigurer.java
@@ -20,19 +20,22 @@ package org.apache.paimon.web.server.configrue;
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-import java.util.Arrays;
-
/** Sa-Token path config. */
@Configuration
public class SaTokenConfigurer implements WebMvcConfigurer {
+
+ @Value("${interceptor.exclude.path.patterns}")
+ private String[] excludePathPatterns;
+
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new SaInterceptor(handle ->
StpUtil.checkLogin()))
.addPathPatterns("/**")
- .excludePathPatterns(Arrays.asList("/api/login", "/ui/**"));
+ .excludePathPatterns(excludePathPatterns);
}
}
diff --git a/paimon-web-server/src/main/resources/application.yml
b/paimon-web-server/src/main/resources/application.yml
index 821ccfac..c0128576 100644
--- a/paimon-web-server/src/main/resources/application.yml
+++ b/paimon-web-server/src/main/resources/application.yml
@@ -77,3 +77,10 @@ management:
health:
ldap:
enabled: false
+
+interceptor:
+ exclude:
+ path:
+ patterns: /api/login, /ui/**
+
+
diff --git
a/paimon-web-server/src/test/java/org/apache/paimon/web/server/configurer/SaTokenConfigurerTests.java
b/paimon-web-server/src/test/java/org/apache/paimon/web/server/configurer/SaTokenConfigurerTests.java
new file mode 100644
index 00000000..716335bb
--- /dev/null
+++
b/paimon-web-server/src/test/java/org/apache/paimon/web/server/configurer/SaTokenConfigurerTests.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.paimon.web.server.configurer;
+
+import org.apache.paimon.web.server.configrue.SaTokenConfigurer;
+
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Value;
+import
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/** Test for {@link SaTokenConfigurer}. */
+@SpringBootTest
+@AutoConfigureMockMvc
+public class SaTokenConfigurerTests {
+
+ @Value("${interceptor.exclude.path.patterns}")
+ private String[] excludePathPatterns;
+
+ @Test
+ @Order(1)
+ public void testPathExclude() throws Exception {
+ assertEquals(excludePathPatterns.length, 2);
+ assertEquals(excludePathPatterns[0], "/api/login");
+ assertEquals(excludePathPatterns[1], "/ui/**");
+ }
+}
diff --git a/paimon-web-server/src/test/resources/application.yml
b/paimon-web-server/src/test/resources/application.yml
index ae44ae1b..da720673 100644
--- a/paimon-web-server/src/test/resources/application.yml
+++ b/paimon-web-server/src/test/resources/application.yml
@@ -65,3 +65,8 @@ sa-token:
is-write-header: true
is-read-header: true
is-read-body: true
+
+interceptor:
+ exclude:
+ path:
+ patterns: /api/login, /ui/**