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:
2025-12-01 20:08:50 +08:00
parent 7380f783ee
commit b7afe9496a
2 changed files with 2 additions and 2 deletions

View File

@@ -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)) {

View File

@@ -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