This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 499ec0ee5 [ISSUE #3713]Add new plugin: key-auth (#3756)
499ec0ee5 is described below
commit 499ec0ee5f5a150f6c890a315b1ffb28b571fc43
Author: Zihao Huang <[email protected]>
AuthorDate: Thu Nov 3 21:13:46 2022 +0800
[ISSUE #3713]Add new plugin: key-auth (#3756)
* [ISSUE #3713]Fix conflicting
* [ISSUE #3713]fix conflicting SQL scripts
Co-authored-by: xiaoyu <[email protected]>
---
db/init/mysql/schema.sql | 1 +
db/init/oracle/schema.sql | 1 +
db/init/pg/create-table.sql | 1 +
db/upgrade/2.5.0-upgrade-2.5.1-mysql.sql | 2 +
db/upgrade/2.5.0-upgrade-2.5.1-oracle.sql | 4 +
db/upgrade/2.5.0-upgrade-2.5.1-pg.sql | 3 +
.../src/main/resources/sql-script/h2/schema.sql | 2 +
shenyu-bootstrap/pom.xml | 8 ++
.../dto/convert/rule/impl/KeyAuthRuleHandle.java | 100 +++++++++++++++
.../org/apache/shenyu/common/enums/PluginEnum.java | 7 +-
.../convert/rule/impl/KeyAuthRuleHandleTest.java | 40 ++++++
shenyu-plugin/pom.xml | 1 +
.../shenyu/plugin/api/result/ShenyuResultEnum.java | 12 +-
shenyu-plugin/shenyu-plugin-key-auth/pom.xml | 47 ++++++++
.../shenyu/plugin/key/auth/KeyAuthPlugin.java | 88 ++++++++++++++
.../key/auth/handler/KeyAuthPluginDataHandler.java | 48 ++++++++
.../shenyu/plugin/key/auth/KeyAuthPluginTest.java | 134 +++++++++++++++++++++
.../auth/handler/KeyAuthPluginDataHandlerTest.java | 65 ++++++++++
.../shenyu-spring-boot-starter-plugin/pom.xml | 1 +
.../pom.xml | 45 +++++++
.../key/auth/KeyAuthPluginConfiguration.java | 52 ++++++++
.../src/main/resources/META-INF/spring.factories | 19 +++
.../src/main/resources/META-INF/spring.provides | 18 +++
.../key/auth/KeyAuthPluginConfigurationTest.java | 52 ++++++++
24 files changed, 749 insertions(+), 2 deletions(-)
diff --git a/db/init/mysql/schema.sql b/db/init/mysql/schema.sql
index f89a37c4f..6066a490a 100644
--- a/db/init/mysql/schema.sql
+++ b/db/init/mysql/schema.sql
@@ -815,6 +815,7 @@ INSERT INTO `plugin` VALUES ('35', 'loggingPulsar',
'{\"topic":\"shenyu-access-l
INSERT INTO `plugin` VALUES ('36', 'loggingTencentCls','{\"endpoint\":
\"ap-guangzhou.cls.tencentcs.com\", \"topic\": \"shenyu-topic\"}', 'Logging',
176, 0, '2022-06-30 21:00:00', '2022-06-30 21:00:00');
INSERT INTO `plugin` VALUES ('38', 'loggingClickHouse',
'{\"host\":\"127.0.0.1\",\"port\":\"8123\",\"databse\":\"shenyu-gateway\",\"username\":\"foo\",\"password\":\"bar\"}',
'Logging', 195, 0, '2022-06-30 21:00:00', '2022-06-30 21:00:00');
INSERT INTO `plugin` VALUES ('39', 'casdoor',
'{\"endpoint\":\"http://localhost:8000\"}', 'Authentication', 40, 0,
'2022-09-11 12:00:00', '2022-09-11 12:00:00');
+INSERT INTO `plugin` VALUES ('40', 'keyAuth', NULL, 'Authentication', 150, 0,
'2022-07-24 19:00:00', '2022-07-24 19:00:00');
-- ----------------------------
-- Table structure for plugin_handle
diff --git a/db/init/oracle/schema.sql b/db/init/oracle/schema.sql
index a53f796d0..b79d80d98 100644
--- a/db/init/oracle/schema.sql
+++ b/db/init/oracle/schema.sql
@@ -1108,6 +1108,7 @@ INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO
plugin (id, name, conf
INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name,
config, role, sort, enabled) VALUES ('36', 'loggingTencentCls', '{"endpoint":
"ap-guangzhou.cls.tencentcs.com", "topic": "shenyu-topic"}', 'Logging', 176,
'0');
INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name,
config, role, sort, enabled) VALUES ('38', 'loggingClickHouse',
'{"host":"127.0.0.1","port":"8123","databse":"shenyu-gateway","username":"foo","password":"bar"}',
'Logging', 195, '0');
INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name,
config, role, sort, enabled) VALUES ('39', 'casdoor',
'{"endpoint":"http://localhost:8000"}' ,'Authentication', 40, '0');
+INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name,
role, sort, enabled) VALUES ('40', 'keyAuth', 'Authentication', 150, '0');
diff --git a/db/init/pg/create-table.sql b/db/init/pg/create-table.sql
index 0287d6931..de2b6f1f4 100644
--- a/db/init/pg/create-table.sql
+++ b/db/init/pg/create-table.sql
@@ -948,6 +948,7 @@ INSERT INTO "public"."plugin" VALUES ('35',
'loggingPulsar', '{"topic":"shenyu-a
INSERT INTO "public"."plugin" VALUES ('36', 'loggingTencentCls', '{"endpoint":
"ap-guangzhou.cls.tencentcs.com", "topic": "shenyu-topic"}', 'Logging', 176, 0,
'2022-06-30 21:00:00', '2022-06-30 21:00:00');
INSERT INTO "public"."plugin" VALUES ('38', 'loggingClickHouse',
'{"host":"127.0.0.1","port":"8123","databse":"shenyu-gateway","username":"foo","password":"bar"}',
'Logging', 195, 0, '2022-06-30 21:00:00', '2022-06-30 21:00:00');
INSERT INTO "public"."plugin" VALUES ('39', 'casdoor',
'{"endpoint":"http://localhost:8000"}', 'Authentication', 40, 0, '2022-09-11
12:00:00', '2022-09-11 12:00:00');
+INSERT INTO "public"."plugin" VALUES ('40', 'keyAuth', NULL, 'Authentication',
150, 0, '2022-07-24 19:00:00', '2022-07-24 19:00:00');
-- ----------------------------
-- Table structure for plugin_handle
diff --git a/db/upgrade/2.5.0-upgrade-2.5.1-mysql.sql
b/db/upgrade/2.5.0-upgrade-2.5.1-mysql.sql
index e27311199..27d9871b9 100644
--- a/db/upgrade/2.5.0-upgrade-2.5.1-mysql.sql
+++ b/db/upgrade/2.5.0-upgrade-2.5.1-mysql.sql
@@ -268,3 +268,5 @@ INSERT INTO `plugin_handle` VALUES ('1529402613204172767',
'38', 'keyword', 'key
INSERT INTO `plugin_handle` VALUES ('1529402613204172768', '38', 'maskType',
'maskType', 3, 2, 1,
'{\"required\":\"0\",\"defaultValue\":\"dataMaskByMD5\",\"rule\":\"\"}',
'2022-09-22 00:16:27.342', '2022-09-22 00:16:27.342');
INSERT INTO `plugin_handle` VALUES ('1529402613204172769', '38', 'maskStatus',
'maskStatus', 3, 2, 2,
'{\"required\":\"0\",\"defaultValue\":\"false\",\"rule\":\"\"}', '2022-09-22
00:17:21.150', '2022-09-22 00:17:21.150');
+/* insert plugin for keyAuth */
+INSERT INTO `plugin` VALUES ('40', 'keyAuth', NULL, 'Authentication', 150, 0,
'2022-07-24 19:00:00', '2022-07-24 19:00:00');
diff --git a/db/upgrade/2.5.0-upgrade-2.5.1-oracle.sql
b/db/upgrade/2.5.0-upgrade-2.5.1-oracle.sql
index 4057d3e5a..06afd7d46 100644
--- a/db/upgrade/2.5.0-upgrade-2.5.1-oracle.sql
+++ b/db/upgrade/2.5.0-upgrade-2.5.1-oracle.sql
@@ -278,3 +278,7 @@ values ('1518229897214468253', '38', 'maskType',
'maskType', 3, 2, 1, '{"require
insert /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin_handle(plugin_id, field, type))
*/ into plugin_handle (ID, PLUGIN_ID, FIELD, LABEL, DATA_TYPE, TYPE, SORT,
EXT_OBJ)
values ('1518229897214468254', '38', 'maskStatus', 'maskStatus', 3, 2, 2,
'{"required":"0","defaultValue":"false","rule":""}');
+
+-- insert keyAuth plugin start
+INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name,
role, sort, enabled) VALUES ('40', 'keyAuth', 'Authentication', 150, '0');
+-- insert keyAuth plugin end
diff --git a/db/upgrade/2.5.0-upgrade-2.5.1-pg.sql
b/db/upgrade/2.5.0-upgrade-2.5.1-pg.sql
index 32de3c768..001d83d28 100644
--- a/db/upgrade/2.5.0-upgrade-2.5.1-pg.sql
+++ b/db/upgrade/2.5.0-upgrade-2.5.1-pg.sql
@@ -270,3 +270,6 @@ INSERT INTO "public"."plugin_handle" VALUES
('1529402613204172826', '36', 'maskS
INSERT INTO "public"."plugin_handle" VALUES ('1529402613204172827', '38',
'keyword', 'keyword', 2, 2, 0, '{"required":"0","placeholder":"please use ‘;’
to split keyword","rule":""}', '2022-09-22 00:15:56.158', '2022-09-22
00:23:36.169');
INSERT INTO "public"."plugin_handle" VALUES ('1529402613204172829', '38',
'maskType', 'maskType', 3, 2, 1,
'{"required":"0","defaultValue":"dataMaskByMD5","rule":""}', '2022-09-22
00:16:27.342', '2022-09-22 00:16:27.342');
INSERT INTO "public"."plugin_handle" VALUES ('1529402613204172830', '38',
'maskStatus', 'maskStatus', 3, 2, 2,
'{"required":"0","defaultValue":"false","rule":""}', '2022-09-22 00:17:21.150',
'2022-09-22 00:17:21.150');
+
+/* insert plugin for keyAuth */
+INSERT INTO "public"."plugin" VALUES ('40', 'keyAuth', NULL, 'Authentication',
150, 0, '2022-07-24 19:00:00', '2022-07-24 19:00:00');
diff --git a/shenyu-admin/src/main/resources/sql-script/h2/schema.sql
b/shenyu-admin/src/main/resources/sql-script/h2/schema.sql
index 885aabe0b..3eef9394b 100755
--- a/shenyu-admin/src/main/resources/sql-script/h2/schema.sql
+++ b/shenyu-admin/src/main/resources/sql-script/h2/schema.sql
@@ -532,6 +532,8 @@ INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`,
`config`, `enabled`)
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`,
`enabled`) VALUES ('36', 'loggingTencentCls', 'Logging', 176, '{"endpoint":
"ap-guangzhou.cls.tencentcs.com", "topic": "shenyu-topic"}', '0');
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`,
`enabled`) VALUES ('38', 'loggingClickHouse', 'Logging', 195,
'{"host":"127.0.0.1","port":"8123","databse":"shenyu-gateway","username":"foo","password":"bar"}',
'0');
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`,
`enabled`) VALUES ('39', 'casdoor', 'Authentication', 40,
'{"endpoint":"http://localhost:8000"}', '0');
+INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `enabled`) VALUES
('40', 'keyAuth', 'Authentication', 150, '0');
+
/*insert plugin_handle data for sentinel*/
INSERT IGNORE INTO plugin_handle (`id`,
`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`) VALUES
('1529402613195784246', '10', 'flowRuleGrade', 'flowRuleGrade', 3, 2, 8,
'{"required":"1","defaultValue":"1","rule":""}');
INSERT IGNORE INTO plugin_handle (`id`,
`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`) VALUES
('1529402613199978496', '10', 'flowRuleControlBehavior',
'flowRuleControlBehavior', 3, 2, 5,
'{"required":"1","defaultValue":"0","rule":""}');
diff --git a/shenyu-bootstrap/pom.xml b/shenyu-bootstrap/pom.xml
index 4ba2de65c..88d150633 100644
--- a/shenyu-bootstrap/pom.xml
+++ b/shenyu-bootstrap/pom.xml
@@ -257,6 +257,14 @@
<version>${project.version}</version>
</dependency>
+ <!--shenyu key-auth plugin start-->
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-spring-boot-starter-plugin-key-auth</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <!--shenyu key-auth plugin end -->
+
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
diff --git
a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/rule/impl/KeyAuthRuleHandle.java
b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/rule/impl/KeyAuthRuleHandle.java
new file mode 100644
index 000000000..144dadebd
--- /dev/null
+++
b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/rule/impl/KeyAuthRuleHandle.java
@@ -0,0 +1,100 @@
+/*
+ * 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.shenyu.common.dto.convert.rule.impl;
+
+import org.apache.shenyu.common.dto.convert.rule.RuleHandle;
+
+import java.util.Objects;
+
+/**
+ * Key-Auth rule handle.
+ */
+public class KeyAuthRuleHandle implements RuleHandle {
+
+ /**
+ * The key attribute name. It is required.
+ */
+ private String keyName;
+
+ /**
+ * The key value. It is required.
+ */
+ private String key;
+
+ /**
+ * Get key attribute name.
+ *
+ * @return keyName
+ */
+ public String getKeyName() {
+ return keyName;
+ }
+
+ /**
+ * Set key attribute name.
+ *
+ * @param keyName keyName
+ */
+ public void setKeyName(final String keyName) {
+ this.keyName = keyName;
+ }
+
+ /**
+ * Get the key.
+ *
+ * @return key
+ */
+ public String getKey() {
+ return key;
+ }
+
+ /**
+ * Set the key.
+ *
+ * @param key key
+ */
+ public void setKey(final String key) {
+ this.key = key;
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ KeyAuthRuleHandle that = (KeyAuthRuleHandle) o;
+ return Objects.equals(keyName, that.keyName)
+ && Objects.equals(key, that.key);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(keyName, key);
+ }
+
+ @Override
+ public String toString() {
+ return "KeyAuthRuleHandle{"
+ + "keyName='" + keyName
+ + "', key='" + key
+ + "'}";
+ }
+}
diff --git
a/shenyu-common/src/main/java/org/apache/shenyu/common/enums/PluginEnum.java
b/shenyu-common/src/main/java/org/apache/shenyu/common/enums/PluginEnum.java
index dc0055afe..ab21df89a 100644
--- a/shenyu-common/src/main/java/org/apache/shenyu/common/enums/PluginEnum.java
+++ b/shenyu-common/src/main/java/org/apache/shenyu/common/enums/PluginEnum.java
@@ -245,7 +245,12 @@ public enum PluginEnum {
/**
* Response plugin enum.
*/
- RESPONSE(420, 0, "response");
+ RESPONSE(420, 0, "response"),
+
+ /**
+ * Key-auth plugin enum.
+ */
+ KEY_AUTH(430, 0, "keyAuth");
/**
* When the application starts, the plugin is cached and we can obtained
by name.
diff --git
a/shenyu-common/src/test/java/org/apache/shenyu/common/dto/convert/rule/impl/KeyAuthRuleHandleTest.java
b/shenyu-common/src/test/java/org/apache/shenyu/common/dto/convert/rule/impl/KeyAuthRuleHandleTest.java
new file mode 100644
index 000000000..a0a0b5903
--- /dev/null
+++
b/shenyu-common/src/test/java/org/apache/shenyu/common/dto/convert/rule/impl/KeyAuthRuleHandleTest.java
@@ -0,0 +1,40 @@
+/*
+ * 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.shenyu.common.dto.convert.rule.impl;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Test cases for {@link KeyAuthRuleHandle}.
+ */
+public class KeyAuthRuleHandleTest {
+
+ @Test
+ public void testGetterAndSetter() {
+ KeyAuthRuleHandle keyAuthRuleHandle = new KeyAuthRuleHandle();
+
+ keyAuthRuleHandle.setKeyName("apiKey");
+ keyAuthRuleHandle.setKey("123456");
+
+ assertEquals(keyAuthRuleHandle.getKeyName(), "apiKey");
+ assertEquals(keyAuthRuleHandle.getKey(), "123456");
+
+ }
+}
diff --git a/shenyu-plugin/pom.xml b/shenyu-plugin/pom.xml
index fe3341744..46bfd1fcb 100644
--- a/shenyu-plugin/pom.xml
+++ b/shenyu-plugin/pom.xml
@@ -63,5 +63,6 @@
<module>shenyu-plugin-logging</module>
<module>shenyu-plugin-mock</module>
<module>shenyu-plugin-casdoor</module>
+ <module>shenyu-plugin-key-auth</module>
</modules>
</project>
diff --git
a/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/result/ShenyuResultEnum.java
b/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/result/ShenyuResultEnum.java
index 7694c2e25..b0d76cbb7 100644
---
a/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/result/ShenyuResultEnum.java
+++
b/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/result/ShenyuResultEnum.java
@@ -221,7 +221,17 @@ public enum ShenyuResultEnum {
/**
* Request Entity Too Large.
*/
- REQUEST_ENTITY_TOO_LARGE(413, "Request Entity Too Large");
+ REQUEST_ENTITY_TOO_LARGE(413, "Request Entity Too Large"),
+
+ /**
+ * Key attribute name and key not be configured.
+ */
+ KEY_NAME_AND_KEY_MUST_BE_CONFIGURED(-122, "The key attribute name and the
key must be configured"),
+
+ /**
+ * Key is incorrect.
+ */
+ ERROR_KEY(401, "Key is incorrect");
/**
* the code.
diff --git a/shenyu-plugin/shenyu-plugin-key-auth/pom.xml
b/shenyu-plugin/shenyu-plugin-key-auth/pom.xml
new file mode 100644
index 000000000..4a2a65ab5
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-key-auth/pom.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<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">
+ <parent>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-plugin</artifactId>
+ <version>2.5.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>shenyu-plugin-key-auth</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-plugin-base</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.projectreactor</groupId>
+ <artifactId>reactor-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
diff --git
a/shenyu-plugin/shenyu-plugin-key-auth/src/main/java/org/apache/shenyu/plugin/key/auth/KeyAuthPlugin.java
b/shenyu-plugin/shenyu-plugin-key-auth/src/main/java/org/apache/shenyu/plugin/key/auth/KeyAuthPlugin.java
new file mode 100644
index 000000000..041721bb5
--- /dev/null
+++
b/shenyu-plugin/shenyu-plugin-key-auth/src/main/java/org/apache/shenyu/plugin/key/auth/KeyAuthPlugin.java
@@ -0,0 +1,88 @@
+/*
+ * 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.shenyu.plugin.key.auth;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.SelectorData;
+import org.apache.shenyu.common.dto.convert.rule.impl.KeyAuthRuleHandle;
+import org.apache.shenyu.common.enums.PluginEnum;
+import org.apache.shenyu.plugin.api.ShenyuPluginChain;
+import org.apache.shenyu.plugin.api.result.ShenyuResultEnum;
+import org.apache.shenyu.plugin.api.result.ShenyuResultWrap;
+import org.apache.shenyu.plugin.api.utils.WebFluxResultUtils;
+import org.apache.shenyu.plugin.base.AbstractShenyuPlugin;
+import org.apache.shenyu.plugin.base.utils.CacheKeyUtils;
+import org.apache.shenyu.plugin.key.auth.handler.KeyAuthPluginDataHandler;
+import org.springframework.http.HttpHeaders;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+
+import java.util.Objects;
+
+public class KeyAuthPlugin extends AbstractShenyuPlugin {
+
+ @Override
+ public int getOrder() {
+ return PluginEnum.KEY_AUTH.getCode();
+ }
+
+ @Override
+ public String named() {
+ return PluginEnum.KEY_AUTH.getName();
+ }
+
+ @Override
+ protected Mono<Void> doExecute(final ServerWebExchange exchange, final
ShenyuPluginChain chain,
+ final SelectorData selector, final RuleData
rule) {
+
+ KeyAuthRuleHandle keyAuthRuleHandle =
KeyAuthPluginDataHandler.CACHED_HANDLE.get()
+ .obtainHandle(CacheKeyUtils.INST.getKey(rule));
+ if (Objects.isNull(keyAuthRuleHandle) ||
StringUtils.isBlank(keyAuthRuleHandle.getKeyName())
+ || StringUtils.isBlank(keyAuthRuleHandle.getKey())) {
+ Object error = ShenyuResultWrap.error(exchange,
ShenyuResultEnum.KEY_NAME_AND_KEY_MUST_BE_CONFIGURED);
+ return WebFluxResultUtils.result(exchange, error);
+ }
+ if (checkKey(exchange, keyAuthRuleHandle.getKeyName(),
keyAuthRuleHandle.getKey())) {
+ return chain.execute(exchange);
+ }
+ Object error = ShenyuResultWrap.error(exchange,
ShenyuResultEnum.ERROR_KEY);
+ return WebFluxResultUtils.result(exchange, error);
+ }
+
+ /**
+ * Check the key.
+ * @param exchange exchange
+ * @param keyName key attribute name
+ * @param key key
+ * @return whether the key is correct.
+ */
+ private boolean checkKey(final ServerWebExchange exchange, final String
keyName, final String key) {
+ HttpHeaders httpHeaders = exchange.getRequest().getHeaders();
+ if (StringUtils.equals(httpHeaders.getFirst(keyName), key)) {
+ return true;
+ }
+ MultiValueMap<String, String> multiValueMap =
exchange.getRequest().getQueryParams();
+ if (StringUtils.equals(multiValueMap.getFirst(keyName), key)) {
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git
a/shenyu-plugin/shenyu-plugin-key-auth/src/main/java/org/apache/shenyu/plugin/key/auth/handler/KeyAuthPluginDataHandler.java
b/shenyu-plugin/shenyu-plugin-key-auth/src/main/java/org/apache/shenyu/plugin/key/auth/handler/KeyAuthPluginDataHandler.java
new file mode 100644
index 000000000..62e521b64
--- /dev/null
+++
b/shenyu-plugin/shenyu-plugin-key-auth/src/main/java/org/apache/shenyu/plugin/key/auth/handler/KeyAuthPluginDataHandler.java
@@ -0,0 +1,48 @@
+/*
+ * 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.shenyu.plugin.key.auth.handler;
+
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.convert.rule.impl.KeyAuthRuleHandle;
+import org.apache.shenyu.common.enums.PluginEnum;
+import org.apache.shenyu.common.utils.GsonUtils;
+import org.apache.shenyu.plugin.base.cache.CommonHandleCache;
+import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
+import org.apache.shenyu.plugin.base.utils.BeanHolder;
+import org.apache.shenyu.plugin.base.utils.CacheKeyUtils;
+
+import java.util.Optional;
+import java.util.function.Supplier;
+
+public class KeyAuthPluginDataHandler implements PluginDataHandler {
+
+ public static final Supplier<CommonHandleCache<String, KeyAuthRuleHandle>>
CACHED_HANDLE = new BeanHolder<>(CommonHandleCache::new);
+
+ @Override
+ public void handlerRule(final RuleData ruleData) {
+ Optional.ofNullable(ruleData.getHandle()).ifPresent(s -> {
+ final KeyAuthRuleHandle ruleHandle =
GsonUtils.getInstance().fromJson(s, KeyAuthRuleHandle.class);
+
CACHED_HANDLE.get().cachedHandle(CacheKeyUtils.INST.getKey(ruleData),
ruleHandle);
+ });
+ }
+
+ @Override
+ public String pluginNamed() {
+ return PluginEnum.KEY_AUTH.getName();
+ }
+}
diff --git
a/shenyu-plugin/shenyu-plugin-key-auth/src/test/java/org/apache/shenyu/plugin/key/auth/KeyAuthPluginTest.java
b/shenyu-plugin/shenyu-plugin-key-auth/src/test/java/org/apache/shenyu/plugin/key/auth/KeyAuthPluginTest.java
new file mode 100644
index 000000000..934bdba4d
--- /dev/null
+++
b/shenyu-plugin/shenyu-plugin-key-auth/src/test/java/org/apache/shenyu/plugin/key/auth/KeyAuthPluginTest.java
@@ -0,0 +1,134 @@
+/*
+ * 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.shenyu.plugin.key.auth;
+
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.SelectorData;
+import org.apache.shenyu.common.enums.PluginEnum;
+import org.apache.shenyu.plugin.api.ShenyuPluginChain;
+import org.apache.shenyu.plugin.api.result.DefaultShenyuResult;
+import org.apache.shenyu.plugin.api.result.ShenyuResult;
+import org.apache.shenyu.plugin.api.utils.SpringBeanUtils;
+import org.apache.shenyu.plugin.key.auth.handler.KeyAuthPluginDataHandler;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
+import org.springframework.mock.web.server.MockServerWebExchange;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+import reactor.test.StepVerifier;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Test cases for {@link KeyAuthPlugin}.
+ */
+public class KeyAuthPluginTest {
+
+ private KeyAuthPlugin keyAuthPlugin;
+
+ private ServerWebExchange exchange;
+
+ private ShenyuPluginChain chain;
+
+ private SelectorData selectorData;
+
+ private RuleData ruleData;
+
+ private KeyAuthPluginDataHandler keyAuthPluginDataHandler;
+
+ @BeforeEach
+ public void setUp() {
+ keyAuthPlugin = new KeyAuthPlugin();
+ chain = mock(ShenyuPluginChain.class);
+ when(this.chain.execute(any())).thenReturn(Mono.empty());
+ selectorData = mock(SelectorData.class);
+ ruleData = new RuleData();
+ ruleData.setId("keyAuthRule");
+ ruleData.setSelectorId("keyAuth");
+ ruleData.setName("test");
+ keyAuthPluginDataHandler = new KeyAuthPluginDataHandler();
+ ConfigurableApplicationContext context =
mock(ConfigurableApplicationContext.class);
+ when(context.getBean(ShenyuResult.class)).thenReturn(new
DefaultShenyuResult());
+ SpringBeanUtils.getInstance().setApplicationContext(context);
+ }
+
+ @Test
+ public void testNotConfigured() {
+ ruleData.setHandle("{}");
+ keyAuthPluginDataHandler.handlerRule(ruleData);
+ exchange = MockServerWebExchange.from(MockServerHttpRequest
+ .get("localhost")
+ .build());
+ Mono<Void> mono = keyAuthPlugin.doExecute(exchange, chain,
selectorData, ruleData);
+ StepVerifier.create(mono).expectSubscription().verifyComplete();
+ }
+
+ @Test
+ public void testKeyAuthWithHeaderCredentials() {
+ ruleData.setHandle("{\"keyName\":\"apiKey\",\"key\":\"key\","
+ + "\"hideCredentials\":\"false\"}");
+ keyAuthPluginDataHandler.handlerRule(ruleData);
+ exchange = MockServerWebExchange.from(MockServerHttpRequest
+ .get("localhost")
+ .header("apiKey", "key")
+ .build());
+ Mono<Void> mono = keyAuthPlugin.doExecute(exchange, chain,
selectorData, ruleData);
+ StepVerifier.create(mono).expectSubscription().verifyComplete();
+ }
+
+ @Test
+ public void testKeyAuthWithQueryCredentials() {
+ ruleData.setHandle("{\"keyName\":\"apiKey\",\"key\":\"key\","
+ + "\"hideCredentials\":\"false\"}");
+ keyAuthPluginDataHandler.handlerRule(ruleData);
+ exchange = MockServerWebExchange.from(MockServerHttpRequest
+ .get("localhost")
+ .queryParam("apiKey", "key")
+ .build());
+ Mono<Void> mono = keyAuthPlugin.doExecute(exchange, chain,
selectorData, ruleData);
+ StepVerifier.create(mono).expectSubscription().verifyComplete();
+ }
+
+ @Test
+ public void testKeyAuthWithIncorrectKey() {
+ ruleData.setHandle("{\"keyName\":\"apiKey\",\"key\":\"key\","
+ + "\"hideCredentials\":\"false\"}");
+ keyAuthPluginDataHandler.handlerRule(ruleData);
+ exchange = MockServerWebExchange.from(MockServerHttpRequest
+ .get("localhost")
+ .header("apiKey", "123456")
+ .build());
+ Mono<Void> mono = keyAuthPlugin.doExecute(exchange, chain,
selectorData, ruleData);
+ StepVerifier.create(mono).expectSubscription().verifyComplete();
+ }
+
+ @Test
+ public void testNamed() {
+ assertEquals(PluginEnum.KEY_AUTH.getName(), keyAuthPlugin.named());
+ }
+
+ @Test
+ public void testGetOrder() {
+ assertEquals(PluginEnum.KEY_AUTH.getCode(), keyAuthPlugin.getOrder());
+ }
+}
diff --git
a/shenyu-plugin/shenyu-plugin-key-auth/src/test/java/org/apache/shenyu/plugin/key/auth/handler/KeyAuthPluginDataHandlerTest.java
b/shenyu-plugin/shenyu-plugin-key-auth/src/test/java/org/apache/shenyu/plugin/key/auth/handler/KeyAuthPluginDataHandlerTest.java
new file mode 100644
index 000000000..14310b2bf
--- /dev/null
+++
b/shenyu-plugin/shenyu-plugin-key-auth/src/test/java/org/apache/shenyu/plugin/key/auth/handler/KeyAuthPluginDataHandlerTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.shenyu.plugin.key.auth.handler;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.convert.rule.impl.KeyAuthRuleHandle;
+import org.apache.shenyu.common.enums.PluginEnum;
+import org.apache.shenyu.plugin.base.utils.CacheKeyUtils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Test cases for {@link KeyAuthPluginDataHandler}.
+ */
+public class KeyAuthPluginDataHandlerTest {
+
+ private KeyAuthPluginDataHandler keyAuthPluginDataHandler;
+
+ private String handleString;
+
+ @BeforeEach
+ public void setUp() {
+ keyAuthPluginDataHandler = new KeyAuthPluginDataHandler();
+ handleString = "{\"keyName\":\"apiKey\""
+ + ",\"key\":\"key\"}";
+ }
+
+ @Test
+ public void testHandlerRule() {
+ RuleData ruleData = new RuleData();
+ ruleData.setId("keyAuthRule");
+ ruleData.setSelectorId("keyAuth");
+ ruleData.setHandle(handleString);
+ keyAuthPluginDataHandler.handlerRule(ruleData);
+
+ KeyAuthRuleHandle testRuleHandle =
KeyAuthPluginDataHandler.CACHED_HANDLE.get().obtainHandle(CacheKeyUtils.INST.getKey(ruleData));
+ assertTrue(StringUtils.equals(testRuleHandle.getKeyName(), "apiKey"));
+ assertTrue(StringUtils.equals(testRuleHandle.getKey(), "key"));
+ }
+
+ @Test
+ public void testPluginNamed() {
+ assertEquals(keyAuthPluginDataHandler.pluginNamed(),
PluginEnum.KEY_AUTH.getName());
+ }
+
+}
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/pom.xml
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/pom.xml
index 3dae402ef..8b54ec5de 100644
--- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/pom.xml
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/pom.xml
@@ -68,5 +68,6 @@
<module>shenyu-spring-boot-starter-plugin-logging-tencent-cls</module>
<module>shenyu-spring-boot-starter-plugin-logging-clickhouse</module>
<module>shenyu-spring-boot-starter-plugin-casdoor</module>
+ <module>shenyu-spring-boot-starter-plugin-key-auth</module>
</modules>
</project>
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-key-auth/pom.xml
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-key-auth/pom.xml
new file mode 100644
index 000000000..f6bfe2cc8
--- /dev/null
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-key-auth/pom.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<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">
+ <parent>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-spring-boot-starter-plugin</artifactId>
+ <version>2.5.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>shenyu-spring-boot-starter-plugin-key-auth</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-plugin-key-auth</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-key-auth/src/main/java/org/apache/shenyu/springboot/starter/plugin/key/auth/KeyAuthPluginConfiguration.java
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-key-auth/src/main/java/org/apache/shenyu/springboot/starter/plugin/key/auth/KeyAuthPluginConfiguration.java
new file mode 100644
index 000000000..3ff174c96
--- /dev/null
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-key-auth/src/main/java/org/apache/shenyu/springboot/starter/plugin/key/auth/KeyAuthPluginConfiguration.java
@@ -0,0 +1,52 @@
+/*
+ * 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.shenyu.springboot.starter.plugin.key.auth;
+
+import org.apache.shenyu.plugin.api.ShenyuPlugin;
+import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
+import org.apache.shenyu.plugin.key.auth.KeyAuthPlugin;
+import org.apache.shenyu.plugin.key.auth.handler.KeyAuthPluginDataHandler;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * The type KeyAuth plugin configuration.
+ */
+@Configuration
+public class KeyAuthPluginConfiguration {
+
+ /**
+ * KeyAuth plugin.
+ *
+ * @return KeyAuth plugin
+ */
+ @Bean
+ public ShenyuPlugin keyAuthPlugin() {
+ return new KeyAuthPlugin();
+ }
+
+ /**
+ * KeyAuth plugin data handler.
+ *
+ * @return KeyAuthPluginDataHandler
+ */
+ @Bean
+ public PluginDataHandler keyAuthPluginDataHandler() {
+ return new KeyAuthPluginDataHandler();
+ }
+}
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-key-auth/src/main/resources/META-INF/spring.factories
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-key-auth/src/main/resources/META-INF/spring.factories
new file mode 100644
index 000000000..dbfc87276
--- /dev/null
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-key-auth/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+org.apache.shenyu.springboot.starter.plugin.key.auth.KeyAuthPluginConfiguration
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-key-auth/src/main/resources/META-INF/spring.provides
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-key-auth/src/main/resources/META-INF/spring.provides
new file mode 100644
index 000000000..a47db14cb
--- /dev/null
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-key-auth/src/main/resources/META-INF/spring.provides
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+provides: shenyu-spring-boot-starter-plugin-key-auth
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-key-auth/src/test/java/org/apache/shenyu/springboot/starter/plugin/key/auth/KeyAuthPluginConfigurationTest.java
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-key-auth/src/test/java/org/apache/shenyu/springboot/starter/plugin/key/auth/KeyAuthPluginConfigurationTest.java
new file mode 100644
index 000000000..2fd4b3def
--- /dev/null
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-key-auth/src/test/java/org/apache/shenyu/springboot/starter/plugin/key/auth/KeyAuthPluginConfigurationTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.shenyu.springboot.starter.plugin.key.auth;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Test cases for {@link KeyAuthPluginConfiguration}.
+ */
+public class KeyAuthPluginConfigurationTest {
+
+ private ApplicationContextRunner applicationContextRunner;
+
+ @BeforeEach
+ public void setUp() {
+ applicationContextRunner = new ApplicationContextRunner()
+
.withConfiguration(AutoConfigurations.of(KeyAuthPluginConfiguration.class))
+ .withBean(KeyAuthPluginConfigurationTest.class)
+ .withPropertyValues("debug=true");
+ }
+
+ @Test
+ public void testKeyAuthPlugin() {
+ applicationContextRunner.run(context ->
assertNotNull(context.getBean("keyAuthPlugin")));
+ }
+
+ @Test
+ public void testKeyAuthPluginDataHandler() {
+ applicationContextRunner.run(context ->
assertNotNull(context.getBean("keyAuthPluginDataHandler")));
+ }
+
+}