You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by pe...@apache.org on 2022/04/08 06:34:33 UTC

[incubator-linkis] branch dev-1.1.2 updated: add junit test for gateway-authentication (#1922)

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

peacewong pushed a commit to branch dev-1.1.2
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git


The following commit(s) were added to refs/heads/dev-1.1.2 by this push:
     new 91a33be11 add junit test for gateway-authentication (#1922)
91a33be11 is described below

commit 91a33be1107d98baa85b4c836723acb64cd0a021
Author: Casion <ca...@gmail.com>
AuthorDate: Fri Apr 8 14:34:28 2022 +0800

    add junit test for gateway-authentication (#1922)
    
    * optimize of gateway token dao
    
    * add junit test for gateway-authentication
    
    * code format
---
 .../gateway/authentication/dao/TokenDao.java       |  4 +-
 .../authentication/dao/impl/TokenMapper.xml        |  8 +--
 .../service/CachedTokenService.scala               |  9 ++-
 .../linkis/gateway/authentication/Scan.java}       | 22 ++----
 .../authentication/WebApplicationServer.java}      | 28 ++++----
 .../gateway/authentication/dao/BaseDaoTest.java}   | 25 +++----
 .../gateway/authentication/dao/TokenDaoTest.java}  | 28 ++++++--
 .../service/CachedTokenServiceTest.java            | 82 ++++++++++++++++++++++
 .../src/test/resources/application.properties      | 62 ++++++++++++++++
 .../TokenDao.java => test/resources/create.sql}    | 40 +++++------
 .../src/test/resources/data.sql                    | 28 ++++++++
 .../src/test/resources/linkis.properties           | 21 ++++++
 12 files changed, 278 insertions(+), 79 deletions(-)

diff --git a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/TokenDao.java b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/TokenDao.java
index 2b93005c4..14fb3a857 100644
--- a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/TokenDao.java
+++ b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/TokenDao.java
@@ -19,6 +19,8 @@ package org.apache.linkis.gateway.authentication.dao;
 
 import org.apache.linkis.gateway.authentication.entity.TokenEntity;
 
+import org.apache.ibatis.annotations.Param;
+
 import java.util.List;
 
 public interface TokenDao {
@@ -28,7 +30,7 @@ public interface TokenDao {
 
     Boolean removeToken(TokenEntity token); // TODO
 
-    List<TokenEntity> selectTokenByName(String tokenName);
+    TokenEntity selectTokenByName(@Param("tokenName") String tokenName);
 
     List<TokenEntity> getAllTokens();
 }
diff --git a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/impl/TokenMapper.xml b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/impl/TokenMapper.xml
index 83a567ad5..155c548d6 100644
--- a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/impl/TokenMapper.xml
+++ b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/impl/TokenMapper.xml
@@ -34,19 +34,19 @@
         <result property="updateBy" column="update_by"/>
     </resultMap>
 
-    <sql id="table_name">linkis_mg_gateway_auth_token</sql>
+    <sql id="tableName">linkis_mg_gateway_auth_token</sql>
 
     <select id="selectTokenByName" parameterType="String" resultMap="tokenEntityMap">
         select * from
-        <include refid="table_name"/>
+        <include refid="tableName"/>
         <where>
-            token_name = #{token_name}
+            token_name = #{tokenName}
         </where>
     </select>
 
     <select id="getAllTokens" resultMap="tokenEntityMap">
         select * from
-        <include refid="table_name"/>
+        <include refid="tableName"/>
     </select>
 
 
diff --git a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/scala/org/apache/linkis/gateway/authentication/service/CachedTokenService.scala b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/scala/org/apache/linkis/gateway/authentication/service/CachedTokenService.scala
index 5a6b2ce13..02d628a4c 100644
--- a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/scala/org/apache/linkis/gateway/authentication/service/CachedTokenService.scala
+++ b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/scala/org/apache/linkis/gateway/authentication/service/CachedTokenService.scala
@@ -43,11 +43,10 @@ class CachedTokenService extends TokenService {
     .refreshAfterWrite(TokenConfiguration.TOKEN_CACHE_EXPIRE_HOURS, TimeUnit.HOURS)
     .build(
       new CacheLoader[String, Token]() {
-        @Override
-        def load(tokenName: String): Token = {
-          val tokenEntityList: java.util.List[TokenEntity] = tokenDao.selectTokenByName(tokenName)
-          if (tokenEntityList != null && tokenEntityList.size != 0) {
-            new TokenImpl().convertFrom(tokenEntityList.get(0))
+        override def load(tokenName: String): Token = {
+          val tokenEntity: TokenEntity = tokenDao.selectTokenByName(tokenName)
+          if (tokenEntity != null) {
+            new TokenImpl().convertFrom(tokenEntity)
           } else {
             throw new TokenNotExistException(15204, s"Invalid Token")
           }
diff --git a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/TokenDao.java b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/Scan.java
similarity index 61%
copy from linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/TokenDao.java
copy to linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/Scan.java
index 2b93005c4..4637ad247 100644
--- a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/TokenDao.java
+++ b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/Scan.java
@@ -6,7 +6,7 @@
  * (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
+ *    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,
@@ -15,20 +15,12 @@
  * limitations under the License.
  */
 
-package org.apache.linkis.gateway.authentication.dao;
+package org.apache.linkis.gateway.authentication;
 
-import org.apache.linkis.gateway.authentication.entity.TokenEntity;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 
-import java.util.List;
+import org.mybatis.spring.annotation.MapperScan;
 
-public interface TokenDao {
-    Boolean insertToken(TokenEntity token); // TODO
-
-    Boolean updateToken(TokenEntity token); // TODO
-
-    Boolean removeToken(TokenEntity token); // TODO
-
-    List<TokenEntity> selectTokenByName(String tokenName);
-
-    List<TokenEntity> getAllTokens();
-}
+@EnableAutoConfiguration
+@MapperScan("org.apache.linkis.gateway.authentication")
+public class Scan {}
diff --git a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/TokenDao.java b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/WebApplicationServer.java
similarity index 51%
copy from linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/TokenDao.java
copy to linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/WebApplicationServer.java
index 2b93005c4..aa4ab678c 100644
--- a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/TokenDao.java
+++ b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/WebApplicationServer.java
@@ -6,7 +6,7 @@
  * (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
+ *    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,
@@ -15,20 +15,20 @@
  * limitations under the License.
  */
 
-package org.apache.linkis.gateway.authentication.dao;
+package org.apache.linkis.gateway.authentication;
 
-import org.apache.linkis.gateway.authentication.entity.TokenEntity;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.web.servlet.ServletComponentScan;
+import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
+import org.springframework.context.annotation.ComponentScan;
 
-import java.util.List;
+@EnableAutoConfiguration
+@ServletComponentScan
+@ComponentScan
+public class WebApplicationServer extends SpringBootServletInitializer {
 
-public interface TokenDao {
-    Boolean insertToken(TokenEntity token); // TODO
-
-    Boolean updateToken(TokenEntity token); // TODO
-
-    Boolean removeToken(TokenEntity token); // TODO
-
-    List<TokenEntity> selectTokenByName(String tokenName);
-
-    List<TokenEntity> getAllTokens();
+    public static void main(String[] args) {
+        new SpringApplicationBuilder(WebApplicationServer.class).run(args);
+    }
 }
diff --git a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/TokenDao.java b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/dao/BaseDaoTest.java
similarity index 62%
copy from linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/TokenDao.java
copy to linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/dao/BaseDaoTest.java
index 2b93005c4..2b85bd303 100644
--- a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/TokenDao.java
+++ b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/dao/BaseDaoTest.java
@@ -6,7 +6,7 @@
  * (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
+ *    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,
@@ -17,18 +17,15 @@
 
 package org.apache.linkis.gateway.authentication.dao;
 
-import org.apache.linkis.gateway.authentication.entity.TokenEntity;
+import org.apache.linkis.gateway.authentication.Scan;
 
-import java.util.List;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.Rollback;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+import org.springframework.transaction.annotation.Transactional;
 
-public interface TokenDao {
-    Boolean insertToken(TokenEntity token); // TODO
-
-    Boolean updateToken(TokenEntity token); // TODO
-
-    Boolean removeToken(TokenEntity token); // TODO
-
-    List<TokenEntity> selectTokenByName(String tokenName);
-
-    List<TokenEntity> getAllTokens();
-}
+@SpringBootTest(classes = Scan.class)
+@Transactional
+@Rollback(true)
+@EnableTransactionManagement
+public abstract class BaseDaoTest {}
diff --git a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/TokenDao.java b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/dao/TokenDaoTest.java
similarity index 56%
copy from linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/TokenDao.java
copy to linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/dao/TokenDaoTest.java
index 2b93005c4..230a64b87 100644
--- a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/TokenDao.java
+++ b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/dao/TokenDaoTest.java
@@ -19,16 +19,32 @@ package org.apache.linkis.gateway.authentication.dao;
 
 import org.apache.linkis.gateway.authentication.entity.TokenEntity;
 
+import org.springframework.beans.factory.annotation.Autowired;
+
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.util.List;
 
-public interface TokenDao {
-    Boolean insertToken(TokenEntity token); // TODO
+import static org.junit.jupiter.api.Assertions.*;
+
+class TokenDaoTest extends BaseDaoTest {
 
-    Boolean updateToken(TokenEntity token); // TODO
+    private static final Logger logger = LoggerFactory.getLogger(BaseDaoTest.class);
 
-    Boolean removeToken(TokenEntity token); // TODO
+    private static String TokenName = "BML-AUTH";
+    @Autowired TokenDao tokenDao;
 
-    List<TokenEntity> selectTokenByName(String tokenName);
+    @Test
+    void testSelectTokenByName() {
+        TokenEntity result = tokenDao.selectTokenByName(TokenName);
+        assertEquals(result.getTokenName(), TokenName);
+    }
 
-    List<TokenEntity> getAllTokens();
+    @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
new file mode 100644
index 000000000..56cc8c549
--- /dev/null
+++ b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/java/org/apache/linkis/gateway/authentication/service/CachedTokenServiceTest.java
@@ -0,0 +1,82 @@
+/*
+ * 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.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 = "BML-AUTH";
+
+    @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());
+    }
+}
diff --git a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/resources/application.properties b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/resources/application.properties
new file mode 100644
index 000000000..7a6df750f
--- /dev/null
+++ b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/resources/application.properties
@@ -0,0 +1,62 @@
+# 
+# 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.
+#
+
+#wds.linkis.test.mode=true
+wds.linkis.server.version=v1
+
+#test
+wds.linkis.test.mode=true
+wds.linkis.test.user=hadoop
+
+wds.linkis.is.gateway=true
+wds.linkis.server.web.session.timeout=1h
+wds.linkis.gateway.conf.enable.proxy.user=false
+wds.linkis.gateway.conf.url.pass.auth=/dss/
+wds.linkis.gateway.conf.enable.token.auth=true
+wds.linkis.login_encrypt.enable=false
+#logging.level.root=debug
+#logging.file=./test.log
+#debug=true
+
+ng.datasource.driver-class-name=org.h2.Driver
+spring.datasource.url=jdbc:h2:mem:test;MODE=MySQL;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=true
+spring.datasource.schema=classpath:create.sql
+spring.datasource.data=classpath:data.sql
+spring.datasource.username=sa
+spring.datasource.password=
+spring.datasource.hikari.connection-test-query=select 1
+spring.datasource.hikari.minimum-idle=5
+spring.datasource.hikari.auto-commit=true
+spring.datasource.hikari.validation-timeout=3000
+spring.datasource.hikari.pool-name=linkis-test
+spring.datasource.hikari.maximum-pool-size=50
+spring.datasource.hikari.connection-timeout=30000
+spring.datasource.hikari.idle-timeout=600000
+spring.datasource.hikari.leak-detection-threshold=0
+spring.datasource.hikari.initialization-fail-timeout=1
+
+spring.main.web-application-type=servlet
+server.port=1234
+spring.h2.console.enabled=true
+
+#disable eureka discovery client
+spring.cloud.service-registry.auto-registration.enabled=false
+eureka.client.enabled=false
+eureka.client.serviceUrl.registerWithEureka=false
+
+mybatis-plus.mapper-locations=classpath*:org/apache/linkis/gateway/authentication/dao/impl/*.xml
+mybatis-plus.type-aliases-package=org.apache.linkis.gateway.authentication.entity
+mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
+
diff --git a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/TokenDao.java b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/resources/create.sql
similarity index 55%
copy from linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/TokenDao.java
copy to linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/resources/create.sql
index 2b93005c4..1a64955f1 100644
--- a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/main/java/org/apache/linkis/gateway/authentication/dao/TokenDao.java
+++ b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/resources/create.sql
@@ -6,29 +6,29 @@
  * (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
+ *    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.gateway.authentication.entity.TokenEntity;
-
-import java.util.List;
-
-public interface TokenDao {
-    Boolean insertToken(TokenEntity token); // TODO
-
-    Boolean updateToken(TokenEntity token); // TODO
-
-    Boolean removeToken(TokenEntity token); // TODO
-
-    List<TokenEntity> selectTokenByName(String tokenName);
-
-    List<TokenEntity> getAllTokens();
-}
+*/
+
+SET FOREIGN_KEY_CHECKS=0;
+SET REFERENTIAL_INTEGRITY FALSE;
+
+DROP TABLE IF EXISTS linkis_mg_gateway_auth_token CASCADE;
+CREATE TABLE IF NOT EXISTS linkis_mg_gateway_auth_token (
+  id int(11) NOT NULL AUTO_INCREMENT,
+  token_name varchar(128) NOT NULL,
+  legal_users varchar(512) NOT NULL,
+  legal_hosts varchar(512) NOT NULL,
+  business_owner varchar(32),
+  create_time datetime DEFAULT NULL,
+  update_time datetime DEFAULT NULL,
+  elapse_day  bigint(20) DEFAULT  NULL,
+  update_by   varchar(32),
+  PRIMARY KEY (id),
+  UNIQUE KEY token_name (token_name)
+);
\ No newline at end of file
diff --git a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/resources/data.sql b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/resources/data.sql
new file mode 100644
index 000000000..9c86868a6
--- /dev/null
+++ b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/resources/data.sql
@@ -0,0 +1,28 @@
+/*
+ * 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.
+*/
+
+DELETE FROM linkis_mg_gateway_auth_token;
+-- ----------------------------
+-- Default Tokens
+-- ----------------------------
+INSERT INTO `linkis_mg_gateway_auth_token`(`token_name`,`legal_users`,`legal_hosts`,`business_owner`,`create_time`,`update_time`,`elapse_day`,`update_by`) VALUES ('QML-AUTH','*','*','BDP',curdate(),curdate(),-1,'LINKIS');
+INSERT INTO `linkis_mg_gateway_auth_token`(`token_name`,`legal_users`,`legal_hosts`,`business_owner`,`create_time`,`update_time`,`elapse_day`,`update_by`) VALUES ('BML-AUTH','hadoop,test','127.0.0.1','BDP',curdate(),curdate(),-1,'LINKIS');
+INSERT INTO `linkis_mg_gateway_auth_token`(`token_name`,`legal_users`,`legal_hosts`,`business_owner`,`create_time`,`update_time`,`elapse_day`,`update_by`) VALUES ('WS-AUTH','*','*','BDP',curdate(),curdate(),-1,'LINKIS');
+INSERT INTO `linkis_mg_gateway_auth_token`(`token_name`,`legal_users`,`legal_hosts`,`business_owner`,`create_time`,`update_time`,`elapse_day`,`update_by`) VALUES ('dss-AUTH','*','*','BDP',curdate(),curdate(),-1,'LINKIS');
+INSERT INTO `linkis_mg_gateway_auth_token`(`token_name`,`legal_users`,`legal_hosts`,`business_owner`,`create_time`,`update_time`,`elapse_day`,`update_by`) VALUES ('QUALITIS-AUTH','*','*','BDP',curdate(),curdate(),-1,'LINKIS');
+INSERT INTO `linkis_mg_gateway_auth_token`(`token_name`,`legal_users`,`legal_hosts`,`business_owner`,`create_time`,`update_time`,`elapse_day`,`update_by`) VALUES ('VALIDATOR-AUTH','*','*','BDP',curdate(),curdate(),-1,'LINKIS');
+INSERT INTO `linkis_mg_gateway_auth_token`(`token_name`,`legal_users`,`legal_hosts`,`business_owner`,`create_time`,`update_time`,`elapse_day`,`update_by`) VALUES ('LINKISCLI-AUTH','*','*','BDP',curdate(),curdate(),-1,'LINKIS');
diff --git a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/resources/linkis.properties b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/resources/linkis.properties
new file mode 100644
index 000000000..1c575edc5
--- /dev/null
+++ b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-authentication/src/test/resources/linkis.properties
@@ -0,0 +1,21 @@
+# 
+# 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.
+#
+
+#wds.linkis.test.mode=true
+wds.linkis.server.version=v1
+
+#test
+wds.linkis.test.mode=true
+wds.linkis.test.user=hadoop
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org