feat: initialisation du projet Olhar-API en Clean Architecture
- Spring Boot 3.4.1 + Gradle Kotlin DSL, Java 21 - Clean Architecture (domain / application / infrastructure / interfaces) - Spring Security stateless avec JWT (JJWT 0.12.6) - Flyway + PostgreSQL (migration V1 table users) - SpringDoc OpenAPI / Swagger UI avec auth Bearer - Testcontainers pour les tests d'intégration - Use cases Register et Authenticate (endpoints POST /api/v1/auth/register et /login) - GlobalExceptionHandler avec ProblemDetail (RFC 9457) - docker-compose.yml pour Postgres local Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package com.olhar.olharapi.application.usecase;
|
||||
|
||||
import com.olhar.olharapi.application.port.in.AuthenticateUserUseCase;
|
||||
import com.olhar.olharapi.application.port.out.UserRepository;
|
||||
import com.olhar.olharapi.domain.exception.UserNotFoundException;
|
||||
import com.olhar.olharapi.domain.model.User;
|
||||
import com.olhar.olharapi.infrastructure.security.JwtService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AuthenticateUserService implements AuthenticateUserUseCase {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final JwtService jwtService;
|
||||
|
||||
@Override
|
||||
public String authenticate(Command command) {
|
||||
User user = userRepository.findByEmail(command.email())
|
||||
.orElseThrow(() -> new UserNotFoundException(command.email()));
|
||||
|
||||
if (!passwordEncoder.matches(command.password(), user.passwordHash())) {
|
||||
throw new BadCredentialsException("Invalid credentials");
|
||||
}
|
||||
|
||||
return jwtService.generateToken(user);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user