This is an automated email from the ASF dual-hosted git repository.

kinghao pushed a commit to branch release-1.8.0-rc1
in repository https://gitbox.apache.org/repos/asf/linkis.git


The following commit(s) were added to refs/heads/release-1.8.0-rc1 by this push:
     new 57967e7838 fix token security
57967e7838 is described below

commit 57967e7838e31a473e8be20d7b9d933b930738d9
Author: aiceflower <[email protected]>
AuthorDate: Tue Oct 7 23:25:33 2025 +0800

    fix token security
---
 .../gateway/authentication/dao/TokenDaoTest.java   | 122 +++++++-------
 .../service/CachedTokenServiceTest.java            | 179 +++++++++++----------
 2 files changed, 161 insertions(+), 140 deletions(-)

diff --git 
a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/dao/TokenDaoTest.java
 
b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/dao/TokenDaoTest.java
index 2cc6c03af3..203ea9f903 100644
--- 
a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/dao/TokenDaoTest.java
+++ 
b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/dao/TokenDaoTest.java
@@ -1,56 +1,66 @@
-/*
- * 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.linkis.gateway.authentication.dao;
-
-import org.apache.linkis.common.conf.CommonVars;
-import org.apache.linkis.common.conf.Configuration;
-import org.apache.linkis.gateway.authentication.entity.TokenEntity;
-
-import org.glassfish.jersey.model.internal.CommonConfig;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import java.util.List;
-
-import org.junit.jupiter.api.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotEquals;
-
-class TokenDaoTest extends BaseDaoTest {
-
-  private static final Logger logger = 
LoggerFactory.getLogger(BaseDaoTest.class);
-
-  private static String TokenName =
-      CommonVars.apply("wds.linkis.bml.auth.token.value", 
Configuration.LINKIS_TOKEN().getValue()).getValue();
-
-  @Autowired TokenDao tokenDao;
-
-  @Test
-  void testSelectTokenByName() {
-    TokenEntity result = tokenDao.selectTokenByName(TokenName);
-    assertEquals(result.getTokenName(), TokenName);
-  }
-
-  @Test
-  void testGetAllTokens() {
-    List<TokenEntity> result = tokenDao.getAllTokens();
-    assertNotEquals(result.size(), 0);
-  }
-}
+/*
+ * 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.linkis.gateway.authentication.dao;
+
+import org.apache.linkis.common.conf.CommonVars;
+import org.apache.linkis.common.conf.Configuration;
+import org.apache.linkis.gateway.authentication.entity.TokenEntity;
+
+import org.apache.commons.lang3.StringUtils;
+
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.List;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+class TokenDaoTest extends BaseDaoTest {
+
+  private static final Logger logger = 
LoggerFactory.getLogger(BaseDaoTest.class);
+
+  private static String TokenName =
+      CommonVars.apply("wds.linkis.bml.auth.token.value", 
Configuration.LINKIS_TOKEN().getValue())
+          .getValue();
+
+  @Autowired TokenDao tokenDao;
+
+  @BeforeAll
+  static void before() {
+    if (StringUtils.isBlank(TokenName)) {
+      TokenName = "LINKIS-UNAVAILABLE-TOKE";
+    }
+  }
+
+  @Test
+  void testSelectTokenByName() {
+    TokenEntity result = tokenDao.selectTokenByName(TokenName);
+    assertEquals(result.getTokenName(), TokenName);
+  }
+
+  @Test
+  void testGetAllTokens() {
+    List<TokenEntity> result = tokenDao.getAllTokens();
+    assertNotEquals(result.size(), 0);
+  }
+}
diff --git 
a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/service/CachedTokenServiceTest.java
 
b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/service/CachedTokenServiceTest.java
index d1b46c2d85..f16024a4f6 100644
--- 
a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/service/CachedTokenServiceTest.java
+++ 
b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/service/CachedTokenServiceTest.java
@@ -1,84 +1,95 @@
-/*
- * 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.linkis.gateway.authentication.service;
-
-import org.apache.linkis.common.conf.CommonVars;
-import org.apache.linkis.common.conf.Configuration;
-import org.apache.linkis.gateway.authentication.Scan;
-import org.apache.linkis.gateway.authentication.WebApplicationServer;
-import org.apache.linkis.gateway.authentication.exception.TokenAuthException;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
-
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-@ExtendWith(SpringExtension.class)
-@SpringBootTest(classes = {WebApplicationServer.class, Scan.class})
-public class CachedTokenServiceTest {
-  private static final Logger logger = 
LoggerFactory.getLogger(CachedTokenServiceTest.class);
-
-  private static String TokenName =
-      CommonVars.apply("wds.linkis.bml.auth.token.value", 
Configuration.LINKIS_TOKEN().getValue()).getValue();
-
-  @Autowired CachedTokenService tokenService;
-
-  @Test
-  void testIsTokenValid() {
-    boolean isOk = tokenService.isTokenValid(TokenName);
-    assertTrue(isOk);
-  }
-
-  @Test
-  void testIsTokenAcceptableWithUser() {
-    boolean isOk = tokenService.isTokenAcceptableWithUser(TokenName, "test");
-    assertTrue(isOk);
-    isOk = tokenService.isTokenAcceptableWithUser(TokenName, "test1");
-    assertFalse(isOk);
-  }
-
-  @Test
-  void testIsTokenAcceptableWithHost() {
-    boolean isOk = tokenService.isTokenAcceptableWithHost(TokenName, 
"127.0.0.1");
-    assertTrue(isOk);
-    isOk = tokenService.isTokenAcceptableWithHost(TokenName, "10.10.10.10");
-    assertFalse(isOk);
-  }
-
-  @Test
-  void testDoAuth() {
-    boolean isOk = tokenService.doAuth(TokenName, "test", "127.0.0.1");
-    assertTrue(isOk);
-
-    Exception exception =
-        assertThrows(
-            TokenAuthException.class, () -> tokenService.doAuth(TokenName, 
"test1", "127.0.0.1"));
-    logger.info("assertThrows:{}", exception.getMessage());
-
-    exception =
-        assertThrows(
-            TokenAuthException.class, () -> tokenService.doAuth(TokenName, 
"test", "10.10.10.10"));
-    logger.info("assertThrows:{}", exception.getMessage());
-  }
-}
+/*
+ * 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.linkis.gateway.authentication.service;
+
+import org.apache.linkis.common.conf.CommonVars;
+import org.apache.linkis.common.conf.Configuration;
+import org.apache.linkis.gateway.authentication.Scan;
+import org.apache.linkis.gateway.authentication.WebApplicationServer;
+import org.apache.linkis.gateway.authentication.exception.TokenAuthException;
+
+import org.apache.commons.lang3.StringUtils;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+@ExtendWith(SpringExtension.class)
+@SpringBootTest(classes = {WebApplicationServer.class, Scan.class})
+public class CachedTokenServiceTest {
+  private static final Logger logger = 
LoggerFactory.getLogger(CachedTokenServiceTest.class);
+
+  private static String TokenName =
+      CommonVars.apply("wds.linkis.bml.auth.token.value", 
Configuration.LINKIS_TOKEN().getValue())
+          .getValue();
+
+  @Autowired CachedTokenService tokenService;
+
+  @BeforeAll
+  static void before() {
+    if (StringUtils.isBlank(TokenName)) {
+      TokenName = "LINKIS-UNAVAILABLE-TOKE";
+    }
+  }
+
+  @Test
+  void testIsTokenValid() {
+    boolean isOk = tokenService.isTokenValid(TokenName);
+    assertTrue(isOk);
+  }
+
+  @Test
+  void testIsTokenAcceptableWithUser() {
+    boolean isOk = tokenService.isTokenAcceptableWithUser(TokenName, "test");
+    assertTrue(isOk);
+    isOk = tokenService.isTokenAcceptableWithUser(TokenName, "test1");
+    assertFalse(isOk);
+  }
+
+  @Test
+  void testIsTokenAcceptableWithHost() {
+    boolean isOk = tokenService.isTokenAcceptableWithHost(TokenName, 
"127.0.0.1");
+    assertTrue(isOk);
+    isOk = tokenService.isTokenAcceptableWithHost(TokenName, "10.10.10.10");
+    assertFalse(isOk);
+  }
+
+  @Test
+  void testDoAuth() {
+    boolean isOk = tokenService.doAuth(TokenName, "test", "127.0.0.1");
+    assertTrue(isOk);
+
+    Exception exception =
+        assertThrows(
+            TokenAuthException.class, () -> tokenService.doAuth(TokenName, 
"test1", "127.0.0.1"));
+    logger.info("assertThrows:{}", exception.getMessage());
+
+    exception =
+        assertThrows(
+            TokenAuthException.class, () -> tokenService.doAuth(TokenName, 
"test", "10.10.10.10"));
+    logger.info("assertThrows:{}", exception.getMessage());
+  }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to