Enhance authentication logging and update MyBatis configuration
This commit is contained in:
@@ -4,6 +4,8 @@ import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import io.jsonwebtoken.io.Decoders;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -15,7 +17,7 @@ import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class JwtService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(JwtService.class);
|
||||
private final SecretKey key;
|
||||
private final long accessTokenMinutes;
|
||||
|
||||
@@ -39,11 +41,14 @@ public class JwtService {
|
||||
if (extra != null) {
|
||||
extra.forEach(builder::claim);
|
||||
}
|
||||
return builder.signWith(key, SignatureAlgorithm.HS256).compact();
|
||||
String token = builder.signWith(key, SignatureAlgorithm.HS256).compact();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("JWT generated subject={}, userType={}, userId={}, username={} expInMin={}", subject, userType, userId, username, accessTokenMinutes);
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
public io.jsonwebtoken.Claims parse(String token) {
|
||||
return Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(token).getBody();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user