Complete the code to import the JWT utility class in Spring Boot.
import org.springframework.security.jwt.[1];
The JwtHelper class is used in Spring Security to work with JWT tokens.
Complete the code to extract the JWT token from the HTTP Authorization header.
String token = request.getHeader("Authorization").[1]("Bearer ");
We use replace("Bearer ", "") to remove the 'Bearer ' prefix from the header value.
Fix the error in decoding the JWT token string to get claims.
Jwt jwt = JwtHelper.[1](token);
String claims = jwt.getClaims();The correct method to decode a JWT string in Spring Security is decode.
Fill both blanks to create a JWT token with claims and a secret key.
String token = JwtHelper.encode([1], new [2]("mySecretKey".getBytes(), "HmacSHA256"));
The encode method takes the claims string and a SecretKeySpec object with the secret key.
Fill all three blanks to verify a JWT token's signature and extract claims safely.
try { Jwt jwt = JwtHelper.[1](token); String claims = jwt.getClaims(); // Verify signature SignatureVerifier verifier = new [2]("mySecretKey"); jwt.[3](verifier); } catch (Exception e) { // Handle invalid token }
We decode the token, create a MacSigner with the secret key, then call verifySignature to check the token's validity.