feat(jwt): extend token expiration time and improve authentication filter
- Extend JWT token expiration from 1 hour to 30 days - Improve Authorization header validation in authentication filter - Add null check for header before calling startsWith method - Import Strings utility class for better string handling
This commit is contained in:
@@ -45,7 +45,7 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
|
||||
String header = request.getHeader("Authorization");
|
||||
|
||||
// 2. 校验头格式 (必须以 Bearer 开头)
|
||||
if (StringUtils.startsWith(header, "Bearer ")) {
|
||||
if (header != null && header.startsWith("Bearer ")) {
|
||||
String token = StringUtils.substring(header, 7);
|
||||
log.info("JWT Token: {}", token);
|
||||
if (StringUtils.isNotBlank(token)) {
|
||||
|
||||
@@ -80,7 +80,7 @@ public class JwtTokenHelper implements InitializingBean {
|
||||
*/
|
||||
public String generateToken(String username) {
|
||||
Instant now = Instant.now();
|
||||
Instant expireTime = now.plus(1, ChronoUnit.HOURS);
|
||||
Instant expireTime = now.plus(30, ChronoUnit.DAYS);
|
||||
|
||||
return Jwts.builder()
|
||||
.header().add("type", "JWT").and() // 推荐添加 header
|
||||
|
||||
Reference in New Issue
Block a user