maven项目整合spring boot+mybatis+spring security+jwt(二)

本文是关于maven项目整合spring boot、mybatis、spring security和JWT的第二部分。主要介绍了如何配置JWTAtuhenticationFilter和JWTloginFilter,用于JWT与Spring Security的集成。此外,还展示了WebSecurityConfig的配置以及使用Postman测试API的简单步骤。目前实现了静态认证功能,后续将继续完善。
摘要由CSDN通过智能技术生成

接着上一篇(maven项目整合spring boot+mybatis+jwt+spring security(一))的继续。。。。

再就是整合jwt和spring security。
maven依赖:

<!-- spring-security 和 jwt-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.7.0</version>
        </dependency>

创建JWTAtuthenticationFilter类:一定要看清楚哦,别导错包了。。
接下来创建的两个类就是用来做生成token和jwt认证,目前我也只是会用而已。。原理还没研究透。。

import io.jsonwebtoken.Jwts;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
public class JWTAtuthenticationFilter extends BasicAuthenticationFilter {

public JWTAtuthenticationFilter(AuthenticationManager authenticationManage
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值