Skip to content

williamantoniazzi/spring-rest-data-security

 
 

Repository files navigation

spring-rest-data-security

This sample project contains a simple set of group/members API using:

Security Features

  • User registration and login with JWT authentication
  • Password encryption using BCrypt
  • Role-based authorization with Spring Security
  • Customized access denied handling
  • Logout mechanism
  • Refresh token

Using:

  • JSON Web Tokens (JWT)
  • BCrypt

Users included in test data

# User with USER role
email: user@mail.com
pwd: user123

# User with ADMIN role
email: admin@mail.com
pwd: admin123

Public URLs

  • / <> Home and simple text with Swagger Doc link
  • /auth/authenticate <> Authentication URL
  • /auth/register <> Register a new user with specific role (ADMIN or USER)

CURL to execute logout

# Change the bearer token
curl -X 'GET' \                                                                                                                  6.35G    100% █  702 Mbps   ─╯
  'http://localhost:8000/auth/logout' \
  -H 'accept: */*' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbkBtYWlsLmNvbSIsImlhdCI6MTY5ODA0Mzc1NywiZXhwIjoxNjk4MTMwMTU3fQ.O4XqiJpFbnUHIiqS0xOVSYARpHcdOZJerPIx8ZjhhmA'

Pre-requirements

Build App

mvn clean package

Running

  • Running MariaDB via Docker Compose
# To execute and view logs via Docker Compose v2
docker compose up --force-recreate -d ; docker compose logs -f

# To execute and view logs via Docker Compose v1
docker-compose up --force-recreate -d ; docker-compose logs -f
  • Stopping MariaDB via Docker Compose
# To stop via Docker Compose v2
docker compose down --remove-orphans

# To stop via Docker Compose v1
docker-compose down --remove-orphans
  • Running App
# To run App via Maven after start MariaDB via Docker Compose
mvn clean spring-boot:run
  • Swagger API Documentation

Access http://localhost:8000/swagger-ui/index.html

  • MariaDB connection parameters
# By JDBC URL
URL=jdbc:mariadb://localhost:3306/sample

# By connection parameters
HOST=localhost
PORT=3306
DATABASE=sample

USERNAME=root
PASSWORD=root

About

Fork from lucasnadalete, Fatec SJC, Lab de BD 5

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%