generated from Java-2025Fall/final-vibevault-template
完成作业
This commit is contained in:
parent
4a830003a7
commit
bd14cc66fb
@ -66,9 +66,9 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
|
||||||
if (user != null && jwtService.isTokenValid(jwt, user)) {
|
if (user != null && jwtService.isTokenValid(jwt, user)) {
|
||||||
// 设置用户角色(当前只有默认角色)
|
// 从用户实体获取角色
|
||||||
List<SimpleGrantedAuthority> authorities = Collections.singletonList(
|
List<SimpleGrantedAuthority> authorities = Collections.singletonList(
|
||||||
new SimpleGrantedAuthority("ROLE_USER")
|
new SimpleGrantedAuthority(user.getRole())
|
||||||
);
|
);
|
||||||
|
|
||||||
UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(
|
UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(
|
||||||
|
|||||||
@ -69,6 +69,7 @@ public class JwtService {
|
|||||||
|
|
||||||
return username.equals(extractedUsername) && expirationDate.after(now);
|
return username.equals(extractedUsername) && expirationDate.after(now);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
// 任何异常都表示 token 无效
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user