From b72db6190cc44288cc984b87e47dfd58cf8e7be9 Mon Sep 17 00:00:00 2001 From: "DESKTOP-E7L6HLO\\Noyan" Date: Sun, 21 Jul 2024 15:56:48 +0300 Subject: [PATCH] Task 62 : Add missing Java Doc for product service --- .../client/UserServiceClient.java | 15 ++++++++ .../config/FeignClientConfig.java | 20 +++++++++++ .../productservice/config/SecurityConfig.java | 28 +++++++++++++++ .../config/TokenConfigurationParameter.java | 4 +++ .../controller/ProductController.java | 35 +++++++++++++++++++ ...CustomBearerTokenAuthenticationFilter.java | 20 +++++++++++ .../model/auth/ConfigurationParameter.java | 5 +++ .../productservice/model/auth/JwtRecord.java | 5 +++ .../productservice/model/auth/Token.java | 16 +++++++++ .../productservice/model/auth/UserStatus.java | 4 +++ .../productservice/model/auth/UserType.java | 4 +++ .../model/auth/enums/TokenClaims.java | 5 +++ .../CustomAuthenticationEntryPoint.java | 15 +++++++- .../serializer/LocalDateTimeSerializer.java | 13 +++++++ ...sswordAuthenticationTokenDeserializer.java | 19 +++++++++- ...rnamePasswordAuthenticationTokenMixin.java | 13 +++++++ .../utils/JwtRecordConverter.java | 17 +++++++++ .../productservice/utils/KeyConverter.java | 18 ++++++++++ 18 files changed, 254 insertions(+), 2 deletions(-) diff --git a/productservice/src/main/java/com/springbootmicroservices/productservice/client/UserServiceClient.java b/productservice/src/main/java/com/springbootmicroservices/productservice/client/UserServiceClient.java index 67e6eb5..d992839 100644 --- a/productservice/src/main/java/com/springbootmicroservices/productservice/client/UserServiceClient.java +++ b/productservice/src/main/java/com/springbootmicroservices/productservice/client/UserServiceClient.java @@ -7,12 +7,27 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; +/** + * Feign client interface named {@link UserServiceClient} for interacting with the User Service. + * Provides methods to validate tokens and retrieve authentication information. + */ @FeignClient(name = "userservice", path = "/api/v1/users", configuration = FeignClientConfig.class) public interface UserServiceClient { + /** + * Validates the provided token by making a request to the user service. + * + * @param token the token to validate + */ @PostMapping("/validate-token") void validateToken(@RequestParam String token); + /** + * Retrieves authentication information based on the provided token. + * + * @param token the token to use for retrieving authentication information + * @return {@link UsernamePasswordAuthenticationToken} containing authentication details + */ @GetMapping("/authenticate") UsernamePasswordAuthenticationToken getAuthentication(@RequestParam String token); diff --git a/productservice/src/main/java/com/springbootmicroservices/productservice/config/FeignClientConfig.java b/productservice/src/main/java/com/springbootmicroservices/productservice/config/FeignClientConfig.java index 16b4878..6856e3f 100644 --- a/productservice/src/main/java/com/springbootmicroservices/productservice/config/FeignClientConfig.java +++ b/productservice/src/main/java/com/springbootmicroservices/productservice/config/FeignClientConfig.java @@ -24,10 +24,19 @@ import java.util.Collection; import java.util.Map; +/** + * Configuration class named {@link FeignClientConfig} for setting up Feign client components. + * Configures custom error handling, object mapping, and decoding for Feign clients. + */ @Slf4j @Configuration public class FeignClientConfig { + /** + * Provides a custom {@link ObjectMapper} bean configured with Jackson modules. + * + * @return a configured {@link ObjectMapper} instance + */ @Bean public ObjectMapper objectMapper() { ObjectMapper objectMapper = new ObjectMapper(); @@ -42,11 +51,22 @@ public ObjectMapper objectMapper() { return objectMapper; } + /** + * Provides a custom {@link Decoder} bean for Feign clients. + * + * @param objectMapper the {@link ObjectMapper} to use for decoding + * @return a {@link Decoder} instance + */ @Bean public Decoder feignDecoder(ObjectMapper objectMapper) { return new CustomDecoder(objectMapper); } + /** + * Provides a custom {@link ErrorDecoder} bean for Feign clients. + * + * @return a {@link ErrorDecoder} instance + */ @Bean public ErrorDecoder errorDecoder() { return new CustomErrorDecoder(); diff --git a/productservice/src/main/java/com/springbootmicroservices/productservice/config/SecurityConfig.java b/productservice/src/main/java/com/springbootmicroservices/productservice/config/SecurityConfig.java index 95896cf..996b8a2 100644 --- a/productservice/src/main/java/com/springbootmicroservices/productservice/config/SecurityConfig.java +++ b/productservice/src/main/java/com/springbootmicroservices/productservice/config/SecurityConfig.java @@ -24,6 +24,10 @@ import java.util.List; +/** + * Security configuration class named {@link SecurityConfig} for setting up security filters and policies. + * Configures HTTP security settings, CORS, CSRF, and session management. + */ @Configuration @EnableWebSecurity @RequiredArgsConstructor @@ -31,11 +35,25 @@ @Slf4j public class SecurityConfig { + /** + * Configures the session authentication strategy. + * + * @return a {@link SessionAuthenticationStrategy} instance + */ @Bean protected SessionAuthenticationStrategy sessionAuthenticationStrategy() { return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl()); } + /** + * Configures the security filter chain for HTTP requests. + * + * @param httpSecurity the {@link HttpSecurity} to configure + * @param customBearerTokenAuthenticationFilter the custom filter for token authentication + * @param customAuthenticationEntryPoint the custom entry point for authentication errors + * @return a configured {@link SecurityFilterChain} instance + * @throws Exception if an error occurs while configuring security + */ @Bean public SecurityFilterChain filterChain( final HttpSecurity httpSecurity, @@ -60,6 +78,11 @@ public SecurityFilterChain filterChain( return httpSecurity.build(); } + /** + * Provides CORS configuration for the application. + * + * @return a {@link CorsConfigurationSource} instance + */ private CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); configuration.setAllowedOrigins(List.of("*")); @@ -70,6 +93,11 @@ private CorsConfigurationSource corsConfigurationSource() { return source; } + /** + * Provides a {@link PasswordEncoder} bean for encoding passwords. + * + * @return a {@link PasswordEncoder} instance + */ @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); diff --git a/productservice/src/main/java/com/springbootmicroservices/productservice/config/TokenConfigurationParameter.java b/productservice/src/main/java/com/springbootmicroservices/productservice/config/TokenConfigurationParameter.java index dfbbf56..1dac4a0 100644 --- a/productservice/src/main/java/com/springbootmicroservices/productservice/config/TokenConfigurationParameter.java +++ b/productservice/src/main/java/com/springbootmicroservices/productservice/config/TokenConfigurationParameter.java @@ -8,6 +8,10 @@ import java.security.PrivateKey; import java.security.PublicKey; +/** + * Configuration class named {@link TokenConfigurationParameter} for token parameters. + * Provides access to token expiration settings and cryptographic keys. + */ @Getter @Configuration public class TokenConfigurationParameter { diff --git a/productservice/src/main/java/com/springbootmicroservices/productservice/controller/ProductController.java b/productservice/src/main/java/com/springbootmicroservices/productservice/controller/ProductController.java index 928c5e6..4daa49b 100644 --- a/productservice/src/main/java/com/springbootmicroservices/productservice/controller/ProductController.java +++ b/productservice/src/main/java/com/springbootmicroservices/productservice/controller/ProductController.java @@ -21,6 +21,10 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +/** + * REST controller named {@link ProductController} for managing products. + * Provides endpoints to create, read, update, and delete products. + */ @RestController @RequestMapping("/api/v1/products") @RequiredArgsConstructor @@ -37,6 +41,12 @@ public class ProductController { private final CustomPageToCustomPagingResponseMapper customPageToCustomPagingResponseMapper = CustomPageToCustomPagingResponseMapper.initialize(); + /** + * Creates a new product. + * + * @param productCreateRequest the request payload containing product details + * @return a {@link CustomResponse} containing the ID of the created product + */ @PostMapping @PreAuthorize("hasAnyAuthority('ADMIN')") public CustomResponse createProduct(@RequestBody @Valid final ProductCreateRequest productCreateRequest) { @@ -47,6 +57,12 @@ public CustomResponse createProduct(@RequestBody @Valid final ProductCre return CustomResponse.successOf(createdProduct.getId()); } + /** + * Retrieves a product by its ID. + * + * @param productId the ID of the product to retrieve + * @return a {@link CustomResponse} containing the product details + */ @GetMapping("/{productId}") @PreAuthorize("hasAnyAuthority('ADMIN', 'USER')") public CustomResponse getProductById(@PathVariable @UUID final String productId) { @@ -59,6 +75,12 @@ public CustomResponse getProductById(@PathVariable @UUID final } + /** + * Retrieves a paginated list of products based on the paging request. + * + * @param productPagingRequest the request payload containing paging information + * @return a {@link CustomResponse} containing the paginated list of products + */ @GetMapping @PreAuthorize("hasAnyAuthority('ADMIN', 'USER')") public CustomResponse> getProducts( @@ -73,6 +95,13 @@ public CustomResponse> getProducts( } + /** + * Updates an existing product by its ID. + * + * @param productUpdateRequest the request payload containing updated product details + * @param productId the ID of the product to update + * @return a {@link CustomResponse} containing the updated product details + */ @PutMapping("/{productId}") @PreAuthorize("hasAnyAuthority('ADMIN')") public CustomResponse updatedProductById( @@ -86,6 +115,12 @@ public CustomResponse updatedProductById( return CustomResponse.successOf(productResponse); } + /** + * Deletes a product by its ID. + * + * @param productId the ID of the product to delete + * @return a {@link CustomResponse} indicating successful deletion + */ @DeleteMapping("/{productId}") @PreAuthorize("hasAnyAuthority('ADMIN')") public CustomResponse deleteProductById(@PathVariable @UUID final String productId) { diff --git a/productservice/src/main/java/com/springbootmicroservices/productservice/filter/CustomBearerTokenAuthenticationFilter.java b/productservice/src/main/java/com/springbootmicroservices/productservice/filter/CustomBearerTokenAuthenticationFilter.java index f4c71e7..4ee656d 100644 --- a/productservice/src/main/java/com/springbootmicroservices/productservice/filter/CustomBearerTokenAuthenticationFilter.java +++ b/productservice/src/main/java/com/springbootmicroservices/productservice/filter/CustomBearerTokenAuthenticationFilter.java @@ -21,6 +21,11 @@ import java.io.IOException; +/** + * Custom filter named {@link CustomBearerTokenAuthenticationFilter} for handling Bearer token authentication in HTTP requests. + * This filter extracts the Bearer token from the Authorization header, + * validates it, and sets the authentication context if the token is valid. + */ @Slf4j @Component @RequiredArgsConstructor @@ -28,6 +33,21 @@ public class CustomBearerTokenAuthenticationFilter extends OncePerRequestFilter private final UserServiceClient userServiceClient; + /** + * Processes the incoming HTTP request and performs Bearer token authentication. + * + *

Extracts the Bearer token from the Authorization header, validates the token using + * {@link UserServiceClient#validateToken(String)}, and sets the authentication context + * if the token is valid. If validation fails, sets the appropriate HTTP status and + * writes an error message to the response. The filter chain proceeds regardless of + * token validation success or failure.

+ * + * @param httpServletRequest the HTTP request + * @param httpServletResponse the HTTP response + * @param filterChain the filter chain to proceed with + * @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, diff --git a/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/ConfigurationParameter.java b/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/ConfigurationParameter.java index 20039d4..9e3ff7b 100644 --- a/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/ConfigurationParameter.java +++ b/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/ConfigurationParameter.java @@ -3,6 +3,11 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; +/** + * Enum representing configuration parameters used for token management and key settings. + * This enum provides default values for various configuration parameters related + * to authentication, including token expiration settings and cryptographic keys. + */ @Getter @RequiredArgsConstructor public enum ConfigurationParameter { diff --git a/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/JwtRecord.java b/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/JwtRecord.java index 393ddbb..d70fbde 100644 --- a/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/JwtRecord.java +++ b/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/JwtRecord.java @@ -3,6 +3,11 @@ import java.time.Instant; import java.util.Map; +/** + * Represents a JWT (JSON Web Token) with its components and metadata. + * This record contains information about the token, its headers, claims, + * issuance and expiration times, subject, issuer, and audience. + */ public record JwtRecord(String tokenValue, Map headers, Map claims, Instant issuedAt, Instant expiresAt, String subject, String issuer, String audience) { // You can add any necessary methods or constructors here if needed diff --git a/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/Token.java b/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/Token.java index b7bc480..3320efe 100644 --- a/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/Token.java +++ b/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/Token.java @@ -4,6 +4,10 @@ import lombok.Getter; import org.springframework.util.StringUtils; +/** + * Represents authentication tokens used for access and refresh. + * This class contains the access token, its expiration time, and the refresh token. + */ @Getter @Builder public class Token { @@ -14,11 +18,23 @@ public class Token { private static final String TOKEN_PREFIX = "Bearer "; + /** + * Checks if the provided authorization header contains a Bearer token. + * + * @param authorizationHeader the authorization header to check + * @return {@code true} if the header contains a Bearer token, {@code false} otherwise + */ public static boolean isBearerToken(final String authorizationHeader) { return StringUtils.hasText(authorizationHeader) && authorizationHeader.startsWith(TOKEN_PREFIX); } + /** + * Extracts the JWT from the provided authorization header. + * + * @param authorizationHeader the authorization header containing the JWT + * @return the JWT extracted from the header + */ public static String getJwt(final String authorizationHeader) { return authorizationHeader.replace(TOKEN_PREFIX, ""); } diff --git a/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/UserStatus.java b/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/UserStatus.java index 629a4f3..51feaac 100644 --- a/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/UserStatus.java +++ b/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/UserStatus.java @@ -1,5 +1,9 @@ package com.springbootmicroservices.productservice.model.auth; +/** + * Enum representing various user statuses in the system. + * This enum is used to indicate the current status of a user account. + */ public enum UserStatus { ACTIVE, PASSIVE, diff --git a/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/UserType.java b/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/UserType.java index b0d6a30..f2eceee 100644 --- a/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/UserType.java +++ b/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/UserType.java @@ -1,5 +1,9 @@ package com.springbootmicroservices.productservice.model.auth; +/** + * Enum representing different user types in the system. + * This enum is used to categorize users based on their roles or permissions. + */ public enum UserType { USER, ADMIN diff --git a/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/enums/TokenClaims.java b/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/enums/TokenClaims.java index 5394be8..876f052 100644 --- a/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/enums/TokenClaims.java +++ b/productservice/src/main/java/com/springbootmicroservices/productservice/model/auth/enums/TokenClaims.java @@ -3,6 +3,11 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; +/** + * Enum representing various JWT token claims and their corresponding keys. + * This enum defines the standard claims used in JWT tokens along with their + * JSON keys, which are utilized for encoding and decoding JWT payloads. + */ @Getter @RequiredArgsConstructor public enum TokenClaims { diff --git a/productservice/src/main/java/com/springbootmicroservices/productservice/security/CustomAuthenticationEntryPoint.java b/productservice/src/main/java/com/springbootmicroservices/productservice/security/CustomAuthenticationEntryPoint.java index c433ab7..4404c65 100644 --- a/productservice/src/main/java/com/springbootmicroservices/productservice/security/CustomAuthenticationEntryPoint.java +++ b/productservice/src/main/java/com/springbootmicroservices/productservice/security/CustomAuthenticationEntryPoint.java @@ -14,6 +14,11 @@ import java.io.IOException; import java.text.DateFormat; +/** + * Custom implementation of the {@link AuthenticationEntryPoint} interface. + * This component is responsible for handling unauthorized access attempts + * by sending a custom error response when authentication fails. + */ @Component public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint { @@ -23,7 +28,15 @@ public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint OBJECT_MAPPER.registerModule(new JavaTimeModule()); } - + /** + * Handles authentication errors by sending a custom error response to the client. + * Sets the HTTP status to 401 Unauthorized and sends a JSON response with error details. + * + * @param httpServletRequest the request that resulted in an AuthenticationException + * @param httpServletResponse the response to send to the client + * @param authenticationException the exception that triggered this entry point + * @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/productservice/src/main/java/com/springbootmicroservices/productservice/serializer/LocalDateTimeSerializer.java b/productservice/src/main/java/com/springbootmicroservices/productservice/serializer/LocalDateTimeSerializer.java index d7a4702..4fd9e08 100644 --- a/productservice/src/main/java/com/springbootmicroservices/productservice/serializer/LocalDateTimeSerializer.java +++ b/productservice/src/main/java/com/springbootmicroservices/productservice/serializer/LocalDateTimeSerializer.java @@ -7,11 +7,24 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +/** + * Custom serializer for {@link LocalDateTime} objects. + * This serializer formats the {@link LocalDateTime} as an ISO-8601 string. + */ public class LocalDateTimeSerializer extends JsonSerializer { private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ISO_LOCAL_DATE_TIME; + /** + * Serializes the given {@link LocalDateTime} value to an ISO-8601 formatted string. + * + * @param value the {@link LocalDateTime} value to serialize + * @param gen the {@link JsonGenerator} used to write the serialized value + * @param serializers the {@link SerializerProvider} that can be used to get serializers for other types + * @throws IOException if an I/O error occurs + */ @Override public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException { gen.writeString(value.format(FORMATTER)); } + } diff --git a/productservice/src/main/java/com/springbootmicroservices/productservice/serializer/UsernamePasswordAuthenticationTokenDeserializer.java b/productservice/src/main/java/com/springbootmicroservices/productservice/serializer/UsernamePasswordAuthenticationTokenDeserializer.java index 700a389..00085d6 100644 --- a/productservice/src/main/java/com/springbootmicroservices/productservice/serializer/UsernamePasswordAuthenticationTokenDeserializer.java +++ b/productservice/src/main/java/com/springbootmicroservices/productservice/serializer/UsernamePasswordAuthenticationTokenDeserializer.java @@ -18,17 +18,34 @@ import java.util.ArrayList; import java.util.List; +/** + * Custom deserializer for {@link UsernamePasswordAuthenticationToken}. + * This deserializer converts JSON into a {@link UsernamePasswordAuthenticationToken} object. + */ public class UsernamePasswordAuthenticationTokenDeserializer extends JsonDeserializer { private final ObjectMapper objectMapper; + /** + * Constructs a {@link UsernamePasswordAuthenticationTokenDeserializer} with an {@link ObjectMapper} + * configured to handle date/time serialization and ignore unknown properties. + */ public UsernamePasswordAuthenticationTokenDeserializer() { this.objectMapper = new ObjectMapper(); this.objectMapper.registerModule(new JavaTimeModule()); // Register JavaTimeModule for date/time support this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); // Ignore unknown properties } - + /** + * Deserializes JSON into a {@link UsernamePasswordAuthenticationToken} object. + * Extracts the principal, credentials, and authorities from the JSON. + * + * @param p the {@link JsonParser} used to parse the JSON + * @param ctxt the {@link DeserializationContext} in which the deserialization occurs + * @return a {@link UsernamePasswordAuthenticationToken} object + * @throws IOException if an I/O error occurs + * @throws JsonProcessingException if a JSON processing error occurs + */ @Override public UsernamePasswordAuthenticationToken deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { diff --git a/productservice/src/main/java/com/springbootmicroservices/productservice/serializer/UsernamePasswordAuthenticationTokenMixin.java b/productservice/src/main/java/com/springbootmicroservices/productservice/serializer/UsernamePasswordAuthenticationTokenMixin.java index 6445ee5..aed39b0 100644 --- a/productservice/src/main/java/com/springbootmicroservices/productservice/serializer/UsernamePasswordAuthenticationTokenMixin.java +++ b/productservice/src/main/java/com/springbootmicroservices/productservice/serializer/UsernamePasswordAuthenticationTokenMixin.java @@ -3,9 +3,22 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +/** + * Mixin class for {@link UsernamePasswordAuthenticationToken} to use custom deserialization. + * This class is used to apply the custom {@link UsernamePasswordAuthenticationTokenDeserializer} + * for deserializing JSON into a {@link UsernamePasswordAuthenticationToken} object. + */ @JsonDeserialize(using = UsernamePasswordAuthenticationTokenDeserializer.class) public class UsernamePasswordAuthenticationTokenMixin extends UsernamePasswordAuthenticationToken { + + /** + * Constructs a {@link UsernamePasswordAuthenticationTokenMixin} with the given principal and credentials. + * + * @param principal the principal object (usually a {@link Jwt} or {@link UserDetails}) + * @param credentials the credentials (usually a password) + */ public UsernamePasswordAuthenticationTokenMixin(Object principal, Object credentials) { super(principal, credentials); } + } diff --git a/productservice/src/main/java/com/springbootmicroservices/productservice/utils/JwtRecordConverter.java b/productservice/src/main/java/com/springbootmicroservices/productservice/utils/JwtRecordConverter.java index ac1a7c9..6b8739b 100644 --- a/productservice/src/main/java/com/springbootmicroservices/productservice/utils/JwtRecordConverter.java +++ b/productservice/src/main/java/com/springbootmicroservices/productservice/utils/JwtRecordConverter.java @@ -4,9 +4,19 @@ import lombok.experimental.UtilityClass; import org.springframework.security.oauth2.jwt.Jwt; +/** + * Utility class for converting between {@link Jwt} and {@link JwtRecord} representations. + * Provides methods to convert a {@link Jwt} object to a {@link JwtRecord} and vice versa. + */ @UtilityClass public class JwtRecordConverter { + /** + * Converts a {@link Jwt} object into a {@link JwtRecord}. + * + * @param jwt the {@link Jwt} object to be converted + * @return a {@link JwtRecord} representing the provided {@link Jwt} object + */ public JwtRecord convertJwtToJwtRecord(Jwt jwt) { return new JwtRecord( jwt.getTokenValue(), @@ -20,6 +30,12 @@ public JwtRecord convertJwtToJwtRecord(Jwt jwt) { ); } + /** + * Converts a {@link JwtRecord} into a {@link Jwt} object. + * + * @param jwtRecord the {@link JwtRecord} to be converted + * @return a {@link Jwt} object representing the provided {@link JwtRecord} + */ public Jwt convertJwtRecordToJwt(JwtRecord jwtRecord) { return new Jwt( jwtRecord.tokenValue(), @@ -29,4 +45,5 @@ public Jwt convertJwtRecordToJwt(JwtRecord jwtRecord) { jwtRecord.claims() ); } + } diff --git a/productservice/src/main/java/com/springbootmicroservices/productservice/utils/KeyConverter.java b/productservice/src/main/java/com/springbootmicroservices/productservice/utils/KeyConverter.java index a488cb6..bd54d77 100644 --- a/productservice/src/main/java/com/springbootmicroservices/productservice/utils/KeyConverter.java +++ b/productservice/src/main/java/com/springbootmicroservices/productservice/utils/KeyConverter.java @@ -11,9 +11,20 @@ import java.security.PrivateKey; import java.security.PublicKey; +/** + * Utility class for converting PEM-encoded keys to {@link PublicKey} and {@link PrivateKey} objects. + * Provides methods to parse and convert PEM-encoded public and private key strings into their respective Java security key representations. + */ @UtilityClass public class KeyConverter { + /** + * Converts a PEM-encoded public key string to a {@link PublicKey} object. + * + * @param publicPemKey the PEM-encoded public key string + * @return the corresponding {@link PublicKey} object + * @throws RuntimeException if an error occurs while reading or converting the key + */ public PublicKey convertPublicKey(final String publicPemKey) { final StringReader keyReader = new StringReader(publicPemKey); @@ -27,6 +38,13 @@ public PublicKey convertPublicKey(final String publicPemKey) { } + /** + * Converts a PEM-encoded private key string to a {@link PrivateKey} object. + * + * @param privatePemKey the PEM-encoded private key string + * @return the corresponding {@link PrivateKey} object + * @throws RuntimeException if an error occurs while reading or converting the key + */ public PrivateKey convertPrivateKey(final String privatePemKey) { StringReader keyReader = new StringReader(privatePemKey);