Enterprise-grade loan management system built with Spring Boot 3.x, featuring advanced security mechanisms and complex business logic for real-world financial operations.
SecureLoan API implements sophisticated financial workflows including automated credit scoring, debt-to-income (DTI) ratio calculations, annuity-based installment generation, and multi-role authorization with comprehensive audit trails.
- RSA-based JWT with public/private key pair
- Role-based access control (Customer, Credit Officer, Admin)
- Method-level security with
@PreAuthorizefor resource-specific authorization - Custom security services for fine-grained access control
- Failed login tracking with automatic account locking (5 attempts)
- Temporary locks (15 minutes) with auto-unlock mechanism
- Admin locks (permanent until manual intervention)
- Token invalidation for logout, password change, and force logout
- Automatic cleanup of expired tokens (scheduled hourly)
- Custom filter (
JwtBlacklistFilter) validates every request
- 7-day validity with automatic rotation
- Reuse detection - if a refresh token is reused, all user tokens are revoked
JwtBlacklistFilter β Token Blacklisted? β Account Locked? β Token Expired? β Allow/Deny
1. AOP-Based Security Audit Log
- Automatic logging of critical operations using
@Auditableannotation - Tracks: loan approvals, user locks, password changes, force logouts
- Success/failure tracking with detailed error messages
- SpEL-based resource extraction for dynamic audit trails
2. Login History Tracking
- Device fingerprinting (browser, OS, device type)
- IP address tracking with proxy header support
- Failed/successful login attempts
- User-accessible via
/api/audit/login-history
Auto-Evaluation Engine:
- Credit score validation (min 500)
- Age eligibility (max 65 at loan maturity)
- DTI ratio calculation (max 40% of monthly income)
- Minimum income requirements per loan type
- Auto-approval for credit scores β₯750
Loan Types:
- Personal (1.75% monthly interest, βΊ25K min income)
- Vehicle (1.89% monthly interest, βΊ45K min income)
- Mortgage (1.25% monthly interest, βΊ55K min income)
- Education (1.50% monthly interest, βΊ15K min income)
Annuity Formula Implementation:
Monthly Installment = P Γ r Γ (1+r)^n / ((1+r)^n - 1)
- Principal tracking with interest separation
- Last installment adjustment for rounding precision
- Remaining balance updates on each payment
DTI Calculation:
DTI = (Sum of all active loan installments + new loan installment) / Monthly Income Γ 100
- Sequential payment enforcement (can't pay installment 3 before installment 2)
- Already-paid validation
- Amount matching (exact payment required)
- Automatic loan completion when all installments paid
src/main/java/com/yasirakbal/secureloanapi/
β
βββ π¦ common/ # Shared components
β βββ entity/BaseEntity # Auditing fields, soft delete
β βββ exception/ # Custom exception hierarchy
β βββ mapper/BaseMapper # MapStruct base interface
β
βββ π security/
β βββ config/
β β βββ SecurityConfig # Spring Security configuration
β β βββ JwtConfig # JWT encoder/decoder setup
β β βββ RsaKeysConfig # Runtime RSA key generation
β βββ filter/
β βββ JwtBlacklistFilter # Custom pre-authentication filter
β
βββ π― feature/
β β
β βββ π auth/ # Authentication
β β βββ adapter/AppUserAdapter
β β βββ service/
β β β βββ AuthService # Login, register, logout
β β β βββ RefreshTokenService
β β βββ entity/RefreshToken
β β
β βββ π€ user/
β β βββ entity/User # Security fields (accountLocked, tokensInvalidatedAt)
β β βββ service/
β β βββ UserService # Password change, failed login handling
β β
β βββ π audit/
β β βββ aspect/AuditAspect # AOP-based audit logging
β β βββ entity/
β β β βββ SecurityAuditLog
β β β βββ LoginHistory
β β βββ annotation/@Auditable
β β
β βββ π« blacklist/
β β βββ entity/JwtBlacklist
β β βββ service/JwtBlacklistService
β β
β βββ π application/ # Loan applications
β β βββ entity/LoanApplication
β β βββ service/
β β βββ LoanApplicationService # Auto-evaluation, DTI calculation
β β
β βββ π° loan/
β β βββ entity/Loan
β β βββ service/LoanService # Payment processing
β β
β βββ π installment/
β β βββ entity/Installment
β β βββ service/InstallmentService # Annuity calculations
β β
β βββ π¨βπΌ officer/ # Credit officer operations
β β βββ service/CreditOfficerService # Approve/reject loans
β β
β βββ π admin/
β βββ service/AdminService # User lock/unlock, force logout
β
βββ π³ docker-compose.yml # PostgreSQL container
@Transactional(
propagation = Propagation.REQUIRES_NEW,
noRollbackFor = NonRollbackBusinessException.class
)- Throw exceptions while committing database changes
- Used for failed login tracking (increment attempts but throw error)
@Aspect
@Component
public class AuditAspect {
@AfterReturning("@annotation(auditable)")
public void auditSuccess(JoinPoint joinPoint, Auditable auditable) {
// Automatic audit logging
}
}- Token cleanup (hourly for blacklist, daily for refresh tokens)
- Automatic account unlock on login attempt after lock expiry
- Type-safe DTO mapping
- Custom conversion logic for complex types
- Reduces boilerplate code
| Endpoint | Role | Description |
|---|---|---|
POST /api/auth/register |
Public | Register new user |
POST /api/auth/login |
Public | Login with credentials |
POST /api/auth/refresh |
Public | Refresh access token |
POST /api/applications |
Customer | Create loan application |
GET /api/applications/my |
Customer | View own applications |
GET /api/loans/my |
Customer | View active loans |
POST /api/loans/{id}/installments/{id}/pay |
Customer | Pay installment |
GET /api/officer/applications |
Officer | View pending applications |
PUT /api/officer/applications/{id}/approve |
Officer | Approve loan |
POST /api/admin/users/{id}/lock |
Admin | Lock user account |
GET /api/admin/security/audit-logs |
Admin | View audit logs |
- Spring Boot 3.x - Core framework
- Spring Security 6 - Authentication & authorization
- Spring Data JPA - Database operations
- PostgreSQL - Primary database
- MapStruct - DTO mapping
- Argon2 - Password hashing
- JWT (Nimbus) - Token generation
- Lombok - Boilerplate reduction
- Docker - PostgreSQL containerization
# Start PostgreSQL
docker-compose up -d
# Run application
./mvnw spring-boot:runDefault Users:
- Customer:
johndoe / Pass123! - Officer:
creditofficer / Pass123! - Admin:
admin / Pass123!
This project demonstrates production-grade practices including:
- Multi-layer security (filters, method-level, custom services)
- Complex transaction management with propagation strategies
- AOP for cross-cutting concerns
- Financial domain modeling
- Comprehensive error handling with custom exceptions
- Audit trail implementation for compliance