Files
Olhar-API/src/main/java/com/olhar/olharapi/application/usecase/AuthenticateUserService.java
T
Gato 12a28af1ca
CI — Tests & Docker Build / Tests (push) Failing after 4s
CI — Tests & Docker Build / Build & push image Docker (push) Has been skipped
feat(auth): POST /auth/login retourne email, name, role et token
- Champ `name` ajouté sur User, UserEntity, RegisterRequest
- AuthenticateUserUseCase retourne Result(user, token) au lieu du token seul
- UserNotFoundException remplacé par BadCredentialsException au login (pas de fuite d'info)
- @Email retiré de LoginRequest (identifiant = "gato", pas nécessairement un email)
- Migration V2 : colonne name + utilisateur par défaut gato/change (ADMIN)
- bytecode cible Java 21 (ASM Spring Boot 3.4 ne supporte pas Java 25)
- Tests : AbstractIntegrationTest simplifié, URL TC JDBC + network host

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-07 08:24:41 +02:00

32 lines
1.2 KiB
Java

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.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 Result authenticate(Command command) {
User user = userRepository.findByEmail(command.email())
.orElseThrow(() -> new BadCredentialsException("Identifiants invalides"));
if (!passwordEncoder.matches(command.password(), user.passwordHash())) {
throw new BadCredentialsException("Identifiants invalides");
}
return new Result(user, jwtService.generateToken(user));
}
}