File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
src/main/java/com/cleanengine/coin/user/login/application Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change 11package com .cleanengine .coin .user .login .application ;
22
33
4+ import io .jsonwebtoken .JwtParser ;
45import io .jsonwebtoken .Jwts ;
56import org .springframework .beans .factory .annotation .Value ;
67import org .springframework .stereotype .Component ;
@@ -15,19 +16,22 @@ public class JWTUtil {
1516
1617 private final SecretKey secretKey ;
1718
19+ private final JwtParser jwtParser ;
20+
1821 public JWTUtil (@ Value ("${spring.jwt.secret}" ) String secret ) {
1922 secretKey = new SecretKeySpec (secret .getBytes (StandardCharsets .UTF_8 ), Jwts .SIG .HS256 .key ().build ().getAlgorithm ());
23+ jwtParser = Jwts .parser ().verifyWith (secretKey ).build ();
2024 }
2125
2226 public Integer getUserId (String token ) {
2327
24- return Jwts . parser (). verifyWith ( secretKey ). build () .parseSignedClaims (token ).getPayload ().get ("userId" , Integer .class );
28+ return jwtParser .parseSignedClaims (token ).getPayload ().get ("userId" , Integer .class );
2529
2630 }
2731
2832 public Boolean isExpired (String token ) {
2933
30- return Jwts . parser (). verifyWith ( secretKey ). build () .parseSignedClaims (token ).getPayload ().getExpiration ().before (new Date ());
34+ return jwtParser .parseSignedClaims (token ).getPayload ().getExpiration ().before (new Date ());
3135 }
3236
3337 public String createJwt (Integer userId , Long expiredMs ) {
You can’t perform that action at this time.
0 commit comments