二次验证拦截器

二次验证拦截器,对一些安全性要求比较高的操作,对接口进行二次操作验证,验证成功后,才会调用服务端接口。

验证接口开发

需要继承com.wueasy.cloud.gateway.service.SecondaryVerifyService接口,并实现里面的verify验证密码方法。

/**
 * 验证二次密码
 * @author: fallsea
 * @version 1.0
 */
@Service
public class SecondaryVerifyServiceImpl implements SecondaryVerifyService {

    @Override
    public Result<Void> verify(String value, ServerHttpRequest request) {
        Result<Void> result = new Result<>();
        if(value != "123456"){
            //失败
            result.setErrorNo(-10);//非0即失败
            result.setErrorInfo("验证失败");
        }
        return result;
    }

}

拦截地址配置

  • enabled:是否启用拦截器,默认不启用false
  • urls:需要拦截的地址
  • field-name:#参数字段名称
  • parameter-type:参数类型,HEADER请求头,QUERY查询参数
  • service-name:service服务名称,当有多个规则时候,需要指定

url匹配规则:

  • 模糊匹配:可以通过/**/*模糊匹配所有地址和路径下地址
wueasy:
  gateway:
    interceptor:
      secondary-verify:
        enabled: true #是否启用,默认false
        items: #规则列表
        - urls: #需要拦截的地址
          - /**
          field-name: password #参数字段名称
          parameter-type: HEADER #参数类型
Copyright © wueasy.com 2017-2022 all right reserved,powered by Gitbook未经允许,禁止以任何形式传播 修订时间: 2022-02-26

results matching ""

    No results matching ""