User Model
TheUsuarioPOJO represents a user entity in the e-commerce system. It encapsulates user identification, username, and secure password management through value objects.
Model Structure
Fields
Unique identifier for the user.
Username or email address for the user account.
Password value object with built-in validation and security measures.
Password Validation
The
ContrasenaVO value object enforces password security through constructor validation. Any attempt to create a password that doesn’t meet requirements will throw an InvalidPasswordException.Validation Rules
The password must satisfy ALL of the following conditions:| Rule | Requirement | Exception Message |
|---|---|---|
| Not Empty | Password cannot be null or empty | ”La contraseña no puede estar vacía” |
| Minimum Length | At least 8 characters | ”La contraseña debe tener al menos 8 caracteres” |
| Maximum Length | No more than 64 characters | ”La contraseña no puede superar los 64 caracteres” |
| Complexity | At least one letter AND one digit | ”La contraseña debe contener al menos una letra y un número” |
Valid Password Examples
Invalid Password Examples
Creating a User
Updating a Password
TheContrasenaVO provides an actualizarContrasena() method that creates a new password value object:
Password value objects are immutable. The
actualizarContrasena() method returns a new ContrasenaVO instance rather than modifying the existing one.Security Considerations
Related Models
- Product Model - Product entity with price validation
Source Code Reference
UsuarioPOJO: src/main/java/com/example/demo/usuario/domain/models/UsuarioPOJO.java:14ContrasenaVO: src/main/java/com/example/demo/usuario/domain/vo/ContrasenaVO.java:8