[R9] Auth Service class with login method

This commit is contained in:
Mirna Gama 2024-01-11 14:51:29 -03:00 committed by Mirna Gama
parent 276e62da72
commit becd713f20
2 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,41 @@
package com.mirna.hospitalmanagementapi.application.services.auth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;
import com.mirna.hospitalmanagementapi.domain.dtos.auth.UserLoginDTO;
import com.mirna.hospitalmanagementapi.domain.services.auth.AuthService;
/**
* This class is an implementation of the AuthService interface.
*
* This class provides methods to perform operations on users registration and authentication
*
* @author Mirna Gama
* @version 1.0
*/
@Service
public class AuthServiceImpl implements AuthService {
@Autowired
private AuthenticationManager manager;
/**
* Performs the user login
*
* @param userLoginDTO Data transfer object containing user credentials for login
* @return A fully authentication object including the credentials
*/
@Override
public Authentication login(UserLoginDTO userLoginDTO) {
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(userLoginDTO.login(),
userLoginDTO.password());
return manager.authenticate(token);
}
}

View File

@ -0,0 +1,23 @@
package com.mirna.hospitalmanagementapi.domain.services.auth;
import org.springframework.security.core.Authentication;
import com.mirna.hospitalmanagementapi.domain.dtos.auth.UserLoginDTO;
/**
* Authentication service interface for managing authentication and registration.
*
* @see User
* @author Mirna Gama
* @version 1.0
*/
public interface AuthService {
/**
* Performs the user login
*
* @param userLoginDTO Data transfer object containing user credentials for login
* @return A fully authentication object including the credentials
*/
public Authentication login(UserLoginDTO userLoginDTO);
}