|
|
|
@ -1,5 +1,7 @@
|
|
|
|
package com.mfsys.aconnect.security.service;
|
|
|
|
package com.mfsys.aconnect.security.service;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.mfsys.aconnect.security.exception.AuthenticationException;
|
|
|
|
|
|
|
|
import com.mfsys.common.configuration.constant.ERRCode;
|
|
|
|
import com.mfsys.common.configuration.service.JwtService;
|
|
|
|
import com.mfsys.common.configuration.service.JwtService;
|
|
|
|
import com.mfsys.common.configuration.service.PasswordEncryptionService;
|
|
|
|
import com.mfsys.common.configuration.service.PasswordEncryptionService;
|
|
|
|
import com.mfsys.aconnect.security.dto.LoginRequest;
|
|
|
|
import com.mfsys.aconnect.security.dto.LoginRequest;
|
|
|
|
@ -26,12 +28,14 @@ public class AuthenticationService {
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public LoginResponse login(LoginRequest loginRequest) {
|
|
|
|
public LoginResponse login(LoginRequest loginRequest) {
|
|
|
|
// Find user by email
|
|
|
|
// Find user by email
|
|
|
|
User user = userRepository.findByUserIdAndIsActiveTrue(loginRequest.getUserId())
|
|
|
|
User user = userRepository.findByUserIdAndIsActiveTrue(loginRequest.getUserId())
|
|
|
|
.orElseThrow(() -> new RuntimeException("Invalid credentials"));
|
|
|
|
.orElseThrow(() ->
|
|
|
|
|
|
|
|
new AuthenticationException("Authentication", ERRCode.INVALID_CREDENTIALS)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// Verify password
|
|
|
|
// Verify password
|
|
|
|
if (!PasswordEncryptionService.verifyPassword(loginRequest.getPassword(), user.getPassword())) {
|
|
|
|
if (!PasswordEncryptionService.verifyPassword(loginRequest.getPassword(), user.getPassword())) {
|
|
|
|
throw new RuntimeException("Invalid credentials");
|
|
|
|
throw new AuthenticationException("Authentication", ERRCode.INVALID_CREDENTIALS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String token = jwtService.generateToken(loginRequest.getUserId());
|
|
|
|
String token = jwtService.generateToken(loginRequest.getUserId());
|
|
|
|
|