freew01f / securing-spring-boot-with-jwts Goto Github PK
View Code? Open in Web Editor NEWcode spring
code spring
static final String SECRET = "P@ssw02d"; // JWT密码
这里改怎么改成可配置的密码。?
我用注解@value注入报错。是不是 static final需要另外的注入方式,?麻烦博主能帮忙看下。
JWTAuthenticationFilter 验证token后 为什么走到了CustomAuthenticationProvider.authenticate
@freew01f 谢谢代码,很清楚。
我实际中,在user登陆后生成token保存到数据库,下一次登陆要求user生成新的token,并更新数据库里的token;之前的token作废。那么如何刷新token呢,现在用前后两个token都可以通过验证(两个token都没有逾期)
谢谢
举个例子 用户相关的API
GET /users
POST /users
DELETE /users/{id}
路径都是users 怎么判断其权限
配置
.anyRequest().access("@authorityService.hasPermission(request,authentication)");
我是采用的
自定义
public boolean hasPermission(HttpServletRequest request, Authentication authentication)
UserDetails userDetails = (UserDetails)authentication.getPrincipal();
Collection<? extends GrantedAuthority> authorities = userDetails.getAuthorities();
String uri = request.getRequestURI();
AntPathMatcher antMatcher = new AntPathMatcher();
for (GrantedAuthority authoritie : authorities) {
if(antMatcher.match(authoritie.getAuthority(), uri)){
return true;
}
}
return false;
现在是想 取出 请求方法request..getRequestMethod();
和url 一起来判断
你有什么思路?
登录报500
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.