A very simple example of a Spring Boot application that uses a layered architecture, JWT generation & authentication per SCOPE, automatic local development & testing setup with testcontainers.
- Java 21
- IntelliJ IDEA
- Written using spring boot
- Uses postgreSQL as database
- Uses lombok which needs to be enabled/configured in your editor
- Database migrations done with flyway
- Tests done in JUnit 5 with Testcontainers
- Uses Spring Security with JWT tokens for authentication & authorization
- Maven wrapper is included for building/testing
- On Unix systems use:
./mvnw clean verify
- On Windows:
./mvnw.cmd clean verify
- On Unix systems use:
- run
./mvnw fmt:format
before pushing - run
./mvnw clean verify
before pushing
Navigate to the root of test folder,
And then run the LocalDevApplication
class.
This will start all necessary docker containers
and run the application locally.
curl -s --location "http://localhost:8080/auth/token" \
> --header "Content-Type: application/json" \
> --data "{
> \"sub\": \"123\",
> \"scope\": [
> \"role1\",
> \"role2\",
> \"GUEST\"
> ]
> }"
eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwODAiLCJzdWIiOiJkbWl0cnkiLCJleHAiOjE3MDM5NTg4MjcsImlhdCI6MTcwMzk1ODIyNywic2NvcGUiOlsicm9sZTEiLCJyb2xlMiIsIkdVRVNUIl19.sgwvUVJazeEdhM1Vy8eXGjvGIXkAYWFfRg_VaNpISdU
curl -s --location "http://localhost:8080/greeting" \
--header "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwODAiLCJzdWIiOiJkbWl0cnkiLCJleHAiOjE3MDM5NTg4MjcsImlhdCI6MTcwMzk1ODIyNywic2NvcGUiOlsicm9sZTEiLCJyb2xlMiIsIkdVRVNUIl19.sgwvUVJazeEdhM1Vy8eXGjvGIXkAYWFfRg_VaNpISdU"
Hello, 123. You have next permissions: [SCOPE_role1, SCOPE_role2, SCOPE_GUEST]