Overview
The User API provides endpoints for user registration and authentication. All endpoints return user objects with secure password handling.Passwords must meet the following requirements:
- Minimum 8 characters
- Maximum 64 characters
- Must contain at least one letter and one number
Register User
User Login
Data Models
UsuarioPOJO
The user domain model used across all user endpoints.| Field | Type | Description |
|---|---|---|
id | Long | Unique identifier |
usuario | String | Username |
contrasena | ContrasenaVO | Password value object |
ContrasenaVO
Value object for password handling with built-in validation. Validation Rules:- Cannot be null or empty
- Minimum length: 8 characters
- Maximum length: 64 characters
- Must contain at least one letter (A-Z, a-z)
- Must contain at least one digit (0-9)
- The
toString()method returns"****"to prevent password leakage in logs - Passwords are never returned in plain text in API responses
Implementation Details
Architecture
The User API follows Clean Architecture principles:- Controller Layer:
UsuarioRestController(src/main/java/com/example/demo/usuario/infrastructure/controllers/UsuarioRestController.java:1) - Application Layer: Command and Query handlers
RegistrarUsuarioHandlerfor registrationLoginUsuarioHandlerfor authentication
- Domain Layer:
UsuarioPOJOandContrasenaVOvalue objects
Request Processing Flow
-
Registration (
POST /registro):- Receives
RegistrarUsuarioRequestwith username and password - Creates
RegistrarUsuarioCommandwith validatedContrasenaVO - Handler processes command and persists user
- Returns created
UsuarioPOJO
- Receives
-
Login (
GET /login/{usuario}/{contrasena}):- Extracts credentials from path parameters
- Creates
LoginUsuarioQuery - Handler validates credentials and retrieves user
- Returns authenticated
UsuarioPOJO