接着上一篇(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