Class UserWorkerMutationServiceImpl
java.lang.Object
it.univr.passportease.service.userworker.impl.UserWorkerMutationServiceImpl
- All Implemented Interfaces:
UserWorkerMutationService
@Service
public class UserWorkerMutationServiceImpl
extends Object
implements UserWorkerMutationService
Implementation of
UserWorkerMutationService
. This class contains all the methods that can be used to
mutate user and worker data.-
Field Summary
Modifier and TypeFieldDescriptionprivate static final Pattern
The regex used to check if the email is valid.private final JwtService
The service that handles the JWT.private org.springframework.security.crypto.password.PasswordEncoder
The service that encodes the password.private RequestAnalyzer
The service that analyzes the request.private final UserRepository
The repository forUser
entity.private final WorkerRepository
The repository forWorker
entity. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionchangeEmail
(String newEmail, String oldEmail) Changes the email of the user or worker.void
changePassword
(String oldPassword, String newPassword) Changes the password of the user or worker.private boolean
emailValid
(String email) Checks if the email is valid.void
logout()
Logs out the user by invalidating the access token and the refresh token.refreshAccessToken
(JWT token, JWT refreshToken) Refreshes the access token and the refresh token.
-
Field Details
-
EMAIL_VALID_REGEX
The regex used to check if the email is valid. -
workerRepository
The repository forWorker
entity. -
userRepository
The repository forUser
entity. -
jwtService
The service that handles the JWT. -
requestAnalyzer
The service that analyzes the request. -
passwordEncoder
private org.springframework.security.crypto.password.PasswordEncoder passwordEncoderThe service that encodes the password.
-
-
Constructor Details
-
UserWorkerMutationServiceImpl
public UserWorkerMutationServiceImpl()
-
-
Method Details
-
logout
@PreAuthorize("hasAnyAuthority(\'USER\', \'WORKER\') && hasAuthority(\'VALIDATED\')") public void logout() throws UserNotFoundException, TokenNotInRedisException, AuthenticationCredentialsNotFoundExceptionLogs out the user by invalidating the access token and the refresh token.- Specified by:
logout
in interfaceUserWorkerMutationService
- Throws:
UserNotFoundException
- if the user is not foundTokenNotInRedisException
- if the token is not in redisAuthenticationCredentialsNotFoundException
- if the authentication credentials are not found
-
refreshAccessToken
@PreAuthorize("hasAnyAuthority(\'USER\', \'WORKER\') && hasAuthority(\'VALIDATED\')") public JWTSet refreshAccessToken(JWT token, JWT refreshToken) throws UserNotFoundException, InvalidRefreshTokenException, UserOrWorkerIDNotFoundException Refreshes the access token and the refresh token. TODO: check if the old Access token will be invalidated- Specified by:
refreshAccessToken
in interfaceUserWorkerMutationService
- Parameters:
token
- JWT Access tokenrefreshToken
- JWT Refresh token- Returns:
- New JWT access token and refresh token
- Throws:
UserNotFoundException
- if the user is not foundInvalidRefreshTokenException
- if the refresh token is invalidUserOrWorkerIDNotFoundException
- if the user or worker ID is not found
-
changePassword
@PreAuthorize("hasAnyAuthority(\'USER\', \'WORKER\') && hasAuthority(\'VALIDATED\')") public void changePassword(String oldPassword, String newPassword) throws UserNotFoundException, WrongPasswordException, AuthenticationCredentialsNotFoundException Changes the password of the user or worker.- Specified by:
changePassword
in interfaceUserWorkerMutationService
- Parameters:
oldPassword
- old passwordnewPassword
- new password- Throws:
UserNotFoundException
- if the user is not foundWrongPasswordException
- if the old password is wrongAuthenticationCredentialsNotFoundException
- if the authentication credentials are not found
-
changeEmail
@PreAuthorize("hasAnyAuthority(\'USER\', \'WORKER\') && hasAuthority(\'VALIDATED\')") public String changeEmail(String newEmail, String oldEmail) throws UserNotFoundException, InvalidEmailException, AuthenticationCredentialsNotFoundException Changes the email of the user or worker.- Specified by:
changeEmail
in interfaceUserWorkerMutationService
- Parameters:
newEmail
- new emailoldEmail
- old email- Returns:
- new email
- Throws:
UserNotFoundException
- if the user is not foundInvalidEmailException
- if the email is invalidAuthenticationCredentialsNotFoundException
- if the authentication credentials are not found
-
emailValid
Checks if the email is valid.- Parameters:
email
- email- Returns:
- true if the email is valid, false otherwise
-