You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by he...@apache.org on 2023/11/09 02:09:28 UTC
(shenyu) branch master updated: [ISSUE #3713][resolved #3774] Add new plugin: basic-auth (#5258)
This is an automated email from the ASF dual-hosted git repository.
hefengen 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 c19f7eb387 [ISSUE #3713][resolved #3774] Add new plugin: basic-auth (#5258)
c19f7eb387 is described below
commit c19f7eb3878573187e4fc278f4885c5fb6e771a6
Author: Kerwin Bryant <ke...@qq.com>
AuthorDate: Thu Nov 9 10:09:21 2023 +0800
[ISSUE #3713][resolved #3774] Add new plugin: basic-auth (#5258)
* merged #3774 into kerwin612:master
* Optimize & improve code; add test cases;
* Move shenyu-plugin-basic-auth from shenyu-plugin/ to shenyu-plugin/shenyu-plugin-security/
* Remove unused code
* Perfecting db scripts
* Fix ci feedback error
* Fix database script errors
* Update 2.6.0-upgrade-2.6.1-mysql.sql
* Update schema.sql
* Update CommonPluginDataSubscriber.java
* Update schema.sql
* Update schema.sql
* Update schema.sql
* Update 2.6.0-upgrade-2.6.1-mysql.sql
* Adjust the order of basic-auth-plugin to follow jwt
* use Optional.ofNullable
---------
Co-authored-by: moremind <he...@apache.org>
---
db/init/mysql/schema.sql | 3 +
db/init/og/create-table.sql | 2 +
db/init/oracle/schema.sql | 4 +
db/init/pg/create-table.sql | 2 +
db/upgrade/2.6.0-upgrade-2.6.1-mysql.sql | 20 +--
db/upgrade/2.6.0-upgrade-2.6.1-og.sql | 4 +
db/upgrade/2.6.0-upgrade-2.6.1-oracle.sql | 5 +
db/upgrade/2.6.0-upgrade-2.6.1-pg.sql | 4 +
.../src/main/resources/sql-script/h2/schema.sql | 3 +
shenyu-bootstrap/pom.xml | 8 ++
.../apache/shenyu/common/constant/Constants.java | 5 +
.../org/apache/shenyu/common/enums/PluginEnum.java | 7 +-
shenyu-plugin/pom.xml | 4 +-
.../base/cache/CommonPluginDataSubscriber.java | 2 +-
shenyu-plugin/shenyu-plugin-security/pom.xml | 8 +-
.../{ => shenyu-plugin-basic-auth}/pom.xml | 95 ++++++++-------
.../shenyu/plugin/basic/auth/BasicAuthPlugin.java | 74 +++++++++++
.../plugin/basic/auth/config/BasicAuthConfig.java | 49 ++++++++
.../auth/handle/BasicAuthPluginDataHandler.java | 72 +++++++++++
.../basic/auth/rule/BasicAuthRuleHandle.java | 96 +++++++++++++++
.../auth/rule/DefaultBasicAuthRuleHandle.java | 44 +++++++
.../strategy/BasicAuthAuthenticationStrategy.java | 47 +++++++
.../BasicAuthAuthenticationStrategyFactory.java | 38 ++++++
.../DefaultBasicAuthAuthenticationStrategy.java | 46 +++++++
...c.auth.strategy.BasicAuthAuthenticationStrategy | 17 +++
.../plugin/basic/auth/BasicAuthPluginTest.java | 135 +++++++++++++++++++++
.../handle/BasicAuthPluginDataHandlerTest.java | 74 +++++++++++
.../basic/auth/rule/BasicAuthRuleHandleTest.java | 42 +++++++
.../basic/auth/rule/CustomBasicAuthRuleHandle.java | 42 +++++++
.../CustomBasicAuthAuthenticationStrategy.java | 38 ++++++
...DefaultBasicAuthAuthenticationStrategyTest.java | 73 +++++++++++
...c.auth.strategy.BasicAuthAuthenticationStrategy | 17 +++
.../shenyu-spring-boot-starter-plugin/pom.xml | 1 +
.../pom.xml | 85 ++++++-------
.../basic/auth/BasicAuthPluginConfiguration.java | 53 ++++++++
.../src/main/resources/META-INF/spring.factories | 18 +++
.../src/main/resources/META-INF/spring.provides | 18 +++
37 files changed, 1147 insertions(+), 108 deletions(-)
diff --git a/db/init/mysql/schema.sql b/db/init/mysql/schema.sql
index 4b54927e7d..f8af192d0c 100644
--- a/db/init/mysql/schema.sql
+++ b/db/init/mysql/schema.sql
@@ -837,6 +837,7 @@ INSERT INTO `plugin` VALUES ('40', 'keyAuth', NULL, 'Authentication', 150, 0, '2
INSERT INTO `plugin` VALUES ('41', 'brpc', '{\"address\":\"127.0.0.1\", \"port\":\"8005\", \"corethreads\":0, \"threads\":2147483647, \"queues\":0, \"threadpool\":\"shared\"}', 'Proxy', 310, 0, '2023-01-10 10:08:01', '2023-01-10 10:08:01',null);
INSERT INTO `plugin` VALUES ('42', 'tcp', NULL, 'Proxy', 320, 1, '2023-05-30 18:02:53', '2022-05-30 18:02:53',null);
INSERT INTO `plugin` VALUES ('43', 'loggingHuaweiLts', '{\"totalSizeInBytes\":\"104857600\",\"maxBlockMs\":\"0\",\"ioThreadCount\":\"1\",\"batchSizeThresholdInBytes\":\"524288\",\"batchCountThreshold\":\"4096\",\"lingerMs\":\"2000\",\"retries\":\"100\",\"baseRetryBackoffMs\":\"100\",\"maxRetryBackoffMs\":\"100\",\"enableLocalTest\":\"true\",\"setGiveUpExtraLongSingleLog\":\"false\"}', 'Logging', 177, 0, '2023-07-05 14:03:53.686', '2023-07-06 12:42:07.234', NULL);
+INSERT INTO `plugin` VALUES ('44', 'basicAuth', '{\"defaultHandleJson\":\"{\\\"authorization\\\":\\\"test:test123\\\"}\"}', 'Authentication', 150, 0, '2022-07-24 19:00:00', '2022-07-24 19:00:00', null);
-- ----------------------------
-- Table structure for plugin_handle
-- ----------------------------
@@ -1171,6 +1172,8 @@ INSERT INTO `plugin_handle` VALUES ('1678997557628272640', '42', 'clientPendingA
INSERT INTO `plugin_handle` VALUES ('1678997557628272641', '17', 'registerAddress', 'registerAddress', 2, 3, 1, '{\"required\":\"0\",\"defaultValue\":\"127.0.0.1:2181\",\"placeholder\":\"registerAddress\",\"rule\":\"\"}', '2023-01-10 10:08:01.158', '2023-01-10 10:08:01.158');
INSERT INTO `plugin_handle` VALUES ('1678997557628272642', '15', 'loadBalance', 'loadBalance', 3, 2, 3, '{\"required\":\"0\",\"defaultValue\":\"random\",\"rule\":\"\"}', '2023-09-05 18:02:53', '2023-09-05 18:02:53');
+
+INSERT INTO `plugin_handle` VALUES ('1678997557628272643', '44', 'defaultHandleJson', 'defaultHandleJson', 2, 3, 2, '{\"required\":\"0\",\"defaultValue\":\"{\\\"authorization\\\":\\\"test:test123\\\"}\",\"placeholder\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53');
-- ----------------------------
-- Table structure for resource
-- ----------------------------
diff --git a/db/init/og/create-table.sql b/db/init/og/create-table.sql
index 020dda3706..975e3462dd 100644
--- a/db/init/og/create-table.sql
+++ b/db/init/og/create-table.sql
@@ -972,6 +972,7 @@ INSERT INTO "public"."plugin" VALUES ('40', 'keyAuth', NULL, 'Authentication', 1
INSERT INTO "public"."plugin" VALUES ('41', 'brpc', '{"address":"127.0.0.1","port":"8005","corethreads":0,"threads":2147483647,"queues":0,"threadpool":"shared"}', 'Proxy', 310, 0, '2023-01-10 10:08:01', '2023-01-10 10:08:01', null);
INSERT INTO "public"."plugin" VALUES ('42', 'tcp', null, 'Proxy', 320, 1, '2022-05-25 18:08:01', '2022-05-25 18:08:01', null);
INSERT INTO "public"."plugin" VALUES ('43', 'loggingHuaweiLts', '{ "totalSizeInBytes": "104857600","maxBlockMs":"0","ioThreadCount":"1","batchSizeThresholdInBytes":"524288","batchCountThreshold":"4096","lingerMs":"2000","retries":"100","baseRetryBackoffMs":"100","maxRetryBackoffMs":"100","enableLocalTest":"true","setGiveUpExtraLongSingleLog":"false"}', 'Logging', 177, 0, '2023-07-05 14:03:53', '2023-07-06 12:42:07', null);
+INSERT INTO "public"."plugin" VALUES ('44', 'basicAuth', '{"defaultHandleJson":"{\"authorization\":\"test:test123\"}"}', 'Authentication', 150, 0, '2022-07-24 19:00:00', '2022-07-24 19:00:00', null);
-- ----------------------------
-- Table structure for plugin_handle
-- ----------------------------
@@ -1321,6 +1322,7 @@ INSERT INTO "public"."plugin_handle" VALUES ('1678997769998467072', '42', 'clien
INSERT INTO "public"."plugin_handle" VALUES ('1678997277012557824', '42', 'clientMaxConnections', 'clientMaxConnections', 2, 1, 6, '{"required":"0","defaultValue":"20","rule":""}');
INSERT INTO "public"."plugin_handle" VALUES ('1678997557628272640', '42', 'clientPendingAcquireTimeout', 'clientPendingAcquireTimeout', 2, 1, 5, '{"required":"0","defaultValue":"5","rule":""}');
INSERT INTO "public"."plugin_handle" VALUES ('1570591265492312085', '6', 'loadBalance', 'loadBalance', 3, 2, 3, '{"required":"0","defaultValue":"random","rule":""}', '2023-09-05 18:08:01', '2023-09-05 18:08:01');
+INSERT INTO "public"."plugin_handle" VALUES ('1570591265492312086', '44', 'defaultHandleJson', 'defaultHandleJson', 2, 3, 2, '{"required":"0","defaultValue":"{\"authorization\":\"test:test123\"}","placeholder":""}', '2022-05-25 18:02:53', '2022-05-25 18:02:53');
-- ----------------------------
-- Table structure for resource
-- ----------------------------
diff --git a/db/init/oracle/schema.sql b/db/init/oracle/schema.sql
index 45d28a4bd6..b84a48c85a 100644
--- a/db/init/oracle/schema.sql
+++ b/db/init/oracle/schema.sql
@@ -1150,6 +1150,7 @@ INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name, role
INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name, role, sort, config, enabled) VALUES ('41', 'brpc', 'Proxy', 310,'{"address":"127.0.0.1","port":"8005","corethreads":0,"threads":2147483647,"queues":0,"threadpool":"shared"}','0');
INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name, role, sort, config, enabled) VALUES ('42', 'tcp', 'Proxy', 320, null, '1');
INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name, role, sort, config, enabled) VALUES ('43', 'loggingHuaweiLts', 'Logging', 177, '{"totalSizeInBytes":"104857600","maxBlockMs":"0","ioThreadCount":"1","batchSizeThresholdInBytes":"524288","batchCountThreshold":"4096","lingerMs":"2000","retries":"100","baseRetryBackoffMs":"100","maxRetryBackoffMs":"100","enableLocalTest":"true","setGiveUpExtraLongSingleLog":"false"}','0');
+INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name, role, sort, config, enabled) VALUES ('44', 'basicAuth', 'Authentication', 150, '{"defaultHandleJson":"{\"authorization\":\"test:test123\"}"}','0');
@@ -2082,6 +2083,9 @@ VALUES ('1678997557628272640', '42', 'clientPendingAcquireTimeout', 'clientPendi
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 ('1529402613204172883', '15', 'loadBalance', 'loadBalance', 3, 2, 3, '{"required":"0","defaultValue":"random","rule":""}');
+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 ('1529402613204172884', '44', 'defaultHandleJson', 'defaultHandleJson', 2, 3, 2, '{"required":"0","defaultValue":"{\"authorization\":\"test:test123\"}","placeholder":""}');
+
insert /*+ IGNORE_ROW_ON_DUPKEY_INDEX(shenyu_dict(type, dict_code, dict_name)) */ into SHENYU_DICT (ID, TYPE, DICT_CODE, DICT_NAME, DICT_VALUE, "desc", SORT, ENABLED)
VALUES ('1529402613195784272', 'securityProtocol', 'SECURITY_PROTOCOL', 'PLAINTEXT', 'PLAINTEXT', '', 1, 1);
diff --git a/db/init/pg/create-table.sql b/db/init/pg/create-table.sql
index 458388dcb1..73a3c51988 100644
--- a/db/init/pg/create-table.sql
+++ b/db/init/pg/create-table.sql
@@ -972,6 +972,7 @@ INSERT INTO "public"."plugin" VALUES ('40', 'keyAuth', NULL, 'Authentication', 1
INSERT INTO "public"."plugin" VALUES ('41', 'brpc', '{"address":"127.0.0.1","port":"8005","corethreads":0,"threads":2147483647,"queues":0,"threadpool":"shared"}', 'Proxy', 310, 0, '2023-01-10 10:08:01', '2023-01-10 10:08:01', null);
INSERT INTO "public"."plugin" VALUES ('42', 'tcp', null, 'Proxy', 320, 1, '2022-05-25 18:08:01', '2022-05-25 18:08:01', null);
INSERT INTO "public"."plugin" VALUES ('43', 'loggingHuaweiLts', '{ "totalSizeInBytes": "104857600","maxBlockMs":"0","ioThreadCount":"1","batchSizeThresholdInBytes":"524288","batchCountThreshold":"4096","lingerMs":"2000","retries":"100","baseRetryBackoffMs":"100","maxRetryBackoffMs":"100","enableLocalTest":"true","setGiveUpExtraLongSingleLog":"false"}', 'Logging', 177, 0, '2023-07-05 14:03:53', '2023-07-06 12:42:07', null);
+INSERT INTO "public"."plugin" VALUES ('44', 'basicAuth', '{"defaultHandleJson":"{\"authorization\":\"test:test123\"}"}', 'Authentication', 150, 0, '2022-07-24 19:00:00', '2022-07-24 19:00:00', null);
-- ----------------------------
-- Table structure for plugin_handle
-- ----------------------------
@@ -1321,6 +1322,7 @@ INSERT INTO "public"."plugin_handle" VALUES ('1678997277012557824', '42', 'clien
INSERT INTO "public"."plugin_handle" VALUES ('1678997557628272640', '42', 'clientPendingAcquireTimeout', 'clientPendingAcquireTimeout', 2, 1, 5, '{"required":"0","defaultValue":"5","rule":""}');
INSERT INTO "public"."plugin_handle" VALUES ('1570591265492312085', '6', 'loadBalance', 'loadStrategy', 3, 2, 0, NULL, '2022-05-25 18:08:01', '2022-05-25 18:08:01');
+INSERT INTO "public"."plugin_handle" VALUES ('1570591265492312086', '44', 'defaultHandleJson', 'defaultHandleJson', 2, 3, 2, '{"required":"0","defaultValue":"{\"authorization\":\"test:test123\"}","placeholder":""}', '2022-05-25 18:02:53', '2022-05-25 18:02:53');
-- ----------------------------
-- Table structure for resource
-- ----------------------------
diff --git a/db/upgrade/2.6.0-upgrade-2.6.1-mysql.sql b/db/upgrade/2.6.0-upgrade-2.6.1-mysql.sql
index 2faf53f195..b294813211 100755
--- a/db/upgrade/2.6.0-upgrade-2.6.1-mysql.sql
+++ b/db/upgrade/2.6.0-upgrade-2.6.1-mysql.sql
@@ -17,23 +17,23 @@
-- this file works for MySQL.
INSERT INTO `shenyu_dict` VALUES ('1629402613195884213', 'operator', 'OPERATOR', 'isBlank', 'isBlank', 'isBlank', 10, 1, '2023-08-10 11:11:18', '2023-08-10 11:11:18');
---- clickhouse plugin
+-- clickhouse plugin
INSERT INTO `plugin_handle` VALUES ('1529402613204172777', '38', 'ttl', 'ttl', 3, 3, 10, '{\"required\":\"0\",\"defaultValue\":\"30\"}', '2023-03-01 11:14:15', '2023-08-16 11:15:14');
INSERT INTO `shenyu_dict` VALUES ('1572621976689762310', 'engine', 'engine', 'ReplicatedReplicatedMergeTree', 'ReplicatedReplicatedMergeTree', '', 2, 1, '2023-03-01 11:14:15', '2023-08-16 11:15:14');
INSERT INTO `shenyu_dict` VALUES ('1572621976689762311', 'engine', 'engine', 'ReplicatedMergeTree', 'ReplicatedMergeTree', '', 3, 1, '2023-03-01 11:14:15', '2023-08-16 11:15:14');
----- clickhouse plugin end
+-- clickhouse plugin end
---elasticsearch plugin
+-- elasticsearch plugin
UPDATE `shenyu`.`plugin_handle` SET `plugin_id` = '32', `field` = 'indexName', `label` = 'indexName', `data_type` = 2, `type` = 3, `sort` = 10, `ext_obj` = '{\"required\":\"0\",\"defaultValue\":\"shenyu-access-logging\"}', `date_created` = '2022-06-19 22:00:00.000', `date_updated` = '2023-08-31 22:28:28.353' WHERE `plugin_id` = '32' and field = 'index';
---elasticsearch plugin end
+-- elasticsearch plugin end
---dubbbo plugin
+-- dubbbo plugin
UPDATE `shenyu`.`plugin_handle` SET `plugin_id` = '6', `field` = 'loadBalance', `label` = 'loadStrategy', `data_type` = 3, `type` = 2, `sort` = 0, `ext_obj` = NULL, `date_created` = '2022-06-19 22:00:00.000', `date_updated` = '2023-08-31 22:28:28.353' WHERE `plugin_id` = '6' and field = 'loadbalance';
INSERT INTO `plugin_handle` VALUES ('1529402613204173923', '6', 'retries', 'retries', 3, 2, 0, NULL, '2022-05-25 18:02:53', '2022-05-25 18:02:53');
INSERT INTO `plugin_handle` VALUES ('1529402613204173924', '6', 'timeout', 'timeout', 3, 2, 0, NULL, '2022-05-25 18:02:53', '2022-05-25 18:02:53');
---dubbbo plugin end
+-- dubbbo plugin end
---alert notice menu
+-- alert notice menu
INSERT INTO `resource` VALUES ('1697141926247763968','1346776175553376256','SHENYU.MENU.SYSTEM.MANAGMENT.ALERT','','/system/alert','',1,3,'alert',0,0,'',1, '2023-08-31 14:59:01','2023-08-31 06:59:01');
INSERT INTO `resource` VALUES ('1697146375729025024', '1697141926247763968', 'SHENYU.BUTTON.SYSTEM.LIST', '', '', '', 2, 0, 'unordered-list', 1, 0, 'system:alert:list', 1, '2023-08-31 15:16:42', '2023-08-31 07:22:07');
INSERT INTO `resource` VALUES ('1697145808210333696','1697141926247763968','SHENYU.BUTTON.SYSTEM.ADD','','','',2,0,'plus',1,0,'system:alert:add',1, '2023-08-31 15:14:26','2023-08-31 07:14:26');
@@ -45,7 +45,7 @@ INSERT INTO `permission` VALUES ('1697145808239693824','1346358560427216896','16
INSERT INTO `permission` VALUES ('1697146375754190848','1346358560427216896','1697146375729025024', '2023-08-31 15:16:42', '2023-08-31 07:16:42');
INSERT INTO `permission` VALUES ('1697146617543233536','1346358560427216896','1697146617513873408', '2023-08-31 15:17:39', '2023-08-31 07:17:39');
INSERT INTO `permission` VALUES ('1697146860569595904','1346358560427216896','1697146860540235776', '2023-08-31 15:18:37', '2023-08-31 07:18:37');
---alert notice menu end
+-- alert notice menu end
-- add percentage field for rewrite plugin
INSERT INTO `plugin_handle` VALUES ('1697146860569596304', '3', 'percentage', 'percentage', 1, 2, 3, NULL, '2023-09-15 20:25:53', '2023-09-15 20:25:53');
@@ -89,3 +89,7 @@ CREATE TABLE IF NOT EXISTS `alert_receiver`
UPDATE `shenyu`.`plugin_handle` SET `label` = 'flowRuleEnable 1 or 0' WHERE `id` = '1529402613199978497';
UPDATE `shenyu`.`plugin_handle` SET `label` = 'degradeRuleEnable 1 or 0' WHERE `id` = '1529402613199978499';
+
+
+INSERT INTO `plugin` VALUES ('44', 'basicAuth', '{\"defaultHandleJson\":\"{\\\"authorization\\\":\\\"test:test123\\\"}\"}', 'Authentication', 150, 0, '2022-07-24 19:00:00', '2022-07-24 19:00:00', null);
+INSERT INTO `plugin_handle` VALUES ('1678997557628272643', '44', 'defaultHandleJson', 'defaultHandleJson', 2, 3, 2, '{\"required\":\"0\",\"defaultValue\":\"{\\\"authorization\\\":\\\"test:test123\\\"}\",\"placeholder\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53');
diff --git a/db/upgrade/2.6.0-upgrade-2.6.1-og.sql b/db/upgrade/2.6.0-upgrade-2.6.1-og.sql
index 5f2c0b78ea..0b7ca67dfa 100644
--- a/db/upgrade/2.6.0-upgrade-2.6.1-og.sql
+++ b/db/upgrade/2.6.0-upgrade-2.6.1-og.sql
@@ -97,3 +97,7 @@ COMMENT ON COLUMN "public"."alert_receiver"."date_updated" IS 'update time';
UPDATE "public"."plugin_handle" SET label = 'flowRuleEnable 1 or 0' WHERE id = '1529403902770941954';
UPDATE "public"."plugin_handle" SET label = 'degradeRuleEnable 1 or 0' WHERE id = '1529403902770941956';
+
+
+INSERT INTO "public"."plugin" VALUES ('44', 'basicAuth', '{"defaultHandleJson":"{\"authorization\":\"test:test123\"}"}', 'Authentication', 150, 0, '2022-07-24 19:00:00', '2022-07-24 19:00:00', null);
+INSERT INTO "public"."plugin_handle" VALUES ('1570591265492312086', '44', 'defaultHandleJson', 'defaultHandleJson', 2, 3, 2, '{"required":"0","defaultValue":"{\"authorization\":\"test:test123\"}","placeholder":""}', '2022-05-25 18:02:53', '2022-05-25 18:02:53');
diff --git a/db/upgrade/2.6.0-upgrade-2.6.1-oracle.sql b/db/upgrade/2.6.0-upgrade-2.6.1-oracle.sql
index 867bc0df44..ed5a763f71 100755
--- a/db/upgrade/2.6.0-upgrade-2.6.1-oracle.sql
+++ b/db/upgrade/2.6.0-upgrade-2.6.1-oracle.sql
@@ -132,3 +132,8 @@ update plugin_handle set label = 'flowRuleEnable 1 or 0'
where id = '1518229897206079534';
update plugin_handle set label = 'degradeRuleEnable 1 or 0'
where id = '1518229897206079536';
+
+
+INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name, role, sort, config, enabled) VALUES ('44', 'basicAuth', 'Authentication', 150, '{"defaultHandleJson":"{\"authorization\":\"test:test123\"}"}','0');
+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 ('1529402613204172884', '44', 'defaultHandleJson', 'defaultHandleJson', 2, 3, 2, '{"required":"0","defaultValue":"{\"authorization\":\"test:test123\"}","placeholder":""}');
diff --git a/db/upgrade/2.6.0-upgrade-2.6.1-pg.sql b/db/upgrade/2.6.0-upgrade-2.6.1-pg.sql
index 83a80212a2..d70f30fda8 100755
--- a/db/upgrade/2.6.0-upgrade-2.6.1-pg.sql
+++ b/db/upgrade/2.6.0-upgrade-2.6.1-pg.sql
@@ -99,3 +99,7 @@ COMMENT ON COLUMN "public"."alert_receiver"."date_updated" IS 'update time';
UPDATE "public"."plugin_handle" SET label = 'flowRuleEnable 1 or 0' WHERE id = '1529403902770941954';
UPDATE "public"."plugin_handle" SET label = 'degradeRuleEnable 1 or 0' WHERE id = '1529403902770941956';
+
+
+INSERT INTO "public"."plugin" VALUES ('44', 'basicAuth', '{"defaultHandleJson":"{\"authorization\":\"test:test123\"}"}', 'Authentication', 150, 0, '2022-07-24 19:00:00', '2022-07-24 19:00:00', null);
+INSERT INTO "public"."plugin_handle" VALUES ('1570591265492312086', '44', 'defaultHandleJson', 'defaultHandleJson', 2, 3, 2, '{"required":"0","defaultValue":"{\"authorization\":\"test:test123\"}","placeholder":""}', '2022-05-25 18:02:53', '2022-05-25 18:02:53');
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 917133c938..f96f8d578b 100755
--- a/shenyu-admin/src/main/resources/sql-script/h2/schema.sql
+++ b/shenyu-admin/src/main/resources/sql-script/h2/schema.sql
@@ -549,6 +549,7 @@ INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `enabled`) VALUES ('4
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`, `enabled`) VALUES ('41', 'brpc', 'Proxy', 310,'{"address":"127.0.0.1","port":"8005","corethreads":0,"threads":2147483647,"queues":0,"threadpool":"shared"}','0');
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `enabled`) VALUES ('42','tcp','Proxy', 320, '1');
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`, `enabled`) VALUES ('43', 'loggingHuaweiLts', 'Logging', 177, '{ "totalSizeInBytes":"104857600","maxBlockMs":"0","ioThreadCount":"1","batchSizeThresholdInBytes":"524288","batchCountThreshold":"4096","lingerMs":"2000","retries":"100","baseRetryBackoffMs":"100","maxRetryBackoffMs":"100","enableLocalTest":"true","setGiveUpExtraLongSingleLog":"false"}', '0');
+INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`, `enabled`) VALUES ('44', 'basicAuth', 'Authentication', 500, '{"defaultHandleJson":"{\"authorization\":\"test:test123\"}"}', '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":""}');
@@ -869,6 +870,8 @@ INSERT IGNORE INTO plugin_handle (`id`, `plugin_id`,`field`,`label`,`data_type`,
INSERT IGNORE INTO plugin_handle (`id`, `plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`) VALUES ('1678997557628272642', '15', 'loadBalance', 'loadBalance', 3, 2, 3, '{"required":"0","defaultValue":"random","rule":""}');
+INSERT IGNORE INTO plugin_handle (`id`, `plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`) VALUES ('1678997557628272643', '44', 'defaultHandleJson', 'defaultHandleJson', 2, 3, 2, '{"required":"0","defaultValue":"{\"authorization\":\"test:test123\"}","placeholder":""}');
+
/** insert resource for resource */
INSERT IGNORE INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`) VALUES('1346775491550474240','','SHENYU.MENU.PLUGIN.LIST','plug','/plug','PluginList','0','0','dashboard','0','0','','1');
diff --git a/shenyu-bootstrap/pom.xml b/shenyu-bootstrap/pom.xml
index e99f2a0cf3..b039f7210f 100644
--- a/shenyu-bootstrap/pom.xml
+++ b/shenyu-bootstrap/pom.xml
@@ -615,6 +615,14 @@
<!-- </dependency>-->
<!-- shenyu kubernetes controller end -->
+ <!-- shenyu basic-auth plugin start -->
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-spring-boot-starter-plugin-basic-auth</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <!-- shenyu basic-auth plugin end -->
+
</dependencies>
<profiles>
<profile>
diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java
index 935acd06c3..4f00e94c14 100644
--- a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java
+++ b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java
@@ -367,6 +367,11 @@ public interface Constants {
*/
String SECRET_KEY = "secretKey";
+ /**
+ * basicAuth handle key for defaultHandleJson.
+ */
+ String DEFAULT_HANDLE_JSON = "defaultHandleJson";
+
/**
* local 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 bfdf11e100..e8495d1750 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
@@ -265,7 +265,12 @@ public enum PluginEnum {
/**
* Key-auth plugin enum.
*/
- KEY_AUTH(430, 0, "keyAuth");
+ KEY_AUTH(430, 0, "keyAuth"),
+
+ /**
+ * Basic-auth plugin enum.
+ */
+ BASIC_AUTH(35, 0, "basicAuth");
/**
* When the application starts, the plugin is cached and we can obtained by name.
diff --git a/shenyu-plugin/pom.xml b/shenyu-plugin/pom.xml
index 6996d31f07..91ad1d811c 100644
--- a/shenyu-plugin/pom.xml
+++ b/shenyu-plugin/pom.xml
@@ -25,7 +25,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>shenyu-plugin</artifactId>
<packaging>pom</packaging>
-
+
<modules>
<module>shenyu-plugin-api</module>
<module>shenyu-plugin-base</module>
@@ -66,5 +66,5 @@
<scope>test</scope>
</dependency>
</dependencies>
-
+
</project>
diff --git a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/CommonPluginDataSubscriber.java b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/CommonPluginDataSubscriber.java
index a22fa26d3c..c531b93a9b 100644
--- a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/CommonPluginDataSubscriber.java
+++ b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/CommonPluginDataSubscriber.java
@@ -112,7 +112,7 @@ public class CommonPluginDataSubscriber implements PluginDataSubscriber {
@Override
public void onSubscribe(final PluginData pluginData) {
- LOG.info("subscribe plugin data for plugin: [id: {}, name: {}]", pluginData.getId(), pluginData.getName());
+ LOG.info("subscribe plugin data for plugin: [id: {}, name: {}, config: {}]", pluginData.getId(), pluginData.getName(), pluginData.getConfig());
subscribeDataHandler(pluginData, DataEventTypeEnum.UPDATE);
}
diff --git a/shenyu-plugin/shenyu-plugin-security/pom.xml b/shenyu-plugin/shenyu-plugin-security/pom.xml
index 24ce969c96..47768b3dfc 100644
--- a/shenyu-plugin/shenyu-plugin-security/pom.xml
+++ b/shenyu-plugin/shenyu-plugin-security/pom.xml
@@ -6,9 +6,9 @@
~ 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.
@@ -33,7 +33,7 @@
<module>shenyu-plugin-oauth2</module>
<module>shenyu-plugin-sign</module>
<module>shenyu-plugin-cryptor</module>
-
+ <module>shenyu-plugin-basic-auth</module>
</modules>
<dependencies>
@@ -43,4 +43,4 @@
<version>${project.version}</version>
</dependency>
</dependencies>
-</project>
\ No newline at end of file
+</project>
diff --git a/shenyu-plugin/shenyu-plugin-security/pom.xml b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/pom.xml
old mode 100644
new mode 100755
similarity index 62%
copy from shenyu-plugin/shenyu-plugin-security/pom.xml
copy to shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/pom.xml
index 24ce969c96..c6c54bd705
--- a/shenyu-plugin/shenyu-plugin-security/pom.xml
+++ b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/pom.xml
@@ -1,46 +1,49 @@
-<?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">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.shenyu</groupId>
- <artifactId>shenyu-plugin</artifactId>
- <version>2.6.1-SNAPSHOT</version>
- </parent>
- <artifactId>shenyu-plugin-security</artifactId>
- <packaging>pom</packaging>
-
- <modules>
- <module>shenyu-plugin-casdoor</module>
- <module>shenyu-plugin-jwt</module>
- <module>shenyu-plugin-key-auth</module>
- <module>shenyu-plugin-oauth2</module>
- <module>shenyu-plugin-sign</module>
- <module>shenyu-plugin-cryptor</module>
-
- </modules>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.shenyu</groupId>
- <artifactId>shenyu-plugin-base</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
-</project>
\ No newline at end of file
+<?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-security</artifactId>
+ <version>2.6.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>shenyu-plugin-basic-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>
diff --git a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/BasicAuthPlugin.java b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/BasicAuthPlugin.java
new file mode 100755
index 0000000000..938278aee3
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/BasicAuthPlugin.java
@@ -0,0 +1,74 @@
+/*
+ * 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.basic.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.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.basic.auth.handle.BasicAuthPluginDataHandler;
+import org.apache.shenyu.plugin.basic.auth.rule.BasicAuthRuleHandle;
+import org.apache.shenyu.plugin.basic.auth.strategy.BasicAuthAuthenticationStrategy;
+import org.springframework.http.HttpHeaders;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+
+import java.util.Optional;
+
+/**
+ * basic-auth Plugin.
+ */
+public class BasicAuthPlugin extends AbstractShenyuPlugin {
+
+ /**
+ * this is Template Method child has Implement your own logic.
+ *
+ * @param exchange exchange the current server exchange {@linkplain ServerWebExchange}
+ * @param chain chain the current chain {@linkplain ServerWebExchange}
+ * @param selector selector {@linkplain SelectorData}
+ * @param rule rule {@linkplain RuleData}
+ * @return {@code Mono<Void>} to indicate when request handling is complete
+ */
+ @Override
+ protected Mono<Void> doExecute(final ServerWebExchange exchange, final ShenyuPluginChain chain, final SelectorData selector, final RuleData rule) {
+ String authorization = StringUtils.defaultString(exchange.getRequest().getHeaders().getFirst(HttpHeaders.AUTHORIZATION), exchange.getRequest().getURI().getUserInfo());
+ BasicAuthRuleHandle basicAuthRuleHandle = BasicAuthPluginDataHandler.CACHED_HANDLE.get().obtainHandle(CacheKeyUtils.INST.getKey(rule));
+ BasicAuthAuthenticationStrategy authenticationStrategy = Optional.ofNullable(basicAuthRuleHandle).map(BasicAuthRuleHandle::getBasicAuthAuthenticationStrategy).orElse(null);
+
+ if (authenticationStrategy != null && authenticationStrategy.authenticate(basicAuthRuleHandle, authorization)) {
+ return chain.execute(exchange);
+ }
+ return WebFluxResultUtils.result(exchange, ShenyuResultWrap.error(exchange, ShenyuResultEnum.ERROR_TOKEN));
+ }
+
+ @Override
+ public String named() {
+ return PluginEnum.BASIC_AUTH.getName();
+ }
+
+ @Override
+ public int getOrder() {
+ return PluginEnum.BASIC_AUTH.getCode();
+ }
+}
diff --git a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/config/BasicAuthConfig.java b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/config/BasicAuthConfig.java
new file mode 100755
index 0000000000..035236e6c0
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/config/BasicAuthConfig.java
@@ -0,0 +1,49 @@
+/*
+ * 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.basic.auth.config;
+
+import java.io.Serializable;
+
+/**
+ * basic-auth Plugin.
+ */
+public class BasicAuthConfig implements Serializable {
+ /**
+ * defaultHandleJson.
+ */
+ private String defaultHandleJson;
+
+ /**
+ * get defaultHandleJson.
+ *
+ * @return defaultHandleJson.
+ */
+ public String getDefaultHandleJson() {
+ return defaultHandleJson;
+ }
+
+ /**
+ * set defaultHandleJson.
+ *
+ * @param defaultHandleJson defaultHandleJson.
+ */
+ public void setDefaultHandleJson(final String defaultHandleJson) {
+ this.defaultHandleJson = defaultHandleJson;
+ }
+
+}
diff --git a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/handle/BasicAuthPluginDataHandler.java b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/handle/BasicAuthPluginDataHandler.java
new file mode 100755
index 0000000000..934187a197
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/handle/BasicAuthPluginDataHandler.java
@@ -0,0 +1,72 @@
+/*
+ * 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.basic.auth.handle;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Supplier;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.common.constant.Constants;
+import org.apache.shenyu.common.dto.PluginData;
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.enums.PluginEnum;
+import org.apache.shenyu.common.utils.GsonUtils;
+import org.apache.shenyu.common.utils.Singleton;
+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 org.apache.shenyu.plugin.basic.auth.config.BasicAuthConfig;
+import org.apache.shenyu.plugin.basic.auth.rule.BasicAuthRuleHandle;
+
+/**
+ * Configuration data of the basic auth plugin.
+ */
+public class BasicAuthPluginDataHandler implements PluginDataHandler {
+
+ public static final Supplier<CommonHandleCache<String, BasicAuthRuleHandle>> CACHED_HANDLE = new BeanHolder<>(CommonHandleCache::new);
+
+ @Override
+ public void handlerPlugin(final PluginData pluginData) {
+ Map<String, String> configMap = GsonUtils.getInstance().toObjectMap(pluginData.getConfig(), String.class);
+ String defaultHandleJson = Optional.ofNullable(configMap.get(Constants.DEFAULT_HANDLE_JSON)).orElse("");
+ BasicAuthConfig basicAuthConfig = new BasicAuthConfig();
+ basicAuthConfig.setDefaultHandleJson(defaultHandleJson);
+ Singleton.INST.single(BasicAuthConfig.class, basicAuthConfig);
+ }
+
+ @Override
+ public void removeRule(final RuleData ruleData) {
+ CACHED_HANDLE.get().removeHandle(CacheKeyUtils.INST.getKey(ruleData));
+ }
+
+ @Override
+ public void handlerRule(final RuleData ruleData) {
+ BasicAuthConfig basicAuthConfig = Singleton.INST.get(BasicAuthConfig.class);
+ Optional.ofNullable(ruleData.getHandle()).ifPresent(ruleHandle -> {
+ BasicAuthRuleHandle basicAuthRuleHandle = BasicAuthRuleHandle.newInstance(StringUtils.defaultString(ruleHandle, basicAuthConfig.getDefaultHandleJson()));
+ CACHED_HANDLE.get().cachedHandle(CacheKeyUtils.INST.getKey(ruleData), basicAuthRuleHandle);
+ });
+ }
+
+ @Override
+ public String pluginNamed() {
+ return PluginEnum.BASIC_AUTH.getName();
+ }
+}
diff --git a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/rule/BasicAuthRuleHandle.java b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/rule/BasicAuthRuleHandle.java
new file mode 100755
index 0000000000..7d210b3f04
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/rule/BasicAuthRuleHandle.java
@@ -0,0 +1,96 @@
+/*
+ * 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.basic.auth.rule;
+
+import org.apache.shenyu.common.dto.convert.rule.RuleHandle;
+import org.apache.shenyu.common.utils.GsonUtils;
+import org.apache.shenyu.plugin.basic.auth.strategy.BasicAuthAuthenticationStrategy;
+import org.apache.shenyu.plugin.basic.auth.strategy.BasicAuthAuthenticationStrategyFactory;
+
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * BasicAuth rule handle.
+ */
+
+public class BasicAuthRuleHandle implements RuleHandle {
+
+ private String handleType;
+
+ private BasicAuthAuthenticationStrategy basicAuthAuthenticationStrategy;
+
+ /**
+ * get handleType.
+ *
+ * @return handleType
+ */
+ public String getHandleType() {
+ return handleType;
+ }
+
+ /**
+ * set handleType.
+ *
+ * @param handleType handleType
+ */
+ public void setHandleType(final String handleType) {
+ this.handleType = handleType;
+ }
+
+ /**
+ * get basicAuthAuthenticationStrategy.
+ *
+ * @return basicAuthAuthenticationStrategy
+ */
+ public BasicAuthAuthenticationStrategy getBasicAuthAuthenticationStrategy() {
+ return basicAuthAuthenticationStrategy;
+ }
+
+ /**
+ * set basicAuthAuthenticationStrategy.
+ *
+ * @param basicAuthAuthenticationStrategy basicAuthAuthenticationStrategy
+ */
+ public void setBasicAuthAuthenticationStrategy(final BasicAuthAuthenticationStrategy basicAuthAuthenticationStrategy) {
+ this.basicAuthAuthenticationStrategy = basicAuthAuthenticationStrategy;
+ }
+
+
+ /**
+ * new instance basicAuthRuleHandle.
+ *
+ * @param handleJson handleJson from rule
+ * @return basicAuthRuleHandle
+ */
+ public static BasicAuthRuleHandle newInstance(final String handleJson) {
+ if (Objects.isNull(handleJson)) {
+ return null;
+ }
+ Map<String, Object> handleMap = GsonUtils.getInstance().convertToMap(handleJson);
+ String handleType = null;
+ if (Objects.nonNull(handleMap)) {
+ handleType = handleMap.getOrDefault("handleType", "default").toString();
+ }
+ BasicAuthAuthenticationStrategy basicAuthAuthenticationStrategy1 = BasicAuthAuthenticationStrategyFactory.newInstance(handleType);
+ BasicAuthRuleHandle basicAuthRuleHandle = basicAuthAuthenticationStrategy1.parseHandleJson(handleJson);
+ basicAuthRuleHandle.setBasicAuthAuthenticationStrategy(basicAuthAuthenticationStrategy1);
+ return basicAuthRuleHandle;
+ }
+
+}
diff --git a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/rule/DefaultBasicAuthRuleHandle.java b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/rule/DefaultBasicAuthRuleHandle.java
new file mode 100755
index 0000000000..761cc59fd2
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/rule/DefaultBasicAuthRuleHandle.java
@@ -0,0 +1,44 @@
+/*
+ * 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.basic.auth.rule;
+
+public class DefaultBasicAuthRuleHandle extends BasicAuthRuleHandle {
+
+ private static final long serialVersionUID = 7090772288389508730L;
+
+ private String authorization;
+
+ /**
+ * get authorization.
+ *
+ * @return authorization
+ */
+ public String getAuthorization() {
+ return authorization;
+ }
+
+ /**
+ * set authorization.
+ *
+ * @param authorization authorization
+ */
+ public void setAuthorization(final String authorization) {
+ this.authorization = authorization;
+ }
+
+}
diff --git a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/strategy/BasicAuthAuthenticationStrategy.java b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/strategy/BasicAuthAuthenticationStrategy.java
new file mode 100755
index 0000000000..74825d5141
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/strategy/BasicAuthAuthenticationStrategy.java
@@ -0,0 +1,47 @@
+/*
+ * 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.basic.auth.strategy;
+
+import org.apache.shenyu.plugin.basic.auth.rule.BasicAuthRuleHandle;
+import org.apache.shenyu.spi.SPI;
+
+/**
+ * Strategy of authentication.
+ */
+@SPI
+public interface BasicAuthAuthenticationStrategy {
+
+ /**
+ * HandleJson needs to be parsed into basicAuthRuleHandle in order to
+ * specify how to authenticate basicAuth.
+ *
+ * @param handleJson handleJson from rule
+ * @return basicAuthRuleHandle
+ */
+ BasicAuthRuleHandle parseHandleJson(String handleJson);
+
+ /**
+ * authentication.
+ *
+ * @param basicAuthRuleHandle basicAuthRuleHandle
+ * @param authentication authentication
+ * @return authentication result
+ */
+ boolean authenticate(BasicAuthRuleHandle basicAuthRuleHandle, String authentication);
+
+}
diff --git a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/strategy/BasicAuthAuthenticationStrategyFactory.java b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/strategy/BasicAuthAuthenticationStrategyFactory.java
new file mode 100755
index 0000000000..9b82d7a85b
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/strategy/BasicAuthAuthenticationStrategyFactory.java
@@ -0,0 +1,38 @@
+/*
+ * 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.basic.auth.strategy;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.spi.ExtensionLoader;
+
+public class BasicAuthAuthenticationStrategyFactory {
+
+ /**
+ * new instance basicAuthAuthenticationStrategy.
+ *
+ * @param handleType handleType
+ * @return basicAuthAuthenticationStrategy
+ */
+ public static BasicAuthAuthenticationStrategy newInstance(final String handleType) {
+ String type = handleType;
+ if (StringUtils.isBlank(type)) {
+ type = "default";
+ }
+ return ExtensionLoader.getExtensionLoader(BasicAuthAuthenticationStrategy.class).getJoin(type);
+ }
+}
diff --git a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/strategy/DefaultBasicAuthAuthenticationStrategy.java b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/strategy/DefaultBasicAuthAuthenticationStrategy.java
new file mode 100755
index 0000000000..14517c54fd
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/java/org/apache/shenyu/plugin/basic/auth/strategy/DefaultBasicAuthAuthenticationStrategy.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.shenyu.plugin.basic.auth.strategy;
+
+import org.apache.shenyu.common.utils.GsonUtils;
+import org.apache.shenyu.plugin.basic.auth.rule.BasicAuthRuleHandle;
+import org.apache.shenyu.plugin.basic.auth.rule.DefaultBasicAuthRuleHandle;
+import org.apache.shenyu.spi.Join;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Join
+public class DefaultBasicAuthAuthenticationStrategy implements BasicAuthAuthenticationStrategy {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DefaultBasicAuthAuthenticationStrategy.class);
+
+ @Override
+ public DefaultBasicAuthRuleHandle parseHandleJson(final String handleJson) {
+ try {
+ return GsonUtils.getInstance().fromJson(handleJson, DefaultBasicAuthRuleHandle.class);
+ } catch (Exception exception) {
+ LOG.error("Failed to parse json , please check json format", exception);
+ return null;
+ }
+ }
+
+ @Override
+ public boolean authenticate(final BasicAuthRuleHandle basicAuthRuleHandle, final String authentication) {
+ return authentication.equals(((DefaultBasicAuthRuleHandle) basicAuthRuleHandle).getAuthorization());
+ }
+}
diff --git a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/resources/META-INF/shenyu/org.apache.shenyu.plugin.basic.auth.strategy.BasicAuthAuthenticationStrategy b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/resources/META-INF/shenyu/org.apache.shenyu.plugin.basic.auth.strategy.BasicAuthAuthenticationStrategy
new file mode 100755
index 0000000000..9f25c4cb92
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/main/resources/META-INF/shenyu/org.apache.shenyu.plugin.basic.auth.strategy.BasicAuthAuthenticationStrategy
@@ -0,0 +1,17 @@
+# 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.
+
+default=org.apache.shenyu.plugin.basic.auth.strategy.DefaultBasicAuthAuthenticationStrategy
diff --git a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/java/org/apache/shenyu/plugin/basic/auth/BasicAuthPluginTest.java b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/java/org/apache/shenyu/plugin/basic/auth/BasicAuthPluginTest.java
new file mode 100755
index 0000000000..b355b1afba
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/java/org/apache/shenyu/plugin/basic/auth/BasicAuthPluginTest.java
@@ -0,0 +1,135 @@
+/*
+ * 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.basic.auth;
+
+import org.apache.shenyu.common.dto.PluginData;
+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.basic.auth.handle.BasicAuthPluginDataHandler;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.http.HttpHeaders;
+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.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Test case for {@link BasicAuthPlugin}.
+ */
+public final class BasicAuthPluginTest {
+
+ private BasicAuthPlugin basicAuthPlugin;
+
+ private ServerWebExchange exchange;
+
+ private ShenyuPluginChain chain;
+
+ private SelectorData selectorData;
+
+ private RuleData ruleData;
+
+ private BasicAuthPluginDataHandler basicAuthPluginDataHandler;
+
+ @BeforeEach
+ public void setUp() {
+ initContext();
+ selectorData = mock(SelectorData.class);
+ ruleData = new RuleData();
+ basicAuthPlugin = new BasicAuthPlugin();
+ exchange = createServerWebExchange();
+ chain = mock(ShenyuPluginChain.class);
+ basicAuthPluginDataHandler = new BasicAuthPluginDataHandler();
+ }
+
+ @Test
+ public void testDoExecute() {
+ ruleData.setHandle("{\"authorization\":\"test:test123\"}");
+ basicAuthPluginDataHandler.handlerRule(ruleData);
+ when(this.chain.execute(any())).thenReturn(Mono.empty());
+
+ StepVerifier.create(basicAuthPlugin.doExecute(exchange, chain, selectorData, ruleData)).expectSubscription().verifyComplete();
+
+ verify(chain).execute(exchange);
+ }
+
+ @Test
+ public void testDoExecuteWithCustomHandleType() {
+ ruleData.setHandle("{\"handleType\":\"custom\",\"customAuthorization\":\"test:test123\"}");
+ basicAuthPluginDataHandler.handlerRule(ruleData);
+ when(this.chain.execute(any())).thenReturn(Mono.empty());
+
+ StepVerifier.create(basicAuthPlugin.doExecute(exchange, chain, selectorData, ruleData)).expectSubscription().verifyComplete();
+
+ verify(chain).execute(exchange);
+ }
+
+ @Test
+ public void testDoExecuteWithoutHandle() {
+ when(this.chain.execute(any())).thenReturn(Mono.empty());
+
+ Mono<Void> mono = basicAuthPlugin.doExecute(exchange, chain, selectorData, ruleData);
+
+ StepVerifier.create(mono).expectSubscription().verifyComplete();
+ }
+
+ private static boolean hasHeader(final ServerWebExchange exchange, final String name, final String val) {
+ return exchange.getRequest().getHeaders().get(name).contains(val);
+ }
+
+ @Test
+ public void testNamed() {
+ final String result = basicAuthPlugin.named();
+ Assertions.assertEquals(PluginEnum.BASIC_AUTH.getName(), result);
+ }
+
+ @Test
+ public void testGetOrder() {
+ final int result = basicAuthPlugin.getOrder();
+ Assertions.assertEquals(PluginEnum.BASIC_AUTH.getCode(), result);
+ }
+
+ private void initContext() {
+ ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
+ when(context.getBean(ShenyuResult.class)).thenReturn(new DefaultShenyuResult());
+ SpringBeanUtils springBeanUtils = SpringBeanUtils.getInstance();
+ springBeanUtils.setApplicationContext(context);
+ PluginData pluginData = new PluginData("pluginId", "pluginName", "{\"defaultHandleJson\":\"{\\\"authorization\\\":\\\"test:test123\\\"}\"}", "0", false, null);
+ new BasicAuthPluginDataHandler().handlerPlugin(pluginData);
+ }
+
+ private ServerWebExchange createServerWebExchange() {
+ return MockServerWebExchange.from(MockServerHttpRequest
+ .get("localhost")
+ .header(HttpHeaders.AUTHORIZATION, "test:test123")
+ .build());
+ }
+}
diff --git a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/java/org/apache/shenyu/plugin/basic/auth/handle/BasicAuthPluginDataHandlerTest.java b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/java/org/apache/shenyu/plugin/basic/auth/handle/BasicAuthPluginDataHandlerTest.java
new file mode 100755
index 0000000000..a5da2af7c5
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/java/org/apache/shenyu/plugin/basic/auth/handle/BasicAuthPluginDataHandlerTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.basic.auth.handle;
+
+import org.apache.shenyu.common.dto.PluginData;
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.enums.PluginEnum;
+import org.apache.shenyu.common.utils.GsonUtils;
+import org.apache.shenyu.common.utils.Singleton;
+import org.apache.shenyu.plugin.base.utils.CacheKeyUtils;
+import org.apache.shenyu.plugin.basic.auth.config.BasicAuthConfig;
+import org.apache.shenyu.plugin.basic.auth.rule.DefaultBasicAuthRuleHandle;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Test case for {@link BasicAuthPluginDataHandler}.
+ */
+public final class BasicAuthPluginDataHandlerTest {
+
+ private BasicAuthPluginDataHandler basicAuthPluginDataHandler;
+
+ @BeforeEach
+ public void setUp() {
+ basicAuthPluginDataHandler = new BasicAuthPluginDataHandler();
+ }
+
+ @Test
+ public void testHandlerPlugin() {
+ final PluginData pluginData = new PluginData("pluginId", "pluginName", "{\"defaultHandleJson\":\"test:test123\"}", "0", false, null);
+ basicAuthPluginDataHandler.handlerPlugin(pluginData);
+ BasicAuthConfig basicAuthConfig = Singleton.INST.get(BasicAuthConfig.class);
+ Map<String, String> map = GsonUtils.getInstance().toObjectMap(pluginData.getConfig(), String.class);
+ assertEquals(basicAuthConfig.getDefaultHandleJson(), map.get("defaultHandleJson"));
+ }
+
+ @Test
+ public void testHandlerRule() {
+ RuleData ruleData = new RuleData();
+ ruleData.setId("basicAuthRule");
+ ruleData.setSelectorId("basicAuth");
+ String handleJson = "{\"authorization\":\"test:test123\"}";
+ ruleData.setHandle(handleJson);
+ basicAuthPluginDataHandler.handlerPlugin(new PluginData("pluginId", "pluginName", "{\"defaultHandleJson\":\"test:test123\"}", "0", false, null));
+ basicAuthPluginDataHandler.handlerRule(ruleData);
+ Map<String, String> map = GsonUtils.getInstance().toObjectMap(handleJson, String.class);
+ assertEquals(map.get("authorization"), ((DefaultBasicAuthRuleHandle) BasicAuthPluginDataHandler.CACHED_HANDLE.get().obtainHandle(CacheKeyUtils.INST.getKey(ruleData))).getAuthorization());
+ }
+
+ @Test
+ public void testPluginNamed() {
+ final String result = basicAuthPluginDataHandler.pluginNamed();
+ assertEquals(PluginEnum.BASIC_AUTH.getName(), result);
+ }
+}
diff --git a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/java/org/apache/shenyu/plugin/basic/auth/rule/BasicAuthRuleHandleTest.java b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/java/org/apache/shenyu/plugin/basic/auth/rule/BasicAuthRuleHandleTest.java
new file mode 100755
index 0000000000..43d5e850bf
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/java/org/apache/shenyu/plugin/basic/auth/rule/BasicAuthRuleHandleTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.basic.auth.rule;
+
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.Matchers.isA;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test case for {@link BasicAuthRuleHandle}.
+ */
+public class BasicAuthRuleHandleTest {
+
+ @Test
+ public void testGetInstance() {
+ assertThat(BasicAuthRuleHandle.newInstance(null), nullValue());
+
+ assertThat(BasicAuthRuleHandle.newInstance("{\"handleType\":\"custom\"}"),
+ isA(CustomBasicAuthRuleHandle.class));
+
+ assertThat(BasicAuthRuleHandle.newInstance("{\"authorization\":\"test:test123\"}"),
+ isA(DefaultBasicAuthRuleHandle.class));
+ }
+
+}
diff --git a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/java/org/apache/shenyu/plugin/basic/auth/rule/CustomBasicAuthRuleHandle.java b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/java/org/apache/shenyu/plugin/basic/auth/rule/CustomBasicAuthRuleHandle.java
new file mode 100755
index 0000000000..4de39eee07
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/java/org/apache/shenyu/plugin/basic/auth/rule/CustomBasicAuthRuleHandle.java
@@ -0,0 +1,42 @@
+/*
+ * 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.basic.auth.rule;
+
+public class CustomBasicAuthRuleHandle extends BasicAuthRuleHandle {
+
+ private String customAuthorization;
+
+ /**
+ * get customAuthorization.
+ *
+ * @return customAuthorization
+ */
+ public String getCustomAuthorization() {
+ return customAuthorization;
+ }
+
+ /**
+ * set customAuthorization.
+ *
+ * @param customAuthorization customAuthorization
+ */
+ public void setCustomAuthorization(final String customAuthorization) {
+ this.customAuthorization = customAuthorization;
+ }
+
+}
diff --git a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/java/org/apache/shenyu/plugin/basic/auth/strategy/CustomBasicAuthAuthenticationStrategy.java b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/java/org/apache/shenyu/plugin/basic/auth/strategy/CustomBasicAuthAuthenticationStrategy.java
new file mode 100755
index 0000000000..bce8ae94f4
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/java/org/apache/shenyu/plugin/basic/auth/strategy/CustomBasicAuthAuthenticationStrategy.java
@@ -0,0 +1,38 @@
+/*
+ * 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.basic.auth.strategy;
+
+import org.apache.shenyu.common.utils.GsonUtils;
+import org.apache.shenyu.plugin.basic.auth.rule.BasicAuthRuleHandle;
+import org.apache.shenyu.plugin.basic.auth.rule.CustomBasicAuthRuleHandle;
+import org.apache.shenyu.spi.Join;
+
+@Join
+public class CustomBasicAuthAuthenticationStrategy implements BasicAuthAuthenticationStrategy {
+
+ @Override
+ public CustomBasicAuthRuleHandle parseHandleJson(final String handleJson) {
+
+ return GsonUtils.getInstance().fromJson(handleJson, CustomBasicAuthRuleHandle.class);
+ }
+
+ @Override
+ public boolean authenticate(final BasicAuthRuleHandle basicAuthRuleHandle, final String authentication) {
+ return ((CustomBasicAuthRuleHandle) basicAuthRuleHandle).getCustomAuthorization().equals(authentication);
+ }
+}
diff --git a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/java/org/apache/shenyu/plugin/basic/auth/strategy/DefaultBasicAuthAuthenticationStrategyTest.java b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/java/org/apache/shenyu/plugin/basic/auth/strategy/DefaultBasicAuthAuthenticationStrategyTest.java
new file mode 100755
index 0000000000..7805bc7ebe
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/java/org/apache/shenyu/plugin/basic/auth/strategy/DefaultBasicAuthAuthenticationStrategyTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.basic.auth.strategy;
+
+import org.apache.shenyu.plugin.basic.auth.rule.DefaultBasicAuthRuleHandle;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static junit.framework.Assert.assertFalse;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class DefaultBasicAuthAuthenticationStrategyTest {
+
+ private DefaultBasicAuthAuthenticationStrategy defaultBasicAuthAuthenticationStrategy;
+
+ @BeforeEach
+ public void setUp() {
+ defaultBasicAuthAuthenticationStrategy = new DefaultBasicAuthAuthenticationStrategy();
+ }
+
+ @Test
+ public void testParseHandleJson() {
+ String handleJson = "{\"authorization\":\"test:test123\"}";
+ assertThat(defaultBasicAuthAuthenticationStrategy.parseHandleJson(handleJson), notNullValue(DefaultBasicAuthRuleHandle.class));
+ assertThat(defaultBasicAuthAuthenticationStrategy.parseHandleJson(null), nullValue());
+ }
+
+ @Test
+ public void testConvert() {
+ String handleJson = "{\"authorization\":\"test:test123\"}";
+ DefaultBasicAuthRuleHandle defaultBasicAuthRuleHandle = defaultBasicAuthAuthenticationStrategy.parseHandleJson(handleJson);
+
+ assertTrue(defaultBasicAuthAuthenticationStrategy
+ .authenticate(defaultBasicAuthRuleHandle, "test:test123"));
+ }
+
+ @Test
+ public void testExecuteWithWrongHandleJson() {
+ String wrongHandleJson = "{\"wrongAuthorization\":\"test:test123\"}";
+ DefaultBasicAuthRuleHandle defaultBasicAuthRuleHandle = defaultBasicAuthAuthenticationStrategy.parseHandleJson(wrongHandleJson);
+
+ assertFalse(defaultBasicAuthAuthenticationStrategy
+ .authenticate(defaultBasicAuthRuleHandle, "test:test123"));
+ }
+
+ @Test
+ public void testExecuteWithWrongAuthorization() {
+ String wrongHandleJson = "{\"authorization\":\"test:test123\"}";
+ DefaultBasicAuthRuleHandle defaultBasicAuthRuleHandle = defaultBasicAuthAuthenticationStrategy.parseHandleJson(wrongHandleJson);
+
+ assertFalse(defaultBasicAuthAuthenticationStrategy
+ .authenticate(defaultBasicAuthRuleHandle, "test:test456"));
+ }
+
+}
diff --git a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/resources/META-INF/shenyu/org.apache.shenyu.plugin.basic.auth.strategy.BasicAuthAuthenticationStrategy b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/resources/META-INF/shenyu/org.apache.shenyu.plugin.basic.auth.strategy.BasicAuthAuthenticationStrategy
new file mode 100755
index 0000000000..92273c8a8d
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-basic-auth/src/test/resources/META-INF/shenyu/org.apache.shenyu.plugin.basic.auth.strategy.BasicAuthAuthenticationStrategy
@@ -0,0 +1,17 @@
+# 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.
+
+custom=org.apache.shenyu.plugin.basic.auth.strategy.CustomBasicAuthAuthenticationStrategy
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 4c1fe62364..e535a016ea 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
@@ -73,5 +73,6 @@
<module>shenyu-spring-boot-starter-plugin-tcp</module>
<module>shenyu-spring-boot-starter-plugin-transform</module>
<module>shenyu-spring-boot-starter-plugin-logging-huawei-lts</module>
+ <module>shenyu-spring-boot-starter-plugin-basic-auth</module>
</modules>
</project>
diff --git a/shenyu-plugin/shenyu-plugin-security/pom.xml b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-basic-auth/pom.xml
old mode 100644
new mode 100755
similarity index 62%
copy from shenyu-plugin/shenyu-plugin-security/pom.xml
copy to shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-basic-auth/pom.xml
index 24ce969c96..486f445c47
--- a/shenyu-plugin/shenyu-plugin-security/pom.xml
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-basic-auth/pom.xml
@@ -1,46 +1,39 @@
-<?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">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.shenyu</groupId>
- <artifactId>shenyu-plugin</artifactId>
- <version>2.6.1-SNAPSHOT</version>
- </parent>
- <artifactId>shenyu-plugin-security</artifactId>
- <packaging>pom</packaging>
-
- <modules>
- <module>shenyu-plugin-casdoor</module>
- <module>shenyu-plugin-jwt</module>
- <module>shenyu-plugin-key-auth</module>
- <module>shenyu-plugin-oauth2</module>
- <module>shenyu-plugin-sign</module>
- <module>shenyu-plugin-cryptor</module>
-
- </modules>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.shenyu</groupId>
- <artifactId>shenyu-plugin-base</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
-</project>
\ No newline at end of file
+<?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>
+ <artifactId>shenyu-spring-boot-starter-plugin</artifactId>
+ <groupId>org.apache.shenyu</groupId>
+ <version>2.6.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>shenyu-spring-boot-starter-plugin-basic-auth</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-plugin-basic-auth</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-basic-auth/src/main/java/org/apache/shenyu/springboot/starter/plugin/basic/auth/BasicAuthPluginConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-basic-auth/src/main/java/org/apache/shenyu/springboot/starter/plugin/basic/auth/BasicAuthPluginConfiguration.java
new file mode 100755
index 0000000000..cb9c604aba
--- /dev/null
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-basic-auth/src/main/java/org/apache/shenyu/springboot/starter/plugin/basic/auth/BasicAuthPluginConfiguration.java
@@ -0,0 +1,53 @@
+/*
+ * 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.basic.auth;
+
+import org.apache.shenyu.plugin.api.ShenyuPlugin;
+import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
+import org.apache.shenyu.plugin.basic.auth.BasicAuthPlugin;
+import org.apache.shenyu.plugin.basic.auth.handle.BasicAuthPluginDataHandler;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * The type Basic auth plugin configuration.
+ */
+@Configuration
+@ConditionalOnProperty(value = {"shenyu.plugins.basic-auth.enabled"}, havingValue = "true", matchIfMissing = true)
+public class BasicAuthPluginConfiguration {
+ /**
+ * GeneralContext plugin.
+ *
+ * @return the shenyu plugin
+ */
+ @Bean
+ public ShenyuPlugin basicAuthPlugin() {
+ return new BasicAuthPlugin();
+ }
+
+ /**
+ * GeneralContext plugin data handler.
+ *
+ * @return the plugin data handler
+ */
+ @Bean
+ public PluginDataHandler basicAuthPluginDataHandler() {
+ return new BasicAuthPluginDataHandler();
+ }
+}
diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-basic-auth/src/main/resources/META-INF/spring.factories b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-basic-auth/src/main/resources/META-INF/spring.factories
new file mode 100755
index 0000000000..df83c3223a
--- /dev/null
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-basic-auth/src/main/resources/META-INF/spring.factories
@@ -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.
+#
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+org.apache.shenyu.springboot.starter.plugin.basic.auth.BasicAuthPluginConfiguration
diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-basic-auth/src/main/resources/META-INF/spring.provides b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-basic-auth/src/main/resources/META-INF/spring.provides
new file mode 100755
index 0000000000..4aa9f10b17
--- /dev/null
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-basic-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-basic-auth