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
FieldsModifier and TypeFieldDescriptionprivate static final PatternThe regex used to check if the email is valid.private final JwtServiceThe service that handles the JWT.private org.springframework.security.crypto.password.PasswordEncoderThe service that encodes the password.private RequestAnalyzerThe service that analyzes the request.private final UserRepositoryThe repository forUserentity.private final WorkerRepositoryThe repository forWorkerentity. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchangeEmail(String newEmail, String oldEmail) Changes the email of the user or worker.voidchangePassword(String oldPassword, String newPassword) Changes the password of the user or worker.private booleanemailValid(String email) Checks if the email is valid.voidlogout()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 forWorkerentity. -
userRepository
The repository forUserentity. -
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:
logoutin 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:
refreshAccessTokenin 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:
changePasswordin 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:
changeEmailin 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
-