Spring Boot

JWT & Stateless Security

Stateless security with JWT, token generation and validation, security filters, refresh tokens

20 interview questions·
Senior
1

What is the structure of a JWT (JSON Web Token)?

Answer

A JWT consists of three parts separated by dots: Header (algorithm and type), Payload (claims/data), and Signature (integrity verification). Each part is Base64URL encoded. This structure allows secure and verifiable information transmission between two parties.

2

Which JWT claim represents the subject (user) of the token?

Answer

The 'sub' (subject) claim identifies the JWT's subject, typically the authenticated user (e.g., user ID or username). It's a standard claim defined in RFC 7519. Other standard claims include 'iss' (issuer), 'exp' (expiration), 'iat' (issued at), 'aud' (audience), and 'jti' (JWT ID).

3

What is the main difference between HMAC and RSA signing algorithms for JWT?

Answer

HMAC (e.g., HS256) uses a shared symmetric secret key to sign and verify, while RSA (e.g., RS256) uses an asymmetric key pair (private to sign, public to verify). RSA is preferable when multiple services need to verify tokens without accessing the signing key, as in microservices architectures.

4

Which JWT claim defines the token expiration date?

5

How should a client send a JWT in an HTTP REST request?

+17 interview questions

Master Spring Boot for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free