From a5a0b5c476327828dcc091660de5c72357efa707 Mon Sep 17 00:00:00 2001 From: tanghc Date: Fri, 19 Jul 2019 20:15:52 +0800 Subject: [PATCH] 1.13.0 --- changelog.md | 5 + sop-1.13.0.sql | 9 + sop-admin/sop-admin-vue/src/router/index.js | 14 +- .../sop-admin-vue/src/views/isv/role.vue | 8 +- .../src/views/service/ipBlacklist.vue | 184 ++++++++++ .../service/{limit/index2.vue => limit.vue} | 0 .../src/views/service/limit/index.vue | 347 ------------------ .../views/service/{log/index.vue => log.vue} | 0 .../service/{route/index.vue => route.vue} | 0 .../{list/index.vue => serviceList.vue} | 0 sop-example/sop-auth/pom.xml | 2 +- sop-example/sop-book/sop-book-web/pom.xml | 2 +- sop-example/sop-easyopen/pom.xml | 2 +- sop-example/sop-springmvc/pom.xml | 2 +- sop-example/sop-story/sop-story-web/pom.xml | 2 +- sop-gateway/pom.xml | 2 +- .../gateway/manager/DbIPBlacklistManager.java | 64 ++++ .../gateway/manager/ManagerInitializer.java | 1 + .../sop/gateway/mapper/IPBlacklistMapper.java | 22 ++ sop-website/website-server/pom.xml | 2 +- sop.sql | 11 + 21 files changed, 314 insertions(+), 365 deletions(-) create mode 100644 sop-1.13.0.sql create mode 100644 sop-admin/sop-admin-vue/src/views/service/ipBlacklist.vue rename sop-admin/sop-admin-vue/src/views/service/{limit/index2.vue => limit.vue} (100%) delete mode 100644 sop-admin/sop-admin-vue/src/views/service/limit/index.vue rename sop-admin/sop-admin-vue/src/views/service/{log/index.vue => log.vue} (100%) rename sop-admin/sop-admin-vue/src/views/service/{route/index.vue => route.vue} (100%) rename sop-admin/sop-admin-vue/src/views/service/{list/index.vue => serviceList.vue} (100%) create mode 100644 sop-gateway/src/main/java/com/gitee/sop/gateway/manager/DbIPBlacklistManager.java create mode 100644 sop-gateway/src/main/java/com/gitee/sop/gateway/mapper/IPBlacklistMapper.java diff --git a/changelog.md b/changelog.md index 692483fb..273ce30e 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ # changelog + +## 1.13.0 + +- 新增IP黑名单 + ## 1.12.4 - 优化属性文件配置 diff --git a/sop-1.13.0.sql b/sop-1.13.0.sql new file mode 100644 index 00000000..091b94dc --- /dev/null +++ b/sop-1.13.0.sql @@ -0,0 +1,9 @@ +CREATE TABLE `config_ip_blacklist` ( + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + `ip` varchar(64) NOT NULL DEFAULT '' COMMENT 'ip', + `remark` varchar(128) DEFAULT NULL COMMENT '备注', + `gmt_create` datetime DEFAULT CURRENT_TIMESTAMP, + `gmt_modified` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `uk_ip` (`ip`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='IP黑名单'; \ No newline at end of file diff --git a/sop-admin/sop-admin-vue/src/router/index.js b/sop-admin/sop-admin-vue/src/router/index.js index 6ac2aa67..e88328d3 100644 --- a/sop-admin/sop-admin-vue/src/router/index.js +++ b/sop-admin/sop-admin-vue/src/router/index.js @@ -64,26 +64,32 @@ export const constantRoutes = [ { path: 'list', name: 'ServiceList', - component: () => import('@/views/service/list/index'), + component: () => import('@/views/service/serviceList'), meta: { title: '服务列表' } }, { path: 'route', name: 'Route', - component: () => import('@/views/service/route/index'), + component: () => import('@/views/service/route'), meta: { title: '路由管理' } }, { path: 'limit', name: 'Limit', - component: () => import('@/views/service/limit/index2'), + component: () => import('@/views/service/limit'), meta: { title: '限流管理' } }, { path: 'log', name: 'Log', - component: () => import('@/views/service/log/index'), + component: () => import('@/views/service/log'), meta: { title: '监控日志' } + }, + { + path: 'blacklist', + name: 'Blacklist', + component: () => import('@/views/service/ipBlacklist'), + meta: { title: 'IP黑名单' } } ] }, diff --git a/sop-admin/sop-admin-vue/src/views/isv/role.vue b/sop-admin/sop-admin-vue/src/views/isv/role.vue index 74507d04..b7166436 100644 --- a/sop-admin/sop-admin-vue/src/views/isv/role.vue +++ b/sop-admin/sop-admin-vue/src/views/isv/role.vue @@ -108,17 +108,11 @@ export default { roleDialogFormRules: { roleCode: [ { required: true, message: '不能为空', trigger: 'blur' }, - { min: 1, max: 64, message: '长度在 1 到 100 个字符', trigger: 'blur' } + { min: 1, max: 64, message: '长度在 1 到 64 个字符', trigger: 'blur' } ], description: [ { max: 64, message: '不能超过 64 个字符', trigger: 'blur' } ] - }, - rulesIsvForm: { - appKey: [ - { required: true, message: '不能为空', trigger: 'blur' }, - { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' } - ] } } }, diff --git a/sop-admin/sop-admin-vue/src/views/service/ipBlacklist.vue b/sop-admin/sop-admin-vue/src/views/service/ipBlacklist.vue new file mode 100644 index 00000000..e7e79a25 --- /dev/null +++ b/sop-admin/sop-admin-vue/src/views/service/ipBlacklist.vue @@ -0,0 +1,184 @@ + + + diff --git a/sop-admin/sop-admin-vue/src/views/service/limit/index2.vue b/sop-admin/sop-admin-vue/src/views/service/limit.vue similarity index 100% rename from sop-admin/sop-admin-vue/src/views/service/limit/index2.vue rename to sop-admin/sop-admin-vue/src/views/service/limit.vue diff --git a/sop-admin/sop-admin-vue/src/views/service/limit/index.vue b/sop-admin/sop-admin-vue/src/views/service/limit/index.vue deleted file mode 100644 index 1e6ada92..00000000 --- a/sop-admin/sop-admin-vue/src/views/service/limit/index.vue +++ /dev/null @@ -1,347 +0,0 @@ - - - diff --git a/sop-admin/sop-admin-vue/src/views/service/log/index.vue b/sop-admin/sop-admin-vue/src/views/service/log.vue similarity index 100% rename from sop-admin/sop-admin-vue/src/views/service/log/index.vue rename to sop-admin/sop-admin-vue/src/views/service/log.vue diff --git a/sop-admin/sop-admin-vue/src/views/service/route/index.vue b/sop-admin/sop-admin-vue/src/views/service/route.vue similarity index 100% rename from sop-admin/sop-admin-vue/src/views/service/route/index.vue rename to sop-admin/sop-admin-vue/src/views/service/route.vue diff --git a/sop-admin/sop-admin-vue/src/views/service/list/index.vue b/sop-admin/sop-admin-vue/src/views/service/serviceList.vue similarity index 100% rename from sop-admin/sop-admin-vue/src/views/service/list/index.vue rename to sop-admin/sop-admin-vue/src/views/service/serviceList.vue diff --git a/sop-example/sop-auth/pom.xml b/sop-example/sop-auth/pom.xml index 18134dd1..622a2c0e 100644 --- a/sop-example/sop-auth/pom.xml +++ b/sop-example/sop-auth/pom.xml @@ -26,7 +26,7 @@ com.gitee.sop sop-service-common - 1.12.4-SNAPSHOT + 1.13.0-SNAPSHOT org.springframework.cloud diff --git a/sop-example/sop-book/sop-book-web/pom.xml b/sop-example/sop-book/sop-book-web/pom.xml index efe05420..439c1efb 100644 --- a/sop-example/sop-book/sop-book-web/pom.xml +++ b/sop-example/sop-book/sop-book-web/pom.xml @@ -24,7 +24,7 @@ com.gitee.sop sop-service-common - 1.12.4-SNAPSHOT + 1.13.0-SNAPSHOT com.gitee.sop diff --git a/sop-example/sop-easyopen/pom.xml b/sop-example/sop-easyopen/pom.xml index 43ca8cc5..9b0ddba2 100644 --- a/sop-example/sop-easyopen/pom.xml +++ b/sop-example/sop-easyopen/pom.xml @@ -29,7 +29,7 @@ com.gitee.sop sop-service-common - 1.12.4-SNAPSHOT + 1.13.0-SNAPSHOT org.springframework.cloud diff --git a/sop-example/sop-springmvc/pom.xml b/sop-example/sop-springmvc/pom.xml index 6c7a105b..68dc85fd 100644 --- a/sop-example/sop-springmvc/pom.xml +++ b/sop-example/sop-springmvc/pom.xml @@ -20,7 +20,7 @@ com.gitee.sop sop-service-common - 1.12.4-SNAPSHOT + 1.13.0-SNAPSHOT diff --git a/sop-example/sop-story/sop-story-web/pom.xml b/sop-example/sop-story/sop-story-web/pom.xml index 091c245a..d560381e 100644 --- a/sop-example/sop-story/sop-story-web/pom.xml +++ b/sop-example/sop-story/sop-story-web/pom.xml @@ -24,7 +24,7 @@ com.gitee.sop sop-service-common - 1.12.4-SNAPSHOT + 1.13.0-SNAPSHOT com.gitee.sop diff --git a/sop-gateway/pom.xml b/sop-gateway/pom.xml index 79b06053..2424dafd 100644 --- a/sop-gateway/pom.xml +++ b/sop-gateway/pom.xml @@ -23,7 +23,7 @@ com.gitee.sop sop-gateway-common - 1.12.4-SNAPSHOT + 1.13.0-SNAPSHOT diff --git a/sop-gateway/src/main/java/com/gitee/sop/gateway/manager/DbIPBlacklistManager.java b/sop-gateway/src/main/java/com/gitee/sop/gateway/manager/DbIPBlacklistManager.java new file mode 100644 index 00000000..540c898c --- /dev/null +++ b/sop-gateway/src/main/java/com/gitee/sop/gateway/manager/DbIPBlacklistManager.java @@ -0,0 +1,64 @@ +package com.gitee.sop.gateway.manager; + +import com.alibaba.fastjson.JSON; +import com.gitee.sop.gateway.mapper.IPBlacklistMapper; +import com.gitee.sop.gatewaycommon.bean.ChannelMsg; +import com.gitee.sop.gatewaycommon.manager.DefaultIPBlacklistManager; +import com.gitee.sop.gatewaycommon.manager.ZookeeperContext; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; + +import javax.annotation.PostConstruct; +import java.util.List; + +/** + * 限流配置管理 + * @author tanghc + */ +@Slf4j +public class DbIPBlacklistManager extends DefaultIPBlacklistManager { + + @Autowired + IPBlacklistMapper ipBlacklistMapper; + + @Autowired + Environment environment; + + @Override + public void load() { + List ipList = ipBlacklistMapper.listAllIP(); + log.info("加载IP黑名单, size:{}", ipList.size()); + ipList.stream().forEach(this::add); + + } + + @PostConstruct + protected void after() throws Exception { + ZookeeperContext.setEnvironment(environment); + String path = ZookeeperContext.getIpBlacklistChannelPath(); + ZookeeperContext.listenPath(path, nodeCache -> { + String nodeData = new String(nodeCache.getCurrentData().getData()); + ChannelMsg channelMsg = JSON.parseObject(nodeData, ChannelMsg.class); + final IPDto ipDto = JSON.parseObject(channelMsg.getData(), IPDto.class); + String ip = ipDto.getIp(); + switch (channelMsg.getOperation()) { + case "add": + log.info("添加IP黑名单,ip:{}", ip); + add(ip); + break; + case "delete": + log.info("移除IP黑名单,ip:{}", ip); + remove(ip); + break; + } + }); + } + + @Data + private static class IPDto { + private String ip; + } + +} diff --git a/sop-gateway/src/main/java/com/gitee/sop/gateway/manager/ManagerInitializer.java b/sop-gateway/src/main/java/com/gitee/sop/gateway/manager/ManagerInitializer.java index abeaba2a..0a59778b 100644 --- a/sop-gateway/src/main/java/com/gitee/sop/gateway/manager/ManagerInitializer.java +++ b/sop-gateway/src/main/java/com/gitee/sop/gateway/manager/ManagerInitializer.java @@ -13,5 +13,6 @@ public class ManagerInitializer { apiConfig.setIsvRoutePermissionManager(new DbIsvRoutePermissionManager()); apiConfig.setRouteConfigManager(new DbRouteConfigManager()); apiConfig.setLimitConfigManager(new DbLimitConfigManager()); + apiConfig.setIpBlacklistManager(new DbIPBlacklistManager()); } } diff --git a/sop-gateway/src/main/java/com/gitee/sop/gateway/mapper/IPBlacklistMapper.java b/sop-gateway/src/main/java/com/gitee/sop/gateway/mapper/IPBlacklistMapper.java new file mode 100644 index 00000000..91d8e1df --- /dev/null +++ b/sop-gateway/src/main/java/com/gitee/sop/gateway/mapper/IPBlacklistMapper.java @@ -0,0 +1,22 @@ +package com.gitee.sop.gateway.mapper; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +/** + * IP黑名单 + * @author tanghc + */ +@Mapper +public interface IPBlacklistMapper { + + /** + * 获取所有IP + * @return + */ + @Select("SELECT ip FROM config_ip_blacklist") + List listAllIP(); + +} diff --git a/sop-website/website-server/pom.xml b/sop-website/website-server/pom.xml index fca39acd..03056a95 100644 --- a/sop-website/website-server/pom.xml +++ b/sop-website/website-server/pom.xml @@ -25,7 +25,7 @@ com.gitee.sop sop-registry-api - 1.12.4-SNAPSHOT + 1.13.0-SNAPSHOT diff --git a/sop.sql b/sop.sql index d184bde3..97003bfa 100644 --- a/sop.sql +++ b/sop.sql @@ -14,6 +14,7 @@ DROP TABLE IF EXISTS `config_limit`; DROP TABLE IF EXISTS `admin_user_info`; DROP TABLE IF EXISTS `config_common`; DROP TABLE IF EXISTS `isv_keys`; +DROP TABLE IF EXISTS `config_ip_blacklist`; CREATE TABLE `admin_user_info` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, @@ -164,6 +165,16 @@ CREATE TABLE `isv_keys` ( UNIQUE KEY `uk_appkey` (`app_key`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='ISV秘钥'; +CREATE TABLE `config_ip_blacklist` ( + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + `ip` varchar(64) NOT NULL DEFAULT '' COMMENT 'ip', + `remark` varchar(128) DEFAULT NULL COMMENT '备注', + `gmt_create` datetime DEFAULT CURRENT_TIMESTAMP, + `gmt_modified` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `uk_ip` (`ip`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='IP黑名单'; + SET FOREIGN_KEY_CHECKS = @PREVIOUS_FOREIGN_KEY_CHECKS;