This project aims to perform user authorization using JsonWebToken using Spring Boot 3 & Spring Security 6
- Run
docker-compose up -don root project - Create a database named
testauthdb - Create all the tables inside the database using the querys in
<project_root>/SQL_tables_querys.txtfile - Run
./mvnw spring-boot:runon root project
- Spring Security 6. There is a big change in security filter chain between SS5 and SS6
- Docker compose file for the database
- Uses relational database to store user related data
- Users table
- Roles table
- Access token table
- Refresh token table
- Tokens expiration is configurable in application.yml file
- Simple API
- Public
- POST
/api/auth/register- Body:
{ "enmail":string, "username":string, "password":string }- Response
200if user is new400if body is null401if user exists
- POST
/api/auth/login- Body:
{ "username":string, "password":string }- Response
200if user and password are correct- Body:
{"userId":number,"accesssToken":string,"refreshToken":string}
- Body:
400if body is null401if user and password are not correct
- POST
/api/auth/token- Body:
{ "userId":number, "accesssToken":string, "refreshToken":string }- Response
200if userid and refresh token is correct and not expired- Body:
{"userId":number,"accesssToken":string,"refreshToken":string}
- Body:
400if body is null401if refresh token is expired
- POST
- Authenticated user with any role
- GET
/api/test- Response:
Hello <username>
- Response:
- GET
- Authenticated user with ADMIN role
- GET
/api/test/role- Response:
Test OK
- Response:
- GET