This is a sample Spring Boot application that demonstrates how to implement JWT-based authentication and authorization using Spring Security. This application is designed to be deployed on Docker.
To run this application on Docker, you'll need to have Docker installed on your machine. You can download and install Docker from the official Docker website.
To build and run the Docker image for this application, follow these steps:
1.Clone the repository to your local machine.
-
Change into the project directory.
- cd spring-security-jwt-app
-
Build the Docker image.
- docker build -t spring-security-jwt-app
- Run the Docker container.
Once the container is running, you can access the application at http://localhost:8080.
The following endpoints are available in this application:
- `/api/login - Authenticates a user and returns a JWT token
- `/api/signup - Registers a new user
- `/api/hello - Get user details
- `/api/all - A public endpoint that can be accessed without authentication
- `/api/user - An endpoint that can only be accessed by authenticated users
- `/api/admin - An endpoint that can only be accessed by users with the "ROLE_ADMIN" role
The application uses the following configuration properties:
- `jwt.secret - The secret key used to sign JWT tokens
- `jwt.expirationMs - The expiration time (in milliseconds) for JWT tokens
- `spring.datasource.url - The URL of the database used by the application
- `spring.datasource.username - The username used to connect to the database
- `spring.datasource.password - The password used to connect to the database
You can modify these properties by editing the application.properties file located in the src/main/resources directory.
This application uses Spring Security to provide authentication and authorization. JWT tokens are used to authenticate users and to grant access to protected endpoints.
This project is licensed under the MIT License. See the LICENSE file for details.
This application was created using the following technologies:
- Spring Boot
- Spring Security
- JWT
- MySQL
- Maven
- Docker
- docker-compose down