CRUD-Test — API de Usuarios con Autenticación JWT

REST API for users with two-phase registration, stateless JWT authentication, PENDING → ACTIVE state transition via one-time token and integration tests.

  • Java
  • Spring
  • MySQL
  • Flyway
  • JWT
  • Spring AI

Problem

User registration in many APIs is binary: either the user exists and is active, or they don't exist. This project explores a more realistic flow where the user can remain in PENDING state after initial registration, with a short-lived partial token to complete the onboarding process.

Solution

API with two registration phases controlled by state (PENDINGACTIVE) and differentiated JWT tokens. A partial token (15 min, single use) covers the activation flow; the full token enables all operations. Spring Security validates the token type on each endpoint.

Architecture

  • Single-use partial token — stored in the database, invalidated when consumed or expired; prevents replay attacks in the activation flow
  • MapStruct — type-safe mapping between DTOs and entities without manual reflection
  • Flyway — versioned migrations for the MySQL schema
  • Spring AI — module prepared for OpenAI integration; architecture ready to add AI assistance without refactoring
  • OpenAPI / Swagger UI — auto-generated documentation for all endpoints
  • Integration tests — coverage of the partial token repository with a dedicated database profile for testing
CR
CRUD-Test · API Usuarios con JWT
Java 21 · Spring Boot · MySQL · Flyway · JWT · Spring AI
▶ Pruébalo — arrastra nodos · click para inspeccionar
JWT headerHTTPvalidadotoken opsJPA/HibernateHTTP ClientPostman · Swagger UI · TestsSpring SecurityJWT Filter · OncePerRequestPartialTokenFilterFullTokenFilterAuthController/auth/register · /activate · /loginUserServiceregistro 2 fases · JWT genPartialTokenRepotokens de un solo usoUserRepositorySpring Data JPAMySQLFlyway · 2 tablas · JPA
cada barra = POST /register → filter → service → BD → 201
Architecture diagram of CRUD-Test — API de Usuarios con Autenticación JWT
Architecture diagram of CRUD-Test — API de Usuarios con Autenticación JWT