12a28af1ca
- 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>
32 lines
1.2 KiB
Java
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));
|
|
}
|
|
}
|