Skip to content

feat: Phase 2 — Sécurité (JWT + API Key + Gestion erreurs)

idevx5 a demandé de fusionner phase/2-security vers develop

Phase 2 — Sécurité (JWT + API Key + Gestion erreurs)

Ce qui a été implémenté

Authentification JWT

  • User entity implementing UserDetails with roles: admin | fleet_manager | supervisor | operator
  • UserRepository with findByEmail / existsByEmail
  • UserDetailsServiceImpl — charge l'utilisateur depuis la BDD
  • JwtTokenProvider — génération & validation des access/refresh tokens (JJWT 0.12+)
  • JwtAuthenticationFilter — filtre OncePerRequestFilter qui extrait et valide le JWT

Authentification API Key (inter-service)

  • ApiKeyAuthenticationFilter — valide le header X-API-Key et attribue le rôle ROLE_SERVICE

Configuration sécurité

  • SecurityConfig — chaîne de filtres stateless, CSRF désactivé, règles d'autorisation par endpoint
  • CorsConfig — CORS configurable via cors.allowed-origins

DTOs Auth

  • LoginRequest, LoginResponse, RefreshRequest

Service & Contrôleur

  • AuthService — login (retourne access + refresh token) + refresh
  • AuthControllerPOST /api/v1/auth/login et POST /api/v1/auth/refresh

Gestion d'erreurs globale

  • ErrorCode enum (NOT_FOUND, CONFLICT, BAD_REQUEST, FORBIDDEN)
  • BusinessException, ResourceNotFoundException, ConflictException
  • ErrorResponse record
  • GlobalExceptionHandler — handler centralisé pour toutes les exceptions

Endpoints publics

  • POST /api/v1/auth/login
  • POST /api/v1/auth/refresh
  • GET /actuator/health
  • WS /ws/**

Propriétés requises

security:
  jwt:
    secret: <min 256-bit secret>
    expiration-ms: 900000       # 15 min
    refresh-expiration-ms: 604800000  # 7 days
  inter-service:
    api-key: <api-key>
cors:
  allowed-origins: http://localhost:3000

Rapports de requête de fusion