Compare commits
2 Commits
6ff61fccfa
...
320a344c04
Author | SHA1 | Date | |
---|---|---|---|
320a344c04 | |||
53a484dd2b |
6
pom.xml
6
pom.xml
@ -78,6 +78,12 @@
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>13.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -5,6 +5,7 @@ import io.jsonwebtoken.security.Keys;
|
||||
import io.jsonwebtoken.security.SignatureException;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@ -29,6 +30,7 @@ public class JwtService {
|
||||
@Value("${jwt.token-expiration-ms}")
|
||||
private long tokenExpirationMs;
|
||||
|
||||
@org.jetbrains.annotations.NotNull
|
||||
private Key getSignKey() {
|
||||
byte[] keyBytes = Base64.getDecoder().decode(secretKey);
|
||||
return Keys.hmacShaKeyFor(keyBytes);
|
||||
@ -46,7 +48,7 @@ public class JwtService {
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T extractClaim(String token, Function<Claims, T> claimsResolver) {
|
||||
public <T> T extractClaim(String token, @NotNull Function<Claims, T> claimsResolver) {
|
||||
final Claims claims = extractAllClaims(token);
|
||||
return claimsResolver.apply(claims);
|
||||
}
|
||||
@ -60,7 +62,7 @@ public class JwtService {
|
||||
.getBody();
|
||||
}
|
||||
|
||||
public String generateToken(UserDetails userDetails) {
|
||||
public String generateToken(@NotNull UserDetails userDetails) {
|
||||
Map<String, Object> claims = new HashMap<>();
|
||||
return createToken(claims, userDetails.getUsername());
|
||||
}
|
||||
|
Reference in New Issue
Block a user