Authentication and user management microservice. Issues stateless JWT (RSA) and secures endpoints with Spring Security.
- Java 21
- Spring Boot 3
- Spring Security (OAuth2 Resource Server, JWT, BCrypt)
- Spring Data JPA
- PostgreSQL
- Maven
- Solid, production-friendly security baseline (JWT + RSA, stateless)
- Simple integration via Authorization: Bearer
- Clear user lifecycle: create, update, list, lookup, and soft delete
- Java 21 or higher
- Maven 3.9+
- PostgreSQL
Update src/main/resources/application.properties:
# Database
spring.datasource.url=jdbc:postgresql://localhost:5432/ms_auth_db
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.jpa.hibernate.ddl-auto=update
# JWT Keys (PEM)
jwt.public-key=classpath:keys/public.key
jwt.private-key=classpath:keys/private.key
spring.application.name=ms-authPlace RSA keys under src/main/resources/keys/.
Sample keys exist for local usage only; always replace them in production.
- Clone the repository
git clone <repo-url>- Go to the project folder
cd ms-auth- Start the app
mvn spring-boot:runApp available at: http://localhost:8080
- Public endpoints:
POST /user/authenticate,POST /user/create - Protected endpoints require header:
Authorization: Bearer <token>
- URL:
/user/authenticate - Method:
POST - Request:
{
"username": "alice",
"password": "123456"
}- Response:
{
"username": "alice",
"token": "<jwt>",
"roles": ["ROLE_USER"]
}- URL:
/user/create - Method:
POST - Request:
{
"username": "alice",
"password": "123456",
"idProfilePicture": "abc123"
}- Response:
201 Createdwith created user in body
- URL:
/user/{id} - Method:
PUT - Request (example):
{
"username": "alice.new",
"password": "newPassword",
"idProfilePicture": "xyz789"
}- Response:
200 OKwith updated user
- URL:
/user/{id} - Method:
GET - Response:
200 OKwith user
- URL:
/user/by-username/{username} - Method:
GET - Response:
200 OKwith user
- URL:
/user/getUsersByQuantity/{quantity} - Method:
GET - Response:
200 OKwith list
- URL:
/user/ - Method:
GET - Response:
200 OKwith list
- URL:
/user/{id} - Method:
DELETE - Response:
204 No Content(user is marked inactive)
This project is licensed under the MIT License.