实现校验链

master
kezhen0805 2 years ago
commit b3ac672edb

38
.gitignore vendored

@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/beancon-api/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>com.mashibing</groupId>
<artifactId>beacon-cloud</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>beancon-api</artifactId>
<dependencies>
<!-- web项目-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 注册到nacos-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- nacos拉取配置-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- openFeign-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!-- RabbitMQ-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<!-- lombok记录日志等工具-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- 测试的依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

@ -0,0 +1,17 @@
package com.mashibing.api;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* @author kezhen
* @date 2022/12/21 01:43
*/
@SpringBootApplication
@EnableDiscoveryClient
public class ApiStarterApp {
public static void main(String[] args) {
SpringApplication.run(ApiStarterApp.class,args);
}
}

@ -0,0 +1,21 @@
package com.mashibing.api.controller;
import com.mashibing.api.filter.CheckFilterContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
/**
* @author kezhen
* @description
*/
@Controller
public class TestController {
@Autowired
private CheckFilterContext checkFilterContext;
@GetMapping("/api/test")
public void test(){
System.out.println("==============================");
checkFilterContext.check(new Object());
}
}

@ -0,0 +1,14 @@
package com.mashibing.api.filter;
/**
* @author kezhen
* @description
*/
public interface CheckFilter {
/**
*
* @param obj
*/
void check(Object obj);
}

@ -0,0 +1,34 @@
package com.mashibing.api.filter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* @author kezhen
* @description
*/
@Component
@RefreshScope
public class CheckFilterContext {
//Spring IOC 会将对象全部放到map集合里面
@Autowired
private Map<String ,CheckFilter> checkFilterMap;
@Value("${filters:apikey,ip,sign,template}")
private String filters;
/**
* check
*/
public void check(Object obj){
String[] filterArray = filters.split(",");
for (String filter : filterArray) {
CheckFilter checkFilter = checkFilterMap.get(filter);
checkFilter.check(obj);
}
}
}

@ -0,0 +1,18 @@
package com.mashibing.api.filter.impl;
import com.mashibing.api.filter.CheckFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @author kezhen
* @description
*/
@Service(value = "apikey")
@Slf4j
public class ApiKeyCheckFilter implements CheckFilter {
@Override
public void check(Object obj) {
log.info("【接口模块-校验apikey】 校验ing…………");
}
}

@ -0,0 +1,18 @@
package com.mashibing.api.filter.impl;
import com.mashibing.api.filter.CheckFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @author kezhen
* @description
*/
@Service(value = "fee")
@Slf4j
public class FeeCheckFilter implements CheckFilter {
@Override
public void check(Object obj) {
log.info("【接口模块-校验客户余额】 校验ing…………");
}
}

@ -0,0 +1,18 @@
package com.mashibing.api.filter.impl;
import com.mashibing.api.filter.CheckFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @author kezhen
* @description
*/
@Service(value = "ip")
@Slf4j
public class IPCheckFilter implements CheckFilter {
@Override
public void check(Object obj) {
log.info("【接口模块-校验IP】 校验ing…………");
}
}

@ -0,0 +1,18 @@
package com.mashibing.api.filter.impl;
import com.mashibing.api.filter.CheckFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @author kezhen
* @description
*/
@Service(value = "mobile")
@Slf4j
public class MobileCheckFilter implements CheckFilter {
@Override
public void check(Object obj) {
log.info("【接口模块-校验手机号】 校验ing…………");
}
}

@ -0,0 +1,18 @@
package com.mashibing.api.filter.impl;
import com.mashibing.api.filter.CheckFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @author kezhen
* @description
*/
@Service(value = "sign")
@Slf4j
public class SignCheckFilter implements CheckFilter {
@Override
public void check(Object obj) {
log.info("【接口模块-校验签名】 校验ing…………");
}
}

@ -0,0 +1,18 @@
package com.mashibing.api.filter.impl;
import com.mashibing.api.filter.CheckFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @author kezhen
* @description
*/
@Service(value = "template")
@Slf4j
public class TemplateCheckFilter implements CheckFilter {
@Override
public void check(Object obj) {
log.info("【接口模块-校验模版】 校验ing…………");
}
}

@ -0,0 +1,22 @@
# 服务名称
spring:
application:
name: beacon-api
# 多环境
profiles:
active: dev
cloud:
nacos:
# nacos注册中心地址
discovery:
server-addr: 192.168.1.8:8848
# nacos配置中心地址
config:
server-addr: 192.168.1.8:8848
file-extension: yml
# beacon-api-dev.yml

@ -0,0 +1,25 @@
package com.mashibing.api.filter;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.*;
/**
* @author kezhen
* @description
*/
@SpringBootTest
@RunWith(SpringRunner.class)
public class CheckFilterContextTest {
@Autowired
private CheckFilterContext checkFilterContext;
@org.junit.Test
public void check() {
Object obj = new Object();
checkFilterContext.check(obj);
}
}

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.12.RELEASE</version>
<relativePath/>
</parent>
<groupId>com.mashibing</groupId>
<artifactId>beacon-cloud</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>beancon-api</module>
</modules>
<properties>
<spring.cloud-version>Hoxton.SR12</spring.cloud-version>
<spring.cloud.alibaba-version>2.2.6.RELEASE</spring.cloud.alibaba-version>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring.cloud-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring.cloud.alibaba-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Loading…
Cancel
Save