Jhipster版本 4.14.5,"applicationType":"monolith", "authenticationType":"jwt"
1.token生成
在用户登录时,请求/api/authenticate,Controller中注入AuthenticationManager用于验证用户名和密码是否正确,验证通过使用tokenProvider创建token并返回给前端

2. token验证
使用JWT认证,会生成如下3个类

其中TokenProvider提供创建token,验证token,获取权限等功能
JWTFilter拦截器对token进行校验和权限获取,并赋给SpringContext
JWTConfigurer中配置了JWTFiter的作用时机在UsernamePasswordAuthenticationFilter之前
如此,在请求到达时,通过JWTFiter解析并验证token,给这个请求赋予权限
注:由于token没有做服务器持有,所以token在过期之前一直有效,并且无法控制token失效。
网友评论