Code Monkey home page Code Monkey logo

api-signature's Introduction

📚api-signature-spring-boot-starter

在web开发的过程当中,当对外提供的接口可以被随意调用时,可能存在非法用户可以对咱们的服务器进行恶意攻击,致使服务器不能有效处理正常的业务请求,所以须要考虑对这些暴露出去的http接口作安全防护。其中一个行之有效的方法就是给对外接口加验证身份的签名(即验签)。具体到业务中,当调用者B请求调用服务者A的接口时,服务者A须要验证调用者B的身份,并经过签名来验证调用者的身份,整个流程大体如下:

⭐️ 1、快速开始

1.1 引入依赖

工具基于Spring Boot自动配置原理开发,已经打包成场景启动器 api-signature-spring-boot-starter,使用时首先需要在项目POM文件中引入以下依赖:

<dependency>
    <groupId>top.easyboot</groupId>
    <artifactId>api-signature-spring-boot-starter</artifactId>
    <version>${api-signature-version}</version>
</dependency>

1.2 写配置

目前提供有一下配置项,配置不是必须的,都有默认值

application.signature.enable  #是否开启验签自动配置,默认值为true,即默认自动开启
application.signature.app-id  #配置分配的app_id
application.signature.secret  #配置分配的secret
application.signature.hash-type  #使用何种摘要算法,目前支持MD5、SHA、以及HAMC,默认值SHA256

1.3 注册验签拦截器

在项目中实现Spring MVC提供的WebMvcConfigurer接口并实现方法addInterceptor(InterceptorRegistry)注册验签拦截器

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import top.easyboot.handler.SignInterceptor;
import top.easyboot.titan.handler.LogInterceptor;


@Configuration
public class WebAppConfigurer implements WebMvcConfigurer {

    @Autowired
    private SignInterceptor signInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(signInterceptor);
    }
}

api-signature's People

Contributors

loveriter 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.