Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a JWT token with a secret key.
Spring Boot
String token = Jwts.builder().setSubject(user.getUsername()).signWith([1]).compact(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using null or incorrect signature algorithm causes errors.
✗ Incorrect
Use Keys.secretKeyFor(SignatureAlgorithm.HS256) to generate a secure secret key for signing the JWT.
2fill in blank
mediumComplete the code to store user info in HTTP session.
Spring Boot
HttpSession session = request.getSession(); session.setAttribute("[1]", user);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent attribute names causes retrieval issues.
✗ Incorrect
The attribute name user is commonly used to store the user object in session.
3fill in blank
hardFix the error in the JWT validation code by completing the missing method.
Spring Boot
Jwts.parserBuilder().setSigningKey([1]).build().parseClaimsJws(token); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing null or wrong key causes exceptions.
✗ Incorrect
The setSigningKey method requires the secret key used to sign the token for validation.
4fill in blank
hardFill both blanks to configure session timeout and secure cookie.
Spring Boot
session.setMaxInactiveInterval([1]); response.addCookie(new Cookie("JSESSIONID", [2]));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong timeout units or invalid cookie values.
✗ Incorrect
Set session timeout to 1800 seconds (30 minutes) and add a secure cookie value.
5fill in blank
hardFill all three blanks to create a JWT with claims and expiration.
Spring Boot
String jwt = Jwts.builder().setSubject([1]).claim("role", [2]).setExpiration([3]).signWith(secretKey).compact();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using password as subject or invalid expiration date.
✗ Incorrect
Use the username as subject, set role claim to "admin", and expiration to 1 hour from now.