Coder Social home page Coder Social logo

gateway's Introduction

gateway

基于Spring Cloud Gateway封装的网关.

功能

  • 请求参数验签、响应结果加签

网关过滤器

SignGatewayFilterFactory 验签加签网关过滤器

对请求参数验签、响应参数加签.

使用该功能需要自行实现签名服务接口SignService

因为body只能读取一次的原因,验签接口中会传递请求体参数,其他参数请自行从request中获取。

响应结果签名成功后,如果签名值在body中,修改原始body,返回即可。如果是放在请求头中,直接通过response设置响应头即可.

package tech.aomi.cloud.gateway.service;

import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import tech.aomi.common.exception.ServiceException;

/**
 * 签名服务接口
 *
 * @author Sean createAt 2021/5/8
 */
public interface SignService {

    /**
     * 签名验证
     *
     * @param request http request
     * @param body    请求body参数
     * @throws ServiceException 签名出现任何异常则认为签名验证失败
     */
    default void verify(ServerHttpRequest request, byte[] body) throws ServiceException {
        // TODO
    }

    /**
     * 对响应数据进行签名
     *
     * @param response http response
     * @param body     原始响应body
     * @return 签名完成后响应的body数据,如果没有变动,直接返回原始响应body
     */
    default byte[] sign(ServerHttpResponse response, byte[] body) {
        return body;
    }
}

Example application.yml

spring:
  cloud:
    gateway:
      routes:
        - id: hello_sign
          uri: https://api.xxxx.com/v1
          predicates:
            - Path=/v1/**
          filters:
            - "Sign"

gateway's People

Contributors

sean-snow avatar yedg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.