0
0
Spring Bootframework~10 mins

Why JWT matters for APIs in Spring Boot - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the JWT utility class in Spring Boot.

Spring Boot
import org.springframework.security.jwt.[1];
Drag options to blanks, or click blank then click option'
AJwtUtils
BJwtToken
CJwtHelper
DJwtService
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a class that does not exist in Spring Security JWT package.
2fill in blank
medium

Complete the code to extract the JWT token from the HTTP Authorization header.

Spring Boot
String token = request.getHeader("Authorization").[1]("Bearer ");
Drag options to blanks, or click blank then click option'
Asubstring
Breplace
Cremove
Dsplit
Attempts:
3 left
💡 Hint
Common Mistakes
Using substring without calculating the correct index.
Using split which returns an array.
3fill in blank
hard

Fix the error in decoding the JWT token string to get claims.

Spring Boot
Jwt jwt = JwtHelper.[1](token);
String claims = jwt.getClaims();
Drag options to blanks, or click blank then click option'
Adecode
Bparse
CdecodeToken
Dextract
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'parse' which is not a method in JwtHelper.
Using 'decodeToken' which does not exist.
4fill in blank
hard

Fill both blanks to create a JWT token with claims and a secret key.

Spring Boot
String token = JwtHelper.encode([1], new [2]("mySecretKey".getBytes(), "HmacSHA256"));
Drag options to blanks, or click blank then click option'
Aclaims
BSecretKeySpec
CMac
DKey
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Mac' instead of 'SecretKeySpec' for the key.
Passing the wrong data type for claims.
5fill in blank
hard

Fill all three blanks to verify a JWT token's signature and extract claims safely.

Spring Boot
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
}
Drag options to blanks, or click blank then click option'
Adecode
BMacSigner
CverifySignature
DJwtVerifier
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names for decoding or verification.
Using a wrong class for the signer.