Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

A demo to test Spring Security and JWT for a RESTful application

License

Notifications You must be signed in to change notification settings

ThomasVitale/spring-security-jwt-rest-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot REST Application + Spring Security with JWT

A demo to test Spring Security and JWT for a RESTful application

Usage

To login, add the following code to the body of a GET request at '/login': {"username":"user","password":"password"}

To access the protected resource '/quotes', add to the Authentication header of the request the token obtained by logging in:

Authentication: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Implementation

Spring Security is configured in com.thomasvitale.config package:

  • WebSecurityConfig defines the policy to access resources, filters for login and authentication, a fake user in memory.

Authentication, Login and JWT are handled in com.thomasvitale.security package:

  • JWTAuthenticationEntryPoint returns a 401 status code if token authentication fails (whatever the reason)
  • JWTLoginFilter is used to log in users and generate a token.
  • JWTAuthenticationFilter is used to authenticate (token verification) users when trying to access protected resources.
  • TokenAuthenticationService provides methods to generate tokens, to verify their validity.
  • TokenHandler is a utility class implementing methods to build and parse tokens.

Resources

This demo has been inspired by the following guides and tutorials:

Useful Readings

About

A demo to test Spring Security and JWT for a RESTful application

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published