https://github.com/psv73/account-service
Spring Boot microservice for user accounts and payroll with RBAC and security events
https://github.com/psv73/account-service
gradle h2 java rest-api spring-boot spring-security
Last synced: about 2 months ago
JSON representation
Spring Boot microservice for user accounts and payroll with RBAC and security events
- Host: GitHub
- URL: https://github.com/psv73/account-service
- Owner: psv73
- License: mit
- Created: 2025-08-15T08:40:04.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-09-12T11:05:28.000Z (10 months ago)
- Last Synced: 2025-09-12T11:27:36.378Z (10 months ago)
- Topics: gradle, h2, java, rest-api, spring-boot, spring-security
- Language: Java
- Homepage:
- Size: 85 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# π§Ύ Account Service β Payroll & User Management (Java, Spring Boot)



A Spring Boot microservice for user account and payroll management with **roleβbased access control (RBAC)**, authentication/authorization, and **security event logging**.
> Port used in examples: **28852**. H2 console is enabled for local development.
---
## π Features
- **User management** β sign up, change password, list users (admin scope)
- **Payroll** β add payments, list payments (per user & accountant views)
- **Security** β RBAC (Administrator, User, Accountant, Auditor) + security events
- **Validation & error handling** with clear JSON responses
- **H2 console** (`/h2-console`) for local development; **Actuator shutdown** for tests
---
## π§± Tech Stack
- Java 21 (compatible 17+)
- Spring Boot 3.x: Web, Security, Data JPA
- H2 (dev)
- Gradle Wrapper, Git/GitHub
- Docker (optional for deployment)
---
## βΆοΈ Getting Started
**Prerequisites**: JDK 17+ (21 recommended), Git. No Gradle installation needed (wrapper included).
```bash
git clone https://github.com/psv73/Account-Service.git
cd Account-Service
# build & run
./gradlew clean bootRun
# choose a custom port if needed
./gradlew bootRun --args='--server.port=28852'
```
**H2 console**: `http://localhost:28852/h2-console` (FrameOptions configured as `sameOrigin`).
---
## π Endpoints Overview (centralized in `AppPath`)
```
/api/auth/signup
/api/auth/changepass
/api/empl/payment
/api/acct/payments
/api/security/events
/api/admin/user
/api/admin/user/role
/api/admin/user/access
/h2-console/**
/actuator/shutdown
```
---
## π Access Rules (Spring Security β RBAC)
```java
.authorizeHttpRequests(auth -> auth
.requestMatchers(AppPath.USER + "/**").hasRole("ADMINISTRATOR")
.requestMatchers(HttpMethod.GET, AppPath.PAYMENT).hasAnyRole("ACCOUNTANT", "USER")
.requestMatchers(HttpMethod.GET, AppPath.SECURITY_EVENT).hasRole("AUDITOR")
.requestMatchers(HttpMethod.POST, AppPath.PAYMENTS).hasRole("ACCOUNTANT")
.requestMatchers(HttpMethod.PUT, AppPath.PAYMENTS).hasRole("ACCOUNTANT")
.requestMatchers(HttpMethod.POST, AppPath.CHANGE_PASS).authenticated()
.requestMatchers(HttpMethod.POST, AppPath.SIGN_UP).permitAll()
.requestMatchers(HttpMethod.POST, AppPath.ACTUATOR_SHUTDOWN).permitAll()
.anyRequest().permitAll()
);
```
---
## π Example Requests
### 1) Sign up
```http
POST http://localhost:28852/api/auth/signup
Content-Type: application/json
{
"name": "John",
"lastname": "Doe",
"email": "john.black@acme.com",
"password": "oMoa3VvqnLxW"
}
```
β
Response
```json
{
"id": 7952,
"name": "John",
"lastname": "Doe",
"email": "john.black@acme.com",
"roles": ["ROLE_USER"]
}
```
### 2) Change password (authenticated)
```http
POST http://localhost:28852/api/auth/changepass
Content-Type: application/json
Authorization: Basic
{ "new_password": "oMoa3VvqnLxW" }
```
β
Response
```json
{
"email": "johndoe1@acme.com",
"status": "The password has been updated successfully"
}
```
### 3) Add payment (ACCOUNTANT)
```http
POST http://localhost:28852/api/empl/payment
Content-Type: application/json
Authorization: Basic
{ "employee": "john.black@acme.com", "period": "08-2025", "salary": 350000 }
```
β
Response
```json
{ "status": "Added successfully!" }
```
### 4) List payments
- **User view**
```http
GET http://localhost:28852/api/empl/payment
Authorization: Basic
```
- **Accountant view**
```http
GET http://localhost:28852/api/acct/payments
Authorization: Basic
```
---
## π Audit & Security Events
**Endpoint**
```http
GET http://localhost:28852/api/security/events
Authorization: Basic
```
**Response example**
```json
[
{
"id": 1,
"date": "2025-08-15T10:20:54.282006",
"action": "CREATE_USER",
"subject": "Anonymous",
"object": "johndoe@acme.com",
"path": "/api/auth/signup"
},
{
"id": 4,
"date": "2025-08-15T10:22:05.260397",
"action": "ACCESS_DENIED",
"subject": "johndoe@acme.com",
"object": "/api/acct/payments",
"path": "/api/acct/payments"
}
]
```
---
## π Project Structure (high level)
- `config/` β security configuration & beans
- `controller/` β REST endpoints
- `service/` β business logic
- `repository/` β Spring Data JPA
- `model/` β entities & DTOs
- `exception/` β error handling
---
## π What this project demonstrates
- RBAC with Spring Security (Administrator/User/Accountant/Auditor)
- Clean REST API design & validation
- Consistent JSON errors and **security event** auditing
- Devβfriendly setup (H2 console, Gradle wrapper, profiles)