From b2b1617a405751f7e17f35a392a54d2812426b50 Mon Sep 17 00:00:00 2001 From: "DESKTOP-E7L6HLO\\Noyan" Date: Sun, 21 Jul 2024 15:27:20 +0300 Subject: [PATCH] Task 61 : Add missing Java Doc for auth service --- .../authservice/AuthserviceApplication.java | 10 ++++++ .../authservice/client/UserServiceClient.java | 34 +++++++++++++++++++ .../authservice/config/SecurityConfig.java | 30 +++++++++++++++- .../controller/AuthController.java | 29 +++++++++++++++- .../authservice/exception/CustomError.java | 10 ++++++ ...CustomBearerTokenAuthenticationFilter.java | 15 ++++++++ .../authservice/model/auth/Token.java | 17 ++++++++++ .../authservice/model/auth/User.java | 4 +++ .../model/auth/dto/request/LoginRequest.java | 3 ++ .../auth/dto/request/RegisterRequest.java | 4 +++ .../dto/request/TokenInvalidateRequest.java | 4 +++ .../auth/dto/request/TokenRefreshRequest.java | 4 +++ .../auth/dto/response/TokenResponse.java | 4 +++ .../model/auth/enums/UserStatus.java | 4 +++ .../model/auth/enums/UserType.java | 4 +++ .../CustomAuthenticationEntryPoint.java | 14 +++++++- .../authservice/service/LogoutService.java | 10 ++++++ .../service/RefreshTokenService.java | 10 ++++++ .../authservice/service/RegisterService.java | 10 ++++++ .../authservice/service/UserLoginService.java | 10 ++++++ .../service/impl/LogoutServiceImpl.java | 11 ++++++ .../service/impl/RefreshTokenServiceImpl.java | 10 ++++++ .../service/impl/RegisterServiceImpl.java | 10 ++++++ .../service/impl/UserLoginServiceImpl.java | 11 ++++++ 24 files changed, 269 insertions(+), 3 deletions(-) diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/AuthserviceApplication.java b/authservice/src/main/java/com/springbootmicroservices/authservice/AuthserviceApplication.java index 2fc43a0..0c16305 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/AuthserviceApplication.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/AuthserviceApplication.java @@ -4,10 +4,20 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.openfeign.EnableFeignClients; +/** + * The entry point for the API Gateway Spring Boot application. + * This application is a Eureka client that registers itself with a Eureka server. + * The application is configured with the {@link SpringBootApplication} annotation. + */ @SpringBootApplication @EnableFeignClients public class AuthserviceApplication { + /** + * Main method to run the Spring Boot application. + * + * @param args Command-line arguments passed during the application startup. + */ public static void main(String[] args) { SpringApplication.run(AuthserviceApplication.class, args); } diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/client/UserServiceClient.java b/authservice/src/main/java/com/springbootmicroservices/authservice/client/UserServiceClient.java index d23f690..6b084cd 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/client/UserServiceClient.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/client/UserServiceClient.java @@ -14,21 +14,55 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; +/** + * Feign client interface named {@link UserServiceClient} for interacting with the User Service. + * This client is used to perform various operations related to user management, + * such as registration, token validation, login, token refresh, and logout. + */ @FeignClient(name = "userservice", path = "/api/v1/users") public interface UserServiceClient { + /** + * Registers a new user with the provided registration request. + * + * @param request the registration request containing user details + * @return the registered user + */ @PostMapping("/register") ResponseEntity register(@RequestBody @Valid final RegisterRequest request); + /** + * Validates the given token by making a POST request to the User Service. + * + * @param token the token to be validated + */ @PostMapping("/validate-token") void validateToken(@RequestParam String token); + /** + * Logs in a user with the provided login request. + * + * @param loginRequest the login request containing user credentials + * @return the token response containing access and refresh tokens + */ @PostMapping("/login") CustomResponse loginUser(@RequestBody @Valid final LoginRequest loginRequest); + /** + * Refreshes the access token using the provided token refresh request. + * + * @param tokenRefreshRequest the token refresh request containing the refresh token + * @return the token response containing new access and refresh tokens + */ @PostMapping("/refresh-token") CustomResponse refreshToken(@RequestBody @Valid final TokenRefreshRequest tokenRefreshRequest); + /** + * Logs out a user by invalidating the provided token. + * + * @param tokenInvalidateRequest the token invalidate request containing the token to be invalidated + * @return a response indicating the result of the logout operation + */ @PostMapping("/logout") CustomResponse logout(@RequestBody @Valid final TokenInvalidateRequest tokenInvalidateRequest); diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/config/SecurityConfig.java b/authservice/src/main/java/com/springbootmicroservices/authservice/config/SecurityConfig.java index 24f70ec..cecc5b3 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/config/SecurityConfig.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/config/SecurityConfig.java @@ -24,17 +24,35 @@ import java.util.List; +/** + * Configuration class named {@link SecurityConfig} for Spring Security. + * It sets up security filters, session management, CORS configuration, and password encoding. + */ @Configuration @EnableWebSecurity @RequiredArgsConstructor @EnableMethodSecurity public class SecurityConfig { + /** + * Configures the session authentication strategy. + * + * @return the session authentication strategy + */ @Bean protected SessionAuthenticationStrategy sessionAuthenticationStrategy() { return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl()); } + /** + * Configures the security filter chain. + * + * @param httpSecurity the HttpSecurity to modify + * @param customBearerTokenAuthenticationFilter the custom filter for Bearer token authentication + * @param customAuthenticationEntryPoint the custom entry point for authentication errors + * @return the configured security filter chain + * @throws Exception if an error occurs while configuring the filter chain + */ @Bean public SecurityFilterChain filterChain( final HttpSecurity httpSecurity, @@ -56,7 +74,11 @@ public SecurityFilterChain filterChain( return httpSecurity.build(); } - + /** + * Configures the CORS settings. + * + * @return the CORS configuration source + */ private CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); configuration.setAllowedOrigins(List.of("*")); @@ -67,8 +89,14 @@ private CorsConfigurationSource corsConfigurationSource() { return source; } + /** + * Configures the password encoder. + * + * @return the password encoder + */ @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } + } diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/controller/AuthController.java b/authservice/src/main/java/com/springbootmicroservices/authservice/controller/AuthController.java index a6bc4d0..fbb6cd5 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/controller/AuthController.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/controller/AuthController.java @@ -17,6 +17,10 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * Controller named {@link AuthController} for handling authentication-related operations. + * This includes user registration, login, token refresh, and logout. + */ @RestController @RequestMapping("/api/v1/authentication/users") @RequiredArgsConstructor @@ -30,23 +34,46 @@ public class AuthController { private final LogoutService logoutService; - + /** + * Registers a new user with the provided registration request. + * + * @param registerRequest the registration request containing user details + * @return a response indicating success + */ @PostMapping("/register") public CustomResponse registerAdmin(@RequestBody @Valid final RegisterRequest registerRequest) { registerService.registerUser(registerRequest); return CustomResponse.SUCCESS; } + /** + * Logs in a user with the provided login request. + * + * @param loginRequest the login request containing user credentials + * @return the token response containing access and refresh tokens + */ @PostMapping("/login") public CustomResponse loginUser(@RequestBody @Valid final LoginRequest loginRequest) { return userLoginService.login(loginRequest); } + /** + * Refreshes the access token using the provided token refresh request. + * + * @param tokenRefreshRequest the token refresh request containing the refresh token + * @return the token response containing new access and refresh tokens + */ @PostMapping("/refresh-token") public CustomResponse refreshToken(@RequestBody @Valid final TokenRefreshRequest tokenRefreshRequest) { return refreshTokenService.refreshToken(tokenRefreshRequest); } + /** + * Logs out a user by invalidating the provided token. + * + * @param tokenInvalidateRequest the token invalidate request containing the token to be invalidated + * @return a response indicating success + */ @PostMapping("/logout") public CustomResponse logout(@RequestBody @Valid final TokenInvalidateRequest tokenInvalidateRequest) { logoutService.logout(tokenInvalidateRequest); diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/exception/CustomError.java b/authservice/src/main/java/com/springbootmicroservices/authservice/exception/CustomError.java index 3c7f43f..c873769 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/exception/CustomError.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/exception/CustomError.java @@ -9,6 +9,10 @@ import java.time.LocalDateTime; import java.util.List; +/** + * Represents a custom error response named {@link CustomError} for the API. + * It contains details about the error such as time, HTTP status, header, message, and sub-errors. + */ @Getter @Builder public class CustomError { @@ -29,6 +33,9 @@ public class CustomError { @JsonInclude(JsonInclude.Include.NON_NULL) private List subErrors; + /** + * Represents a sub-error, providing additional details about the error. + */ @Getter @Builder public static class CustomSubError { @@ -45,6 +52,9 @@ public static class CustomSubError { } + /** + * Enum representing the headers for different types of errors. + */ @Getter @RequiredArgsConstructor public enum Header { diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/filter/CustomBearerTokenAuthenticationFilter.java b/authservice/src/main/java/com/springbootmicroservices/authservice/filter/CustomBearerTokenAuthenticationFilter.java index 29c216e..6ba4498 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/filter/CustomBearerTokenAuthenticationFilter.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/filter/CustomBearerTokenAuthenticationFilter.java @@ -15,6 +15,10 @@ import java.io.IOException; +/** + * Filter named {@link CustomBearerTokenAuthenticationFilter} for authenticating requests using a Bearer token. + * This filter validates the Bearer token by calling the user service. + */ @Slf4j @Component @RequiredArgsConstructor @@ -22,6 +26,15 @@ public class CustomBearerTokenAuthenticationFilter extends OncePerRequestFilter private final UserServiceClient userServiceClient; + /** + * Filters requests to authenticate using a Bearer token. + * + * @param httpServletRequest the HTTP request + * @param httpServletResponse the HTTP response + * @param filterChain the filter chain + * @throws ServletException if an error occurs during filtering + * @throws IOException if an I/O error occurs during filtering + */ @Override protected void doFilterInternal(@NonNull final HttpServletRequest httpServletRequest, @NonNull final HttpServletResponse httpServletResponse, @@ -37,5 +50,7 @@ protected void doFilterInternal(@NonNull final HttpServletRequest httpServletReq } filterChain.doFilter(httpServletRequest, httpServletResponse); + } + } diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/Token.java b/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/Token.java index c18af44..f12424b 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/Token.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/Token.java @@ -4,6 +4,10 @@ import lombok.Getter; import org.springframework.util.StringUtils; +/** + * Represents an authentication token named {@link Token} used for securing API requests. + * This class contains the access token, its expiration time, and the refresh token. + */ @Getter @Builder public class Token { @@ -14,11 +18,24 @@ public class Token { private static final String TOKEN_PREFIX = "Bearer "; + /** + * Checks if the given authorization header contains a Bearer token. + * + * @param authorizationHeader the Authorization header value + * @return {@code true} if the header starts with "Bearer "; {@code false} otherwise + */ public static boolean isBearerToken(final String authorizationHeader) { return StringUtils.hasText(authorizationHeader) && authorizationHeader.startsWith(TOKEN_PREFIX); } + /** + * Extracts the JWT from the given Authorization header. + * The JWT is expected to follow the Bearer token prefix. + * + * @param authorizationHeader the Authorization header value + * @return the JWT extracted from the header, without the "Bearer " prefix + */ public static String getJwt(final String authorizationHeader) { return authorizationHeader.replace(TOKEN_PREFIX, ""); } diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/User.java b/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/User.java index b65570f..47d7b72 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/User.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/User.java @@ -7,6 +7,10 @@ import lombok.Setter; import lombok.experimental.SuperBuilder; +/** + * Represents a user named {@link User} in the system. + * This class contains information about the user's identity, contact details, status, and type. + */ @Getter @Setter @SuperBuilder diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/dto/request/LoginRequest.java b/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/dto/request/LoginRequest.java index 788e272..cf56ce2 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/dto/request/LoginRequest.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/dto/request/LoginRequest.java @@ -3,6 +3,9 @@ import jakarta.validation.constraints.NotBlank; import lombok.*; +/** + * Represents a login request named {@link LoginRequest} containing the user's email and password. + */ @Getter @Setter @Builder diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/dto/request/RegisterRequest.java b/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/dto/request/RegisterRequest.java index d754555..0894f9a 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/dto/request/RegisterRequest.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/dto/request/RegisterRequest.java @@ -5,6 +5,10 @@ import jakarta.validation.constraints.Size; import lombok.*; +/** + * Represents a request named {@link RegisterRequest} for user registration. + * This class contains the necessary details required to register a new user. + */ @Getter @Setter @NoArgsConstructor diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/dto/request/TokenInvalidateRequest.java b/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/dto/request/TokenInvalidateRequest.java index 65d8427..21534e0 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/dto/request/TokenInvalidateRequest.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/dto/request/TokenInvalidateRequest.java @@ -3,6 +3,10 @@ import jakarta.validation.constraints.NotBlank; import lombok.*; +/** + * Represents a request named {@link TokenInvalidateRequest} to invalidate tokens. + * This class contains the access and refresh tokens that need to be invalidated. + */ @Getter @Setter @Builder diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/dto/request/TokenRefreshRequest.java b/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/dto/request/TokenRefreshRequest.java index b66e73e..ec7eb38 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/dto/request/TokenRefreshRequest.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/dto/request/TokenRefreshRequest.java @@ -3,6 +3,10 @@ import jakarta.validation.constraints.NotBlank; import lombok.*; +/** + * Represents a request named {@link TokenRefreshRequest} to refresh an access token using a refresh token. + * This class contains the refresh token required for obtaining a new access token. + */ @Getter @Setter @Builder diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/dto/response/TokenResponse.java b/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/dto/response/TokenResponse.java index abf9e55..763812a 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/dto/response/TokenResponse.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/dto/response/TokenResponse.java @@ -2,6 +2,10 @@ import lombok.*; +/** + * Represents a response named {@link TokenResponse} containing tokens for authentication. + * This class includes the access token, its expiration time, and the refresh token. + */ @Getter @Setter @Builder diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/enums/UserStatus.java b/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/enums/UserStatus.java index 88f0805..808c046 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/enums/UserStatus.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/enums/UserStatus.java @@ -1,5 +1,9 @@ package com.springbootmicroservices.authservice.model.auth.enums; +/** + * Represents the status of a user. + * This enum defines the different states a user can have in the system. + */ public enum UserStatus { ACTIVE, PASSIVE, diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/enums/UserType.java b/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/enums/UserType.java index 98776a2..8428639 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/enums/UserType.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/model/auth/enums/UserType.java @@ -1,5 +1,9 @@ package com.springbootmicroservices.authservice.model.auth.enums; +/** + * Represents the type of a user in the system. + * This enum defines the different roles a user can have. + */ public enum UserType { USER, ADMIN diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/security/CustomAuthenticationEntryPoint.java b/authservice/src/main/java/com/springbootmicroservices/authservice/security/CustomAuthenticationEntryPoint.java index 0195b04..725e147 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/security/CustomAuthenticationEntryPoint.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/security/CustomAuthenticationEntryPoint.java @@ -14,6 +14,11 @@ import java.io.IOException; import java.text.DateFormat; +/** + * Custom implementation of {@link AuthenticationEntryPoint}. + * This class handles authentication errors by returning a custom JSON error response. + * It is used to respond with an appropriate error message when an unauthenticated request is made. + */ @Component public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint { @@ -23,7 +28,14 @@ public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint OBJECT_MAPPER.registerModule(new JavaTimeModule()); } - + /** + * Commences the authentication process by sending an unauthorized error response. + * + * @param httpServletRequest the request that resulted in an authentication error + * @param httpServletResponse the response to send back to the client + * @param authenticationException the exception that triggered the authentication failure + * @throws IOException if an input or output exception occurs + */ @Override public void commence(final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse, final AuthenticationException authenticationException) throws IOException { diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/service/LogoutService.java b/authservice/src/main/java/com/springbootmicroservices/authservice/service/LogoutService.java index 410210b..b537584 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/service/LogoutService.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/service/LogoutService.java @@ -5,8 +5,18 @@ import jakarta.validation.Valid; import org.springframework.web.bind.annotation.RequestBody; +/** + * Service interface named {@link LogoutService} for handling user logout operations. + * Provides methods for invalidating user tokens during logout. + */ public interface LogoutService { + /** + * Logs out a user by invalidating the provided tokens. + * + * @param tokenInvalidateRequest the request containing the access and refresh tokens to be invalidated + * @return a {@link CustomResponse} indicating the result of the logout operation + */ CustomResponse logout(@RequestBody @Valid final TokenInvalidateRequest tokenInvalidateRequest); } diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/service/RefreshTokenService.java b/authservice/src/main/java/com/springbootmicroservices/authservice/service/RefreshTokenService.java index b643e87..34bec1f 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/service/RefreshTokenService.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/service/RefreshTokenService.java @@ -6,8 +6,18 @@ import jakarta.validation.Valid; import org.springframework.web.bind.annotation.RequestBody; +/** + * Service interface named {@link RefreshTokenService} for handling token refresh operations. + * Provides methods for refreshing access tokens using a refresh token. + */ public interface RefreshTokenService { + /** + * Refreshes the access token using the provided refresh token. + * + * @param tokenRefreshRequest the request containing the refresh token + * @return a {@link CustomResponse} containing the {@link TokenResponse} with the new access and refresh tokens + */ CustomResponse refreshToken(@RequestBody @Valid final TokenRefreshRequest tokenRefreshRequest); } diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/service/RegisterService.java b/authservice/src/main/java/com/springbootmicroservices/authservice/service/RegisterService.java index 294b447..a530ea1 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/service/RegisterService.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/service/RegisterService.java @@ -3,8 +3,18 @@ import com.springbootmicroservices.authservice.model.auth.User; import com.springbootmicroservices.authservice.model.auth.dto.request.RegisterRequest; +/** + * Service interface named {@link RegisterService} for user registration operations. + * Provides methods for registering a new user. + */ public interface RegisterService { + /** + * Registers a new user with the provided registration details. + * + * @param registerRequest the registration request containing user details (email, password, etc.) + * @return the registered {@link User} object + */ User registerUser(final RegisterRequest registerRequest); } diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/service/UserLoginService.java b/authservice/src/main/java/com/springbootmicroservices/authservice/service/UserLoginService.java index b396c98..91a44b2 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/service/UserLoginService.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/service/UserLoginService.java @@ -4,8 +4,18 @@ import com.springbootmicroservices.authservice.model.auth.dto.response.TokenResponse; import com.springbootmicroservices.authservice.model.common.dto.response.CustomResponse; +/** + * Service interface named {@link UserLoginService} for user login operations. + * Provides methods for handling user login and generating authentication tokens. + */ public interface UserLoginService { + /** + * Logs in a user by processing the provided login request and generating authentication tokens. + * + * @param loginRequest the login request containing user credentials (email and password) + * @return a {@link CustomResponse} containing the {@link TokenResponse} with authentication tokens + */ CustomResponse login(final LoginRequest loginRequest); } diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/service/impl/LogoutServiceImpl.java b/authservice/src/main/java/com/springbootmicroservices/authservice/service/impl/LogoutServiceImpl.java index e867fe4..d1be2a8 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/service/impl/LogoutServiceImpl.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/service/impl/LogoutServiceImpl.java @@ -7,14 +7,25 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +/** + * Implementation of the {@link LogoutService} interface. + * Handles the logic for user logout by invalidating tokens via the {@link UserServiceClient}. + */ @Service @RequiredArgsConstructor public class LogoutServiceImpl implements LogoutService { private final UserServiceClient userServiceClient; + /** + * Logs out a user by invalidating the provided tokens. + * + * @param tokenInvalidateRequest the request containing the access and refresh tokens to be invalidated + * @return a {@link CustomResponse} indicating the result of the logout operation + */ @Override public CustomResponse logout(TokenInvalidateRequest tokenInvalidateRequest) { return userServiceClient.logout(tokenInvalidateRequest); } + } diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/service/impl/RefreshTokenServiceImpl.java b/authservice/src/main/java/com/springbootmicroservices/authservice/service/impl/RefreshTokenServiceImpl.java index f1842cd..0d7feb6 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/service/impl/RefreshTokenServiceImpl.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/service/impl/RefreshTokenServiceImpl.java @@ -8,12 +8,22 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +/** + * Implementation of the {@link RefreshTokenService} interface. + * Handles the logic for refreshing access tokens using a refresh token via the {@link UserServiceClient}. + */ @Service @RequiredArgsConstructor public class RefreshTokenServiceImpl implements RefreshTokenService { private final UserServiceClient userServiceClient; + /** + * Refreshes the access token using the provided refresh token. + * + * @param tokenRefreshRequest the request containing the refresh token + * @return a {@link CustomResponse} containing the {@link TokenResponse} with the new access and refresh tokens + */ @Override public CustomResponse refreshToken(TokenRefreshRequest tokenRefreshRequest) { return userServiceClient.refreshToken(tokenRefreshRequest); diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/service/impl/RegisterServiceImpl.java b/authservice/src/main/java/com/springbootmicroservices/authservice/service/impl/RegisterServiceImpl.java index e38414e..8abefaf 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/service/impl/RegisterServiceImpl.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/service/impl/RegisterServiceImpl.java @@ -7,12 +7,22 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +/** + * Implementation of the {@link RegisterService} interface. + * Handles the logic for user registration by forwarding the request to the {@link UserServiceClient}. + */ @Service @RequiredArgsConstructor public class RegisterServiceImpl implements RegisterService { private final UserServiceClient userServiceClient; + /** + * Registers a new user with the provided registration details. + * + * @param registerRequest the registration request containing user details (email, password, etc.) + * @return the registered {@link User} object + */ @Override public User registerUser(RegisterRequest registerRequest) { return userServiceClient.register(registerRequest).getBody(); diff --git a/authservice/src/main/java/com/springbootmicroservices/authservice/service/impl/UserLoginServiceImpl.java b/authservice/src/main/java/com/springbootmicroservices/authservice/service/impl/UserLoginServiceImpl.java index 0ec6fdd..076020b 100644 --- a/authservice/src/main/java/com/springbootmicroservices/authservice/service/impl/UserLoginServiceImpl.java +++ b/authservice/src/main/java/com/springbootmicroservices/authservice/service/impl/UserLoginServiceImpl.java @@ -8,14 +8,25 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +/** + * Implementation of the {@link UserLoginService} interface. + * Handles user login by processing the login request and generating authentication tokens via the {@link UserServiceClient}. + */ @Service @RequiredArgsConstructor public class UserLoginServiceImpl implements UserLoginService { private final UserServiceClient userServiceClient; + /** + * Logs in a user by processing the provided login request and generating authentication tokens. + * + * @param loginRequest the login request containing user credentials (email and password) + * @return a {@link CustomResponse} containing the {@link TokenResponse} with authentication tokens + */ @Override public CustomResponse login(LoginRequest loginRequest) { return userServiceClient.loginUser(loginRequest); } + }