diff --git a/src/main/java/io/mosip/mimoto/MimotoServiceApplication.java b/src/main/java/io/mosip/mimoto/MimotoServiceApplication.java index 68d5a946..d01d25a2 100644 --- a/src/main/java/io/mosip/mimoto/MimotoServiceApplication.java +++ b/src/main/java/io/mosip/mimoto/MimotoServiceApplication.java @@ -6,6 +6,7 @@ import io.mosip.kernel.cbeffutil.impl.CbeffImpl; import io.mosip.kernel.core.logger.spi.Logger; import io.mosip.mimoto.util.LoggerUtil; +import lombok.extern.slf4j.Slf4j; import org.json.simple.JSONObject; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -30,12 +31,11 @@ HibernateJpaAutoConfiguration.class, CacheAutoConfiguration.class }) +@Slf4j @EnableScheduling @EnableAsync public class MimotoServiceApplication { - private static Logger logger = LoggerUtil.getLogger(MimotoServiceApplication.class); - @Bean @Primary public CbeffUtil getCbeffUtil() { @@ -57,14 +57,14 @@ public static JSONObject getGitProp() { JSONObject.class ); } catch (Exception e) { - logger.error("Error when trying to read build.json file: " + e); + log.error("Error when trying to read build.json file: " + e); } return new JSONObject(); } public static void main(String[] args) { JSONObject gitProp = getGitProp(); - logger.info( + log.info( String.format( "Mimoto Service version: %s - revision: %s @ branch: %s | build @ %s", gitProp.get("git.build.version"), diff --git a/src/main/java/io/mosip/mimoto/config/Config.java b/src/main/java/io/mosip/mimoto/config/Config.java index ec4fa0f8..9b83c183 100644 --- a/src/main/java/io/mosip/mimoto/config/Config.java +++ b/src/main/java/io/mosip/mimoto/config/Config.java @@ -11,9 +11,6 @@ import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; - -import io.mosip.kernel.core.logger.spi.Logger; -import io.mosip.mimoto.util.LoggerUtil; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer; import org.springframework.security.web.SecurityFilterChain; @@ -26,7 +23,6 @@ @EnableMethodSecurity @Order(1) public class Config { - private Logger logger = LoggerUtil.getLogger(Config.class); @Value("${mosipbox.public.url}") private String baseUrl; diff --git a/src/main/java/io/mosip/mimoto/config/IssuersValidationConfig.java b/src/main/java/io/mosip/mimoto/config/IssuersValidationConfig.java index 01b76cd7..dac6ae80 100644 --- a/src/main/java/io/mosip/mimoto/config/IssuersValidationConfig.java +++ b/src/main/java/io/mosip/mimoto/config/IssuersValidationConfig.java @@ -1,9 +1,9 @@ package io.mosip.mimoto.config; -import io.mosip.kernel.core.logger.spi.Logger; + import io.mosip.mimoto.dto.IssuersDTO; import io.mosip.mimoto.exception.ApiNotAccessibleException; import io.mosip.mimoto.service.IssuersService; -import io.mosip.mimoto.util.LoggerUtil; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; @@ -17,6 +17,7 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicReference; +@Slf4j @Component public class IssuersValidationConfig implements ApplicationRunner { @Autowired @@ -27,11 +28,9 @@ public class IssuersValidationConfig implements ApplicationRunner { private final String VALIDATION_ERROR_MSG = "\n\nValidation failed in Mimoto-issuers-config.json:"; - private final Logger logger = LoggerUtil.getLogger(IssuersValidationConfig.class); - @Override public void run(ApplicationArguments args) throws ApiNotAccessibleException, IOException { - logger.info("Validation for mimoto-issuers-config.json STARTED"); + log.info("Validation for mimoto-issuers-config.json STARTED"); IssuersDTO issuerDTOList = issuersService.getAllIssuersWithAllFields(); AtomicReference errors = new AtomicReference<>(); @@ -47,11 +46,11 @@ public void run(ApplicationArguments args) throws ApiNotAccessibleException, IOE String[] tokenEndpointArray = issuerDTO.getToken_endpoint().split("/"); Set currentIssuers = credentialIssuers.get(); if (!currentIssuers.add(credentialIssuer)) { - logger.error(VALIDATION_ERROR_MSG + "duplicate value found " + credentialIssuer); + log.error(VALIDATION_ERROR_MSG + "duplicate value found " + credentialIssuer); throw new RuntimeException(VALIDATION_ERROR_MSG); } if (!tokenEndpointArray[tokenEndpointArray.length - 1].equals(credentialIssuer)) { - logger.error(VALIDATION_ERROR_MSG + "TokenEndpoint does not match with the credential issuer " + credentialIssuer); + log.error(VALIDATION_ERROR_MSG + "TokenEndpoint does not match with the credential issuer " + credentialIssuer); throw new RuntimeException(VALIDATION_ERROR_MSG); } credentialIssuers.set(currentIssuers); @@ -64,10 +63,10 @@ public void run(ApplicationArguments args) throws ApiNotAccessibleException, IOE errors.get().getFieldErrors().forEach(error -> { fieldErrors.set(fieldErrors.get() + error.getField() + " " + error.getDefaultMessage() + "\n"); }); - logger.error(VALIDATION_ERROR_MSG + fieldErrors.get()); + log.error(VALIDATION_ERROR_MSG + fieldErrors.get()); throw new RuntimeException(VALIDATION_ERROR_MSG); } - logger.info("Validation for mimoto-issuers-config.json COMPLETED"); + log.info("Validation for mimoto-issuers-config.json COMPLETED"); } } diff --git a/src/main/java/io/mosip/mimoto/config/SwaggerConfig.java b/src/main/java/io/mosip/mimoto/config/SwaggerConfig.java index 9a7d6c82..c2dcf9fb 100644 --- a/src/main/java/io/mosip/mimoto/config/SwaggerConfig.java +++ b/src/main/java/io/mosip/mimoto/config/SwaggerConfig.java @@ -5,6 +5,7 @@ import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.info.License; import io.swagger.v3.oas.models.servers.Server; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springdoc.core.models.GroupedOpenApi; @@ -12,11 +13,10 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +@Slf4j @Configuration public class SwaggerConfig { - private static final Logger logger = LoggerFactory.getLogger(SwaggerConfig.class); - @Autowired private OpenApiProperties openApiProperties; @@ -35,7 +35,7 @@ public OpenAPI openApi() { openApiProperties.getService().getServers().forEach(server -> { api.addServersItem(new Server().description(server.getDescription()).url(server.getUrl())); }); - logger.info("swagger open api bean is ready"); + log.info("swagger open api bean is ready"); return api; } diff --git a/src/main/java/io/mosip/mimoto/constant/SwaggerExampleConstants.java b/src/main/java/io/mosip/mimoto/constant/SwaggerExampleConstants.java new file mode 100644 index 00000000..f22d378e --- /dev/null +++ b/src/main/java/io/mosip/mimoto/constant/SwaggerExampleConstants.java @@ -0,0 +1,35 @@ +package io.mosip.mimoto.constant; + +public class SwaggerExampleConstants { + + public static final String ALL_PROPERTIES_EXAMPLE = """ + { + "response": { + "modelDownloadMaxRetry": "10", + "audience": "ida-binding", + "datashare.host": "https://datashare-inji.collab.mosip.net", + "allowedInternalAuthType": "otp,bio-Finger,bio-Iris,bio-Face", + "openId4VCIDownloadVCTimeout": "30000", + "qr.code.height": "650", + "ovp.error.redirect.url.pattern": "%s?error=%s&error_description=%s", + "vcDownloadMaxRetry": "10", + "ovp.qrdata.pattern": "INJI_OVP://https://injiweb.collab.mosip.net/authorize?response_type=vp_token&resource=%s&presentation_definition=%s", + "minStorageRequiredForAuditEntry": "2", + "minStorageRequired": "2", + "vcDownloadPoolInterval": "6000", + "issuer": "residentapp", + "ovp.redirect.url.pattern": "%s#vp_token=%s&presentation_submission=%s", + "allowedAuthType": "demo,otp,bio-Finger,bio-Iris,bio-Face", + "allowedEkycAuthType": "demo,otp,bio-Finger,bio-Iris,bio-Face", + "warningDomainName": "https://api.collab.mosip.net", + "qr.code.width": "650", + "web.host": "https://injiweb.collab.mosip.net", + "web.redirect.url": "https://injiweb.collab.mosip.net/authorize", + "aboutInjiUrl": "https://docs.mosip.io/inji/inji-mobile-wallet/overview", + "qr.data.size.limit": "10000", + "faceSdkModelUrl": "https://api.collab.mosip.net/inji" + }, + "errors": [] + } + """; +} diff --git a/src/main/java/io/mosip/mimoto/constant/SwaggerLiteralConstants.java b/src/main/java/io/mosip/mimoto/constant/SwaggerLiteralConstants.java new file mode 100644 index 00000000..66ed97de --- /dev/null +++ b/src/main/java/io/mosip/mimoto/constant/SwaggerLiteralConstants.java @@ -0,0 +1,77 @@ +package io.mosip.mimoto.constant; + +public class SwaggerLiteralConstants { + + /* Attestation Controller */ + public static final String ATTESTATION_NAME = "Attestation" ; + public static final String ATTESTATION_DESCRIPTION = "All the Attestation Related Endpoints" ; + + + /* Common Inji Controller */ + public static final String COMMON_INJI_NAME = "Properties" ; + public static final String COMMON_INJI_DESCRIPTION = "All the Inji Wallet Properties Related Endpoints" ; + public static final String COMMON_INJI_GET_PROPERTIES_SUMMARY = "Retrieve All Inji Wallet Properties" ; + public static final String COMMON_INJI_GET_PROPERTIES_DESCRIPTION = "This endpoint allow you to retrieve all the Inji Wallet Properties" ; + + /* Credentials Controller */ + public static final String CREDENTIALS_NAME = "Credentials Download using OpenId4VCI" ; + public static final String CREDENTIALS_DESCRIPTION = "All the Credentials Related Endpoints" ; + public static final String CREDENTIALS_DOWNLOAD_VC_SUMMARY = "Download Credentials as PDF" ; + public static final String CREDENTIALS_DOWNLOAD_VC_DESCRIPTION = "This endpoint allow you to retrieve all the Inji Wallet Properties" ; + + /* Credentials Share Controller */ + public static final String CREDENTIALS_SHARE_NAME = "Credential Share" ; + public static final String CREDENTIALS_SHARE_DESCRIPTION = "All the Credential Download Endpoints" ; + public static final String CREDENTIALS_SHARE_HANDLE_SUBSCRIBED_EVENT_SUMMARY = "Notify through Web Sub Once Credential is downloaded" ; + public static final String CREDENTIALS_SHARE_HANDLE_SUBSCRIBED_EVENT_DESCRIPTION = "This endpoint allow Web Sub to callback once the credential is issued" ; + public static final String CREDENTIALS_SHARE_REQUEST_VC_SUMMARY = "request for credential issue" ; + public static final String CREDENTIALS_SHARE_REQUEST_VC_DESCRIPTION = "This endpoint allow you to request for credential issue" ; + public static final String CREDENTIALS_SHARE_REQUEST_VC_STATUS_SUMMARY = "polling for credential issue status" ; + public static final String CREDENTIALS_SHARE_REQUEST_VC_STATUS_DESCRIPTION = "This endpoint allow you to poll for credential issue status" ; + public static final String CREDENTIALS_SHARE_DOWNLOAD_VC_SUMMARY = "Download the credential using OTP Flow" ; + public static final String CREDENTIALS_SHARE_DOWNLOAD_VC_DESCRIPTION = "This endpoint allow you to download credential issued" ; + + /* IDP Controller */ + public static final String IDP_NAME = "Wallet Binding" ; + public static final String IDP_DESCRIPTION = "All the Authorization Related Endpoints" ; + public static final String IDP_BINDING_OTP_SUMMARY = "Invoke OTP Request for Wallet Binding" ; + public static final String IDP_BINDING_OTP_DESCRIPTION = "This endpoint allow you to invoke OTP for wallet binding" ; + public static final String IDP_WALLET_BINDING_SUMMARY = "Wallet Binding" ; + public static final String IDP_WALLET_BINDING_DESCRIPTION = "This endpoint allow you to perform the wallet binding" ; + public static final String IDP_GET_TOKEN_SUMMARY = "Retrieve AccessToken for OIDC Flow" ; + public static final String IDP_GET_TOKEN_DESCRIPTION = "This endpoint allow you to retrieve the access token in exchange for authorization Code" ; + + /* Issuers Controller */ + public static final String ISSUERS_NAME = "Issuers" ; + public static final String ISSUERS_DESCRIPTION = "All the Issuers Related Endpoints" ; + public static final String ISSUERS_GET_ISSUERS_SUMMARY = "Retrieve All Onboarded Issuers" ; + public static final String ISSUERS_GET_ISSUERS_DESCRIPTION = "This endpoint allow you to retrieve all the onboarded issuers" ; + public static final String ISSUERS_GET_SPECIFIC_ISSUER_SUMMARY = "Retrieve Specific Issuer's Config" ; + public static final String ISSUERS_GET_SPECIFIC_ISSUER_DESCRIPTION = "This endpoint allow you to retrieve the Complete configuration of the specific issuer" ; + public static final String ISSUERS_GET_ISSUER_WELLKNOWN_SUMMARY = "Retrieve Specific Issuer's Well known" ; + public static final String ISSUERS_GET_ISSUER_WELLKNOWN_DESCRIPTION = "This endpoint allow you to retrieve the well known of the specific issuer" ; + + /* Prensentation Controller */ + public static final String PRESENTATION_NAME = "Presentation" ; + public static final String PRESENTATION_DESCRIPTION = "All the Online Sharing Related Endpoints" ; + public static final String PRESENTATION_AUTHORIZE_SUMMARY = "Perform the Authorization" ; + public static final String PRESENTATION_AUTHORIZE_DESCRIPTION = "This endpoint allow you to redirect the token back to the caller post authorization" ; + + /* Resident Service Controller */ + public static final String RESIDENT_NAME = "Resident Service" ; + public static final String RESIDENT_DESCRIPTION = "All the Resident Service Related Endpoints" ; + public static final String RESIDENT_REQUEST_OTP_SUMMARY = "Request for OTP" ; + public static final String RESIDENT_REQUEST_OTP_DESCRIPTION = "This endpoint allow you to request OTP for credential Download" ; + public static final String RESIDENT_REQUEST_INDIVIDUALID_OTP_SUMMARY = "Request OTP for retrieving individual Id" ; + public static final String RESIDENT_REQUEST_INDIVIDUALID_OTP_DESCRIPTION = "This endpoint allow you to request OTP to download individual ID" ; + public static final String RESIDENT_GET_INDIVIDUALID_SUMMARY = "Retrieve Individual Id using AID" ; + public static final String RESIDENT_GET_INDIVIDUALID_DESCRIPTION = "This endpoint allow you to retrieve the Individual Id using AID" ; + + + /* Verifiers Controller */ + public static final String VERIFIERS_NAME = "Verifiers" ; + public static final String VERIFIERS_DESCRIPTION = "All the Verifiers Related Endpoints" ; + public static final String VERIFIERS_GET_VERIFIERS_SUMMARY = "Retrieve All Trusted Verifiers" ; + public static final String VERIFIERS_GET_VERIFIERS_DESCRIPTION = "This endpoint allow you to retrieve all the Trusted Verifiers" ; + +} diff --git a/src/main/java/io/mosip/mimoto/controller/AttestationServiceController.java b/src/main/java/io/mosip/mimoto/controller/AttestationServiceController.java index c7741b42..0209cf19 100644 --- a/src/main/java/io/mosip/mimoto/controller/AttestationServiceController.java +++ b/src/main/java/io/mosip/mimoto/controller/AttestationServiceController.java @@ -1,7 +1,15 @@ package io.mosip.mimoto.controller; +import io.mosip.kernel.core.logger.spi.Logger; +import io.mosip.mimoto.constant.SwaggerLiteralConstants; +import io.mosip.mimoto.dto.mimoto.AttestationStatement; +import io.mosip.mimoto.dto.mimoto.GenericResponseDTO; +import io.mosip.mimoto.util.AttestationOfflineVerify; +import io.mosip.mimoto.util.AttestationOnlineVerify; +import io.mosip.mimoto.util.LoggerUtil; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -10,19 +18,11 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import io.mosip.kernel.core.logger.spi.Logger; -import io.mosip.mimoto.dto.mimoto.AttestationStatement; -import io.mosip.mimoto.dto.mimoto.GenericResponseDTO; -import io.mosip.mimoto.util.AttestationOfflineVerify; -import io.mosip.mimoto.util.AttestationOnlineVerify; -import io.mosip.mimoto.util.LoggerUtil; - @RestController @RequestMapping(value = "/safetynet") +@Tag(name = SwaggerLiteralConstants.ATTESTATION_NAME, description = SwaggerLiteralConstants.ATTESTATION_DESCRIPTION) public class AttestationServiceController { - private final Logger logger = LoggerUtil.getLogger(AttestationServiceController.class); - @Autowired AttestationOfflineVerify attestationOfflineVerify; @@ -35,6 +35,7 @@ public class AttestationServiceController { * @param attestation * @return */ + @Operation(hidden = true) @PostMapping(path = "/offline/verify", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity processOffline(@RequestBody String attestation) { @@ -45,7 +46,7 @@ public ResponseEntity processOffline(@RequestBody String attestation) GenericResponseDTO responseDTO = new GenericResponseDTO(); responseDTO.setStatus("Error"); responseDTO.setMessage(e.getMessage()); - + return new ResponseEntity<>(responseDTO, HttpStatus.OK); } } @@ -56,6 +57,7 @@ public ResponseEntity processOffline(@RequestBody String attestation) * @param attestation * @return */ + @Operation(hidden = true) @PostMapping(path = "/online/verify", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity processOnline(@RequestBody String attestation) { @@ -66,7 +68,7 @@ public ResponseEntity processOnline(@RequestBody String attestation) GenericResponseDTO responseDTO = new GenericResponseDTO(); responseDTO.setStatus("Error"); responseDTO.setMessage(e.getMessage()); - + return new ResponseEntity<>(responseDTO, HttpStatus.OK); } } diff --git a/src/main/java/io/mosip/mimoto/controller/CommonInjiController.java b/src/main/java/io/mosip/mimoto/controller/CommonInjiController.java index 27331e71..4f211d89 100644 --- a/src/main/java/io/mosip/mimoto/controller/CommonInjiController.java +++ b/src/main/java/io/mosip/mimoto/controller/CommonInjiController.java @@ -1,27 +1,37 @@ package io.mosip.mimoto.controller; +import io.mosip.mimoto.constant.SwaggerExampleConstants; +import io.mosip.mimoto.constant.SwaggerLiteralConstants; import io.mosip.mimoto.core.http.ResponseWrapper; -import io.mosip.mimoto.util.DateUtils; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; + import java.util.Map; @RestController +@Tag(name = SwaggerLiteralConstants.COMMON_INJI_NAME, description = SwaggerLiteralConstants.COMMON_INJI_DESCRIPTION) public class CommonInjiController { @Autowired private Map injiConfig; + @Operation( summary = SwaggerLiteralConstants.COMMON_INJI_GET_PROPERTIES_SUMMARY, description = SwaggerLiteralConstants.COMMON_INJI_GET_PROPERTIES_DESCRIPTION) + @ApiResponses({@ApiResponse(responseCode = "200",content = { @Content(schema = @Schema(implementation = ResponseWrapper.class), + examples = @ExampleObject( value = SwaggerExampleConstants.ALL_PROPERTIES_EXAMPLE),mediaType = "application/json") } ) }) @GetMapping(value = "/allProperties", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity getAllProperties() { + public ResponseEntity>> getAllProperties() { ResponseWrapper> responseWrapper = new ResponseWrapper<>(); - responseWrapper.setId("mosip.inji.properties"); - responseWrapper.setVersion("v1"); - responseWrapper.setResponsetime(DateUtils.getRequestTimeString()); responseWrapper.setResponse(injiConfig); return ResponseEntity.status(HttpStatus.OK).body(responseWrapper); } diff --git a/src/main/java/io/mosip/mimoto/controller/CredentialShareController.java b/src/main/java/io/mosip/mimoto/controller/CredentialShareController.java index 7a8f032d..b5eb65bd 100644 --- a/src/main/java/io/mosip/mimoto/controller/CredentialShareController.java +++ b/src/main/java/io/mosip/mimoto/controller/CredentialShareController.java @@ -1,34 +1,11 @@ package io.mosip.mimoto.controller; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; - import com.fasterxml.jackson.databind.JsonNode; import com.google.gson.Gson; - import io.mosip.kernel.core.util.JsonUtils; -import io.mosip.mimoto.util.*; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.core.env.Environment; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import io.mosip.kernel.core.logger.spi.Logger; import io.mosip.kernel.websub.api.annotation.PreAuthenticateContentAndVerifyIntent; import io.mosip.mimoto.constant.ApiName; +import io.mosip.mimoto.constant.SwaggerLiteralConstants; import io.mosip.mimoto.core.http.RequestWrapper; import io.mosip.mimoto.core.http.ResponseWrapper; import io.mosip.mimoto.dto.mimoto.AppCredentialRequestDTO; @@ -41,15 +18,33 @@ import io.mosip.mimoto.model.EventModel; import io.mosip.mimoto.service.RestClientService; import io.mosip.mimoto.service.impl.CredentialShareServiceImpl; +import io.mosip.mimoto.util.*; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; import javax.validation.Valid; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; @RestController @RequestMapping(value = "/credentialshare") +@Slf4j +@Tag(name = SwaggerLiteralConstants.CREDENTIALS_SHARE_NAME, description = SwaggerLiteralConstants.CREDENTIALS_SHARE_DESCRIPTION) public class CredentialShareController { - private Logger logger = LoggerUtil.getLogger(CredentialShareController.class); - @Autowired private CredentialShareServiceImpl credentialShareService; @@ -88,10 +83,11 @@ public class CredentialShareController { */ @PostMapping(path = "/callback/notify", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @PreAuthenticateContentAndVerifyIntent(secret = "${mosip.event.secret}", callback = "/v1/mimoto/credentialshare/callback/notify", topic = "${mosip.event.topic}") + @Operation(summary = SwaggerLiteralConstants.CREDENTIALS_SHARE_HANDLE_SUBSCRIBED_EVENT_SUMMARY, description = SwaggerLiteralConstants.CREDENTIALS_SHARE_HANDLE_SUBSCRIBED_EVENT_DESCRIPTION) public ResponseEntity handleSubscribeEvent(@RequestBody EventModel eventModel) throws Exception { - logger.info("Received websub event:: transaction id = " + eventModel.getEvent().getTransactionId()); - logger.debug("Received websub event:: " + JsonUtils.javaObjectToJsonString(eventModel)); + log.info("Received websub event:: transaction id = " + eventModel.getEvent().getTransactionId()); + log.debug("Received websub event:: " + JsonUtils.javaObjectToJsonString(eventModel)); GenericResponseDTO responseDTO = new GenericResponseDTO(); Path vcRequestIdPath = Path.of( utilities.getDataPath(), @@ -100,13 +96,13 @@ public ResponseEntity handleSubscribeEvent(@RequestBody Even // Only process event if request id file exists in the storange. if (vcRequestIdPath.toFile().exists()) { boolean documentGenerated = credentialShareService.generateDocuments(eventModel); - logger.info("Credential share process status: {} for event id: {}", documentGenerated, eventModel.getEvent().getId()); + log.info("Credential share process status: {} for event id: {}", documentGenerated, eventModel.getEvent().getId()); } else { - logger.warn("Event transaction id could not found in the storage, skipping..."); + log.warn("Event transaction id could not found in the storage, skipping..."); } responseDTO.setStatus("OK"); responseDTO.setMessage("Successfully issued."); - return new ResponseEntity<>(responseDTO, HttpStatus.OK); + return new ResponseEntity(responseDTO, HttpStatus.OK); } /** @@ -117,11 +113,12 @@ public ResponseEntity handleSubscribeEvent(@RequestBody Even * @throws Exception */ @PostMapping(path = "/request", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity request(@RequestBody AppCredentialRequestDTO requestDTO) + @Operation(summary = SwaggerLiteralConstants.CREDENTIALS_SHARE_REQUEST_VC_SUMMARY, description = SwaggerLiteralConstants.CREDENTIALS_SHARE_REQUEST_VC_DESCRIPTION) + public ResponseEntity request(@RequestBody AppCredentialRequestDTO requestDTO) throws Exception { if (StringUtils.isEmpty(requestDTO.getIndividualId())) { - logger.error("Received empty individual id for transaction id - " + requestDTO.getTransactionID()); + log.error("Received empty individual id for transaction id - " + requestDTO.getTransactionID()); } // Call mosip resident service to issue a new credential @@ -165,8 +162,9 @@ public ResponseEntity request(@RequestBody AppCredentialRequestDTO reque * @throws Exception */ @GetMapping(path = "/request/status/{requestId}", produces = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = SwaggerLiteralConstants.CREDENTIALS_SHARE_REQUEST_VC_STATUS_SUMMARY, description = SwaggerLiteralConstants.CREDENTIALS_SHARE_REQUEST_VC_STATUS_DESCRIPTION) @SuppressWarnings("unchecked") - public ResponseEntity requestStatus(@PathVariable("requestId") String requestId) + public ResponseEntity> requestStatus(@PathVariable("requestId") String requestId) throws Exception { List pathSegment = new ArrayList(); @@ -187,6 +185,7 @@ public ResponseEntity requestStatus(@PathVariable("requestId") String re * @throws Exception */ @PostMapping(path = "/download", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = SwaggerLiteralConstants.CREDENTIALS_SHARE_DOWNLOAD_VC_SUMMARY, description = SwaggerLiteralConstants.CREDENTIALS_SHARE_DOWNLOAD_VC_DESCRIPTION) public ResponseEntity download(@Valid @RequestBody CredentialDownloadRequestDTO requestDTO, BindingResult result) throws Exception { try { diff --git a/src/main/java/io/mosip/mimoto/controller/CredentialsController.java b/src/main/java/io/mosip/mimoto/controller/CredentialsController.java index f569f1fc..728a37e3 100644 --- a/src/main/java/io/mosip/mimoto/controller/CredentialsController.java +++ b/src/main/java/io/mosip/mimoto/controller/CredentialsController.java @@ -1,15 +1,20 @@ package io.mosip.mimoto.controller; -import com.fasterxml.jackson.core.JsonProcessingException; +import io.mosip.mimoto.constant.SwaggerLiteralConstants; import io.mosip.mimoto.core.http.ResponseWrapper; import io.mosip.mimoto.dto.ErrorDTO; import io.mosip.mimoto.dto.idp.TokenResponseDTO; -import io.mosip.mimoto.dto.mimoto.VCCredentialResponse; import io.mosip.mimoto.exception.ApiNotAccessibleException; import io.mosip.mimoto.exception.InvalidCredentialResourceException; import io.mosip.mimoto.exception.VCVerificationException; import io.mosip.mimoto.service.CredentialService; -import io.mosip.mimoto.util.DateUtils; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -18,44 +23,44 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.List; import java.util.Map; -import static io.mosip.mimoto.exception.PlatformErrorMessages.*; +import static io.mosip.mimoto.exception.PlatformErrorMessages.API_NOT_ACCESSIBLE_EXCEPTION; +import static io.mosip.mimoto.exception.PlatformErrorMessages.MIMOTO_PDF_SIGN_EXCEPTION; @RestController @RequestMapping(value="/credentials") +@Slf4j +@Tag( name = SwaggerLiteralConstants.CREDENTIALS_NAME, description = SwaggerLiteralConstants.CREDENTIALS_DESCRIPTION) public class CredentialsController { - private static final String ID = "mosip.mimoto.credentials"; - private final Logger logger = LoggerFactory.getLogger(CredentialsController.class); - - @Autowired CredentialService credentialService; - + @Operation( summary = SwaggerLiteralConstants.CREDENTIALS_DOWNLOAD_VC_SUMMARY, description = SwaggerLiteralConstants.CREDENTIALS_DOWNLOAD_VC_DESCRIPTION) + @ApiResponses({ + @ApiResponse(responseCode = "200", content = { @Content(mediaType = "application/pdf") }), + @ApiResponse(responseCode = "400",content = { @Content(schema = @Schema(implementation = ResponseWrapper.class), mediaType = "application/json") }) }) @PostMapping("/download") - public ResponseEntity downloadCredentialAsPDF( - @RequestParam Map params) { - + public ResponseEntity downloadCredentialAsPDF(@RequestParam Map params ) { ResponseWrapper responseWrapper = new ResponseWrapper<>(); - responseWrapper.setId(ID); - responseWrapper.setVersion("v1"); - responseWrapper.setResponsetime(DateUtils.getRequestTimeString()); try { String issuerId = params.get("issuer"); String credentialType = params.get("credential"); - logger.info("Initiated Token Call"); + log.info("Initiated Token Call"); TokenResponseDTO response = credentialService.getTokenResponse(params, issuerId); - logger.info("Initiated Download Credential Call"); + log.info("Initiated Download Credential Call"); ByteArrayInputStream inputStream = credentialService.downloadCredentialAsPDF(issuerId, credentialType, response); return ResponseEntity @@ -64,19 +69,19 @@ public ResponseEntity downloadCredentialAsPDF( .header(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, "Content-Disposition") .body(new InputStreamResource(inputStream)); } catch (ApiNotAccessibleException | IOException exception) { - logger.error("Exception occurred while fetching credential types ", exception); + log.error("Exception occurred while fetching credential types ", exception); responseWrapper.setErrors(List.of(new ErrorDTO(API_NOT_ACCESSIBLE_EXCEPTION.getCode(), API_NOT_ACCESSIBLE_EXCEPTION.getMessage()))); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(responseWrapper); } catch (InvalidCredentialResourceException invalidCredentialResourceException) { - logger.error("Exception occurred while pushing the data to data share ", invalidCredentialResourceException); + log.error("Exception occurred while pushing the data to data share ", invalidCredentialResourceException); responseWrapper.setErrors(List.of(new ErrorDTO(invalidCredentialResourceException.getErrorCode(), invalidCredentialResourceException.getMessage()))); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(responseWrapper); } catch (VCVerificationException exception) { - logger.error("Exception occurred while verification of the verifiable Credential", exception); + log.error("Exception occurred while verification of the verifiable Credential", exception); responseWrapper.setErrors(List.of(new ErrorDTO(exception.getErrorCode(), exception.getMessage()))); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(responseWrapper); } catch (Exception exception) { - logger.error("Exception occurred while generating pdf ", exception); + log.error("Exception occurred while generating pdf ", exception); responseWrapper.setErrors(List.of(new ErrorDTO(MIMOTO_PDF_SIGN_EXCEPTION.getCode(), exception.getMessage()))); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseWrapper); } diff --git a/src/main/java/io/mosip/mimoto/controller/IdpController.java b/src/main/java/io/mosip/mimoto/controller/IdpController.java index 79c3fca8..0877815f 100644 --- a/src/main/java/io/mosip/mimoto/controller/IdpController.java +++ b/src/main/java/io/mosip/mimoto/controller/IdpController.java @@ -1,9 +1,9 @@ package io.mosip.mimoto.controller; -import com.google.common.collect.Lists; import io.mosip.kernel.core.logger.spi.Logger; import io.mosip.kernel.core.util.JsonUtils; import io.mosip.mimoto.constant.ApiName; +import io.mosip.mimoto.constant.SwaggerLiteralConstants; import io.mosip.mimoto.core.http.ResponseWrapper; import io.mosip.mimoto.dto.ErrorDTO; import io.mosip.mimoto.dto.IssuerDTO; @@ -14,9 +14,22 @@ import io.mosip.mimoto.service.IdpService; import io.mosip.mimoto.service.IssuersService; import io.mosip.mimoto.service.RestClientService; -import io.mosip.mimoto.util.*; +import io.mosip.mimoto.util.JoseUtil; +import io.mosip.mimoto.util.LoggerUtil; +import io.mosip.mimoto.util.RequestValidator; +import io.mosip.mimoto.util.Utilities; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.*; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.util.MultiValueMap; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; @@ -26,14 +39,11 @@ import java.util.List; import java.util.Map; -import static io.mosip.mimoto.util.Utilities.handleExceptionWithErrorCode; - @RestController +@Slf4j +@Tag(name = SwaggerLiteralConstants.IDP_NAME, description = SwaggerLiteralConstants.IDP_DESCRIPTION) public class IdpController { - - private final Logger logger = LoggerUtil.getLogger(IdpController.class); private static final boolean USE_BEARER_TOKEN = true; - private static final String ID = "mosip.mimoto.idp"; @Autowired private RestClientService restClientService; @@ -49,37 +59,38 @@ public class IdpController { @Autowired RequestValidator requestValidator; + + @Operation(summary = SwaggerLiteralConstants.IDP_BINDING_OTP_SUMMARY, description = SwaggerLiteralConstants.IDP_BINDING_OTP_DESCRIPTION) @PostMapping(value = "/binding-otp", produces = MediaType.APPLICATION_JSON_VALUE) @SuppressWarnings("unchecked") - public ResponseEntity otpRequest(@Valid @RequestBody BindingOtpRequestDto requestDTO, BindingResult result) throws Exception { - logger.debug("Received binding-otp request : " + JsonUtils.javaObjectToJsonString(requestDTO)); + public ResponseEntity> otpRequest(@Valid @RequestBody BindingOtpRequestDto requestDTO, BindingResult result) throws Exception { + log.debug("Received binding-otp request : " + JsonUtils.javaObjectToJsonString(requestDTO)); requestValidator.validateInputRequest(result); requestValidator.validateNotificationChannel(requestDTO.getRequest().getOtpChannels()); - + ResponseWrapper response = new ResponseWrapper<>(); try { - ResponseWrapper response = null; - response = (ResponseWrapper) restClientService - .postApi(ApiName.BINDING_OTP, - requestDTO, ResponseWrapper.class, USE_BEARER_TOKEN); + response = (ResponseWrapper) restClientService.postApi(ApiName.BINDING_OTP, requestDTO, ResponseWrapper.class, USE_BEARER_TOKEN); if (response == null) throw new IdpException(); - return ResponseEntity.status(HttpStatus.OK).body(response); } catch (Exception e) { - logger.error("Wallet binding otp error occurred.", e); - ResponseWrapper response = getErrorResponse(PlatformErrorMessages.MIMOTO_OTP_BINDING_EXCEPTION.getCode(), e.getMessage()); + log.error("Wallet binding otp error occurred.", e); + List errors = Utilities.getErrors(PlatformErrorMessages.MIMOTO_OTP_BINDING_EXCEPTION.getCode(), e.getMessage()); + response.setResponse(null); + response.setErrors(errors); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response); } } + @Operation(summary = SwaggerLiteralConstants.IDP_WALLET_BINDING_SUMMARY, description = SwaggerLiteralConstants.IDP_WALLET_BINDING_DESCRIPTION) @PostMapping(path = "/wallet-binding", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity request(@RequestBody WalletBindingRequestDTO requestDTO) + public ResponseEntity> request(@RequestBody WalletBindingRequestDTO requestDTO) throws Exception { - logger.debug("Received wallet-binding request : " + JsonUtils.javaObjectToJsonString(requestDTO)); + log.debug("Received wallet-binding request : " + JsonUtils.javaObjectToJsonString(requestDTO)); + ResponseWrapper responseWrapper = new ResponseWrapper(); try { - ResponseWrapper response = null; WalletBindingInnerRequestDto innerRequestDto = new WalletBindingInnerRequestDto(); innerRequestDto.setChallengeList(requestDTO.getRequest().getChallengeList()); innerRequestDto.setIndividualId(requestDTO.getRequest().getIndividualId()); @@ -96,45 +107,38 @@ public ResponseEntity request(@RequestBody WalletBindingRequestDTO reque if (internalResponse == null) throw new IdpException(); - response = joseUtil.addThumbprintAndKeyId(internalResponse); - return ResponseEntity.status(HttpStatus.OK).body(response); + responseWrapper = joseUtil.addThumbprintAndKeyId(internalResponse); + return ResponseEntity.status(HttpStatus.OK).body(responseWrapper); } catch (Exception e) { - logger.error("Wallet binding error occured for tranaction id " + requestDTO.getRequest().getIndividualId(), e); - ResponseWrapper response = getErrorResponse(PlatformErrorMessages.MIMOTO_WALLET_BINDING_EXCEPTION.getCode(), e.getMessage()); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response); + log.error("Wallet binding error occured for tranaction id " + requestDTO.getRequest().getIndividualId(), e); + String[] errorObj = Utilities.handleExceptionWithErrorCode(e); + List errors = Utilities.getErrors(errorObj[0], errorObj[1]); + responseWrapper.setResponse(null); + responseWrapper.setErrors(errors); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(responseWrapper); } } + @Operation(summary = SwaggerLiteralConstants.IDP_GET_TOKEN_SUMMARY, description = SwaggerLiteralConstants.IDP_GET_TOKEN_DESCRIPTION) + @ApiResponses({ + @ApiResponse(responseCode = "200", content = { @Content(schema = @Schema(implementation = TokenResponseDTO.class), mediaType = "application/json") }), + @ApiResponse(responseCode = "400", content = { @Content(schema = @Schema(implementation = ResponseWrapper.class), mediaType = "application/json") }) }) @PostMapping(value = {"/get-token/{issuer}"}, consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE}, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity getToken(@RequestParam Map params, @PathVariable(required = true, name= "issuer") String issuer) { - - logger.info("Reached the getToken Controller for Issuer " + issuer); + public ResponseEntity getToken(@RequestParam Map params, @PathVariable(required = true, name= "issuer") String issuer) { + log.info("Reached the getToken Controller for Issuer " + issuer); + ResponseWrapper responseWrapper = new ResponseWrapper<>(); try { IssuerDTO issuerDTO = issuersService.getIssuerConfig(issuer); HttpEntity> request = idpService.constructGetTokenRequest(params, issuerDTO); TokenResponseDTO response = new RestTemplate().postForObject(idpService.getTokenEndpoint(issuerDTO), request, TokenResponseDTO.class); return ResponseEntity.status(HttpStatus.OK).body(response); } catch (Exception ex){ - logger.error("Exception Occurred while Invoking the Token Endpoint : ", ex); - ResponseWrapper response = handleExceptionWithErrorCode(ex); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response); + log.error("Exception Occurred while Invoking the Token Endpoint : ", ex); + String[] errorObj = Utilities.handleExceptionWithErrorCode(ex); + List errors = Utilities.getErrors(errorObj[0], errorObj[1]); + responseWrapper.setResponse(null); + responseWrapper.setErrors(errors); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(responseWrapper); } } - - public static ResponseWrapper getErrorResponse(String errorCode, String errorMessage) { - - List errors = getErrors(errorCode, errorMessage); - ResponseWrapper responseWrapper = new ResponseWrapper<>(); - responseWrapper.setResponse(null); - responseWrapper.setResponsetime(DateUtils.getRequestTimeString()); - responseWrapper.setId(ID); - responseWrapper.setErrors(errors); - - return responseWrapper; - } - - public static List getErrors(String errorCode, String errorMessage) { - ErrorDTO errorDTO = new ErrorDTO(errorCode, errorMessage); - return Lists.newArrayList(errorDTO); - } } diff --git a/src/main/java/io/mosip/mimoto/controller/IssuersController.java b/src/main/java/io/mosip/mimoto/controller/IssuersController.java index 082e8302..d1bf9517 100644 --- a/src/main/java/io/mosip/mimoto/controller/IssuersController.java +++ b/src/main/java/io/mosip/mimoto/controller/IssuersController.java @@ -1,5 +1,6 @@ package io.mosip.mimoto.controller; +import io.mosip.mimoto.constant.SwaggerLiteralConstants; import io.mosip.mimoto.core.http.ResponseWrapper; import io.mosip.mimoto.dto.ErrorDTO; import io.mosip.mimoto.dto.IssuerDTO; @@ -7,9 +8,10 @@ import io.mosip.mimoto.dto.mimoto.CredentialIssuerWellKnownResponse; import io.mosip.mimoto.exception.ApiNotAccessibleException; import io.mosip.mimoto.service.IssuersService; -import io.mosip.mimoto.util.DateUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import io.mosip.mimoto.util.Utilities; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -21,28 +23,23 @@ import static io.mosip.mimoto.exception.PlatformErrorMessages.API_NOT_ACCESSIBLE_EXCEPTION; import static io.mosip.mimoto.exception.PlatformErrorMessages.INVALID_ISSUER_ID_EXCEPTION; -import static io.mosip.mimoto.util.Utilities.handleExceptionWithErrorCode; @RestController +@Slf4j @RequestMapping(value = "/issuers") +@Tag(name = SwaggerLiteralConstants.ISSUERS_NAME, description = SwaggerLiteralConstants.ISSUERS_DESCRIPTION) public class IssuersController { @Autowired IssuersService issuersService; - private static final String ID = "mosip.mimoto.issuers"; - - private final Logger logger = LoggerFactory.getLogger(IssuersController.class); - + @Operation(summary = SwaggerLiteralConstants.ISSUERS_GET_ISSUERS_SUMMARY, description = SwaggerLiteralConstants.ISSUERS_GET_ISSUERS_DESCRIPTION) @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity getAllIssuers(@RequestParam(required = false, name = "search") String search) { + public ResponseEntity> getAllIssuers(@RequestParam(required = false, name = "search") String search) { ResponseWrapper responseWrapper = new ResponseWrapper<>(); - responseWrapper.setId(ID); - responseWrapper.setVersion("v1"); - responseWrapper.setResponsetime(DateUtils.getRequestTimeString()); try { responseWrapper.setResponse(issuersService.getAllIssuers(search)); } catch (ApiNotAccessibleException | IOException e) { - logger.error("Exception occurred while fetching issuers ", e); + log.error("Exception occurred while fetching issuers ", e); responseWrapper.setErrors(List.of(new ErrorDTO(API_NOT_ACCESSIBLE_EXCEPTION.getCode(), API_NOT_ACCESSIBLE_EXCEPTION.getMessage()))); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(responseWrapper); } @@ -50,37 +47,36 @@ public ResponseEntity getAllIssuers(@RequestParam(required = false, name return ResponseEntity.status(HttpStatus.OK).body(responseWrapper); } + @Operation(summary = SwaggerLiteralConstants.ISSUERS_GET_ISSUER_WELLKNOWN_SUMMARY, description = SwaggerLiteralConstants.ISSUERS_GET_ISSUER_WELLKNOWN_DESCRIPTION) @GetMapping(value = "/{issuer-id}/well-known-proxy", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity getIssuerWellknown(@PathVariable("issuer-id") String issuerId) { + public ResponseEntity getIssuerWellknown(@PathVariable("issuer-id") String issuerId) { try { CredentialIssuerWellKnownResponse credentialIssuerWellKnownResponse = issuersService.getIssuerWellknown(issuerId); return ResponseEntity.status(HttpStatus.OK).body(credentialIssuerWellKnownResponse); } catch (Exception exception) { - logger.error("Exception occurred while fetching issuers wellknown ", exception); + log.error("Exception occurred while fetching issuers wellknown ", exception); return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null); } } + @Operation(summary = SwaggerLiteralConstants.ISSUERS_GET_SPECIFIC_ISSUER_SUMMARY, description = SwaggerLiteralConstants.ISSUERS_GET_SPECIFIC_ISSUER_DESCRIPTION) @GetMapping(value = "/{issuer-id}", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity getIssuerConfig(@PathVariable("issuer-id") String issuerId) { - ResponseWrapper responseWrapper = new ResponseWrapper<>(); - responseWrapper.setId(ID); - responseWrapper.setVersion("v1"); - responseWrapper.setResponsetime(DateUtils.getRequestTimeString()); - + public ResponseEntity> getIssuerConfig(@PathVariable("issuer-id") String issuerId) { + ResponseWrapper responseWrapper = new ResponseWrapper<>(); IssuerDTO issuerConfig; try { issuerConfig = issuersService.getIssuerConfig(issuerId); } catch (Exception exception) { - logger.error("Exception occurred while fetching issuers ", exception); - responseWrapper = handleExceptionWithErrorCode(exception); + log.error("Exception occurred while fetching issuers ", exception); + String[] errorObj = Utilities.handleExceptionWithErrorCode(exception); + List errors = Utilities.getErrors(errorObj[0], errorObj[1]); + responseWrapper.setResponse(null); + responseWrapper.setErrors(errors); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(responseWrapper); } - responseWrapper.setResponse(issuerConfig); - if (issuerConfig == null) { - logger.error("invalid issuer id passed - {}", issuerId); + log.error("invalid issuer id passed - {}", issuerId); responseWrapper.setErrors(List.of(new ErrorDTO(INVALID_ISSUER_ID_EXCEPTION.getCode(), INVALID_ISSUER_ID_EXCEPTION.getMessage()))); return ResponseEntity.status(HttpStatus.NOT_FOUND).body(responseWrapper); } diff --git a/src/main/java/io/mosip/mimoto/controller/PresentationController.java b/src/main/java/io/mosip/mimoto/controller/PresentationController.java index 4d47a442..074eac0d 100644 --- a/src/main/java/io/mosip/mimoto/controller/PresentationController.java +++ b/src/main/java/io/mosip/mimoto/controller/PresentationController.java @@ -1,6 +1,7 @@ package io.mosip.mimoto.controller; import com.fasterxml.jackson.databind.ObjectMapper; +import io.mosip.mimoto.constant.SwaggerLiteralConstants; import io.mosip.mimoto.dto.openid.presentation.PresentationDefinitionDTO; import io.mosip.mimoto.dto.openid.presentation.PresentationRequestDTO; import io.mosip.mimoto.exception.ErrorConstants; @@ -9,7 +10,14 @@ import io.mosip.mimoto.exception.VPNotCreatedException; import io.mosip.mimoto.service.PresentationService; import io.mosip.mimoto.service.VerifierService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletResponse; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -24,11 +32,12 @@ import java.util.Arrays; @RestController +@Slf4j +@Tag(name = SwaggerLiteralConstants.PRESENTATION_NAME, description = SwaggerLiteralConstants.PRESENTATION_DESCRIPTION) public class PresentationController { @Autowired PresentationService presentationService; - private final Logger logger = LoggerFactory.getLogger(PresentationController.class); @Value("${mosip.inji.ovp.error.redirect.url.pattern}") String injiOvpErrorRedirectUrlPattern; @@ -42,15 +51,17 @@ public class PresentationController { @Autowired ObjectMapper objectMapper; + @Operation( summary = SwaggerLiteralConstants.PRESENTATION_AUTHORIZE_SUMMARY, description = SwaggerLiteralConstants.PRESENTATION_AUTHORIZE_DESCRIPTION) + @ApiResponses({ @ApiResponse(responseCode = "302", content = { @Content(mediaType = "application/text") }) }) @GetMapping("/authorize") public void performAuthorization(HttpServletResponse response, - @RequestParam("response_type") String responseType, - @RequestParam("resource") String resource, - @RequestParam("presentation_definition") String presentationDefinition, - @RequestParam("client_id") String clientId, - @RequestParam("redirect_uri") String redirectUri ) throws IOException { + @RequestParam("response_type") @Schema(description = "Response Type of the Presentation" , defaultValue = "vp_token") String responseType, + @RequestParam("resource") @Schema(description = "URL Encoded Resource url of the Credential ") String resource, + @RequestParam("presentation_definition") @Schema(description = "URL Encoded presentation definition") String presentationDefinition, + @RequestParam("client_id") @Schema(description = "URL Encoded Client Id") String clientId, + @RequestParam("redirect_uri") @Schema(description = "URL Encoded Redirect URI") String redirectUri ) throws IOException { try { - logger.info("Started Presentation Authorization in the controller."); + log.info("Started Presentation Authorization in the controller."); verifierService.validateVerifier(clientId, redirectUri); PresentationDefinitionDTO presentationDefinitionDTO = objectMapper.readValue(presentationDefinition, PresentationDefinitionDTO.class); PresentationRequestDTO presentationRequestDTO = PresentationRequestDTO.builder() @@ -60,7 +71,7 @@ public void performAuthorization(HttpServletResponse response, .clientId(clientId) .redirectUri(redirectUri).build(); String redirectString = presentationService.authorizePresentation(presentationRequestDTO); - logger.info("Completed Presentation Authorization in the controller."); + log.info("Completed Presentation Authorization in the controller."); response.sendRedirect(redirectString); } catch( InvalidVerifierException exception){ sendRedirect(response, injiWebRedirectUrl, exception.getErrorCode(), exception.getErrorText(), exception); @@ -72,7 +83,7 @@ public void performAuthorization(HttpServletResponse response, } private void sendRedirect(HttpServletResponse response, String domain, String code, String message, Exception exception) throws IOException { - logger.error("Exception Occurred in Authorizing the presentation : \n\t code - " + code + "\n\t message - " + message + "\n\t Trace - " + Arrays.toString(exception.getStackTrace())); + log.error("Exception Occurred in Authorizing the presentation : \n\t code - " + code + "\n\t message - " + message + "\n\t Trace - " + Arrays.toString(exception.getStackTrace())); String injiVerifyRedirectString = String.format(injiOvpErrorRedirectUrlPattern, domain, code, diff --git a/src/main/java/io/mosip/mimoto/controller/ResidentServiceController.java b/src/main/java/io/mosip/mimoto/controller/ResidentServiceController.java index ff8fc462..e0502b08 100644 --- a/src/main/java/io/mosip/mimoto/controller/ResidentServiceController.java +++ b/src/main/java/io/mosip/mimoto/controller/ResidentServiceController.java @@ -1,8 +1,16 @@ package io.mosip.mimoto.controller; +import io.mosip.mimoto.constant.ApiName; +import io.mosip.mimoto.constant.SwaggerLiteralConstants; +import io.mosip.mimoto.core.http.RequestWrapper; +import io.mosip.mimoto.core.http.ResponseWrapper; import io.mosip.mimoto.dto.mimoto.*; import io.mosip.mimoto.dto.resident.*; +import io.mosip.mimoto.service.RestClientService; +import io.mosip.mimoto.util.DateUtils; import io.mosip.mimoto.util.RequestValidator; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.http.HttpStatus; @@ -13,21 +21,12 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; -import io.mosip.kernel.core.logger.spi.Logger; -import io.mosip.mimoto.constant.ApiName; -import io.mosip.mimoto.core.http.RequestWrapper; -import io.mosip.mimoto.core.http.ResponseWrapper; -import io.mosip.mimoto.service.RestClientService; -import io.mosip.mimoto.util.DateUtils; -import io.mosip.mimoto.util.LoggerUtil; - import javax.validation.Valid; @RestController +@Tag(name = SwaggerLiteralConstants.RESIDENT_NAME, description = SwaggerLiteralConstants.RESIDENT_DESCRIPTION) public class ResidentServiceController { - private final Logger logger = LoggerUtil.getLogger(ResidentServiceController.class); - @Autowired public RestClientService restClientService; @@ -45,8 +44,9 @@ public class ResidentServiceController { * @throws Exception */ @PostMapping("/req/otp") + @Operation(summary = SwaggerLiteralConstants.RESIDENT_REQUEST_OTP_SUMMARY, description = SwaggerLiteralConstants.RESIDENT_REQUEST_OTP_DESCRIPTION) @SuppressWarnings("unchecked") - public ResponseEntity otpRequest(@Valid @RequestBody AppOTPRequestDTO requestDTO, BindingResult result) throws Exception { + public ResponseEntity> otpRequest(@Valid @RequestBody AppOTPRequestDTO requestDTO, BindingResult result) throws Exception { requestValidator.validateInputRequest(result); requestValidator.validateNotificationChannel(requestDTO.getOtpChannel()); OTPRequestDTO mosipOTPRequestPayload = new OTPRequestDTO(); @@ -72,6 +72,7 @@ public ResponseEntity otpRequest(@Valid @RequestBody AppOTPRequestDTO re * @throws Exception */ @PostMapping("/vid") + @Operation(hidden = true) @SuppressWarnings("unchecked") public ResponseEntity vidGenerate(@RequestBody AppVIDGenerateRequestDTO requestDTO) throws Exception { VIDGenerateRequestDTO vidRequestDTO = new VIDGenerateRequestDTO(); @@ -100,6 +101,7 @@ public ResponseEntity vidGenerate(@RequestBody AppVIDGenerateRequestDTO * @throws Exception */ @PostMapping("/req/auth/lock") + @Operation(hidden = true) @SuppressWarnings("unchecked") public ResponseEntity authLock(@RequestBody AuthLockRequestDTO requestDTO) throws Exception { RequestWrapper mosipAuthLockRequestPayload = new RequestWrapper<>(); @@ -121,6 +123,7 @@ public ResponseEntity authLock(@RequestBody AuthLockRequestDTO requestDT * @throws Exception */ @PostMapping("/req/auth/unlock") + @Operation(hidden = true) @SuppressWarnings("unchecked") public ResponseEntity authUnlock(@RequestBody AuthUnlockRequestDTO requestDTO) throws Exception { RequestWrapper mosipAuthUnlockRequestPayload = new RequestWrapper<>(); @@ -136,8 +139,9 @@ public ResponseEntity authUnlock(@RequestBody AuthUnlockRequestDTO reque } @PostMapping("/req/individualId/otp") + @Operation(summary = SwaggerLiteralConstants.RESIDENT_REQUEST_INDIVIDUALID_OTP_SUMMARY, description = SwaggerLiteralConstants.RESIDENT_REQUEST_INDIVIDUALID_OTP_DESCRIPTION) @SuppressWarnings("unchecked") - public ResponseEntity individualIdOtpRequest(@RequestBody IndividualIdOtpRequestDTO requestDTO) throws Exception { + public ResponseEntity individualIdOtpRequest(@RequestBody IndividualIdOtpRequestDTO requestDTO) throws Exception { IndividualIdOTPRequestDTO mosipOTPRequestPayload = new IndividualIdOTPRequestDTO(); mosipOTPRequestPayload.setId("mosip.identity.otp.internal"); mosipOTPRequestPayload.setVersion("1.0"); @@ -153,8 +157,9 @@ public ResponseEntity individualIdOtpRequest(@RequestBody IndividualIdOt } @PostMapping("/aid/get-individual-id") + @Operation(summary = SwaggerLiteralConstants.RESIDENT_GET_INDIVIDUALID_SUMMARY, description = SwaggerLiteralConstants.RESIDENT_GET_INDIVIDUALID_DESCRIPTION) @SuppressWarnings("unchecked") - public ResponseEntity aidGetIndividualId(@RequestBody AidStatusRequestDTO requestDTO) throws Exception { + public ResponseEntity> aidGetIndividualId(@RequestBody AidStatusRequestDTO requestDTO) throws Exception { InternalAidStatusDTO req = new InternalAidStatusDTO(requestDTO.getAid(), requestDTO.getOtp(), requestDTO.getTransactionID()); RequestWrapper mosipAuthLockRequestPayload = new RequestWrapper<>(); mosipAuthLockRequestPayload.setId("mosip.resident.checkstatus"); diff --git a/src/main/java/io/mosip/mimoto/controller/VerifiersController.java b/src/main/java/io/mosip/mimoto/controller/VerifiersController.java index 2f8a0bec..7ff7d698 100644 --- a/src/main/java/io/mosip/mimoto/controller/VerifiersController.java +++ b/src/main/java/io/mosip/mimoto/controller/VerifiersController.java @@ -1,13 +1,14 @@ package io.mosip.mimoto.controller; +import io.mosip.mimoto.constant.SwaggerLiteralConstants; import io.mosip.mimoto.core.http.ResponseWrapper; import io.mosip.mimoto.dto.ErrorDTO; import io.mosip.mimoto.dto.openid.VerifiersDTO; import io.mosip.mimoto.exception.ApiNotAccessibleException; import io.mosip.mimoto.service.VerifierService; -import io.mosip.mimoto.util.DateUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -23,25 +24,21 @@ @RestController @RequestMapping(value = "/verifiers") +@Slf4j +@Tag(name = SwaggerLiteralConstants.VERIFIERS_NAME, description = SwaggerLiteralConstants.VERIFIERS_DESCRIPTION) public class VerifiersController { @Autowired VerifierService verifierService; - private static final String ID = "mosip.mimoto.verifier"; - - private final Logger logger = LoggerFactory.getLogger(VerifiersController.class); - + @Operation(summary = SwaggerLiteralConstants.VERIFIERS_GET_VERIFIERS_SUMMARY, description = SwaggerLiteralConstants.VERIFIERS_GET_VERIFIERS_DESCRIPTION) @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity getAllTrustedVerifiers() { + public ResponseEntity> getAllTrustedVerifiers() { ResponseWrapper responseWrapper = new ResponseWrapper<>(); - responseWrapper.setId(ID); - responseWrapper.setVersion("v1"); - responseWrapper.setResponsetime(DateUtils.getRequestTimeString()); try { responseWrapper.setResponse(verifierService.getTrustedVerifiers()); } catch (ApiNotAccessibleException | IOException e) { - logger.error("Exception occurred while fetching trusted verifiers ", e); + log.error("Exception occurred while fetching trusted verifiers ", e); responseWrapper.setErrors(List.of(new ErrorDTO(API_NOT_ACCESSIBLE_EXCEPTION.getCode(), API_NOT_ACCESSIBLE_EXCEPTION.getMessage()))); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(responseWrapper); } diff --git a/src/main/java/io/mosip/mimoto/core/http/ResponseWrapper.java b/src/main/java/io/mosip/mimoto/core/http/ResponseWrapper.java index 14b794e0..baff4a65 100644 --- a/src/main/java/io/mosip/mimoto/core/http/ResponseWrapper.java +++ b/src/main/java/io/mosip/mimoto/core/http/ResponseWrapper.java @@ -7,19 +7,11 @@ import javax.validation.constraints.NotNull; import io.mosip.mimoto.dto.ErrorDTO; -import lombok.Data; +import lombok.*; @Data +@NoArgsConstructor public class ResponseWrapper { - private String id; - private String version; - String str; - private String responsetime; - private Object metadata; - @NotNull - @Valid private T response; - private List errors = new ArrayList<>(); - } diff --git a/src/main/java/io/mosip/mimoto/dto/DisplayDTO.java b/src/main/java/io/mosip/mimoto/dto/DisplayDTO.java index 17dc858c..2689a0f1 100644 --- a/src/main/java/io/mosip/mimoto/dto/DisplayDTO.java +++ b/src/main/java/io/mosip/mimoto/dto/DisplayDTO.java @@ -1,6 +1,7 @@ package io.mosip.mimoto.dto; import com.google.gson.annotations.Expose; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import jakarta.validation.Valid; @@ -10,17 +11,22 @@ public class DisplayDTO { @Expose @NotBlank + @Schema(description = "Display Name of the Issuer") String name; @Expose @Valid + @Schema(description = "Display Logo of the Issuer") LogoDTO logo; @Expose @NotBlank + @Schema(description = "Display title of the Issuer") String title; @Expose @NotBlank + @Schema(description = "Display description of the Issuer") String description; @Expose @NotBlank + @Schema(description = "Display language of the Issuer") String language; } diff --git a/src/main/java/io/mosip/mimoto/dto/IssuerDTO.java b/src/main/java/io/mosip/mimoto/dto/IssuerDTO.java index 3aa1529a..b12749ec 100644 --- a/src/main/java/io/mosip/mimoto/dto/IssuerDTO.java +++ b/src/main/java/io/mosip/mimoto/dto/IssuerDTO.java @@ -5,6 +5,7 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; import io.mosip.mimoto.model.QRCodeType; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.Valid; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotEmpty; @@ -19,41 +20,52 @@ public class IssuerDTO { @Expose @NotBlank + @Schema(description = "Unique Identifier of the Issuer") String credential_issuer; @Expose @NotBlank + @Schema(description = "protocol of the download flow", allowableValues = {"OTP", "OpenId4VCI"}) String protocol; @Expose @Valid @NotEmpty + @Schema(description = "Display Properties of the Issuer") List display; @Expose @NotBlank + @Schema(description = "Client Id of the Onboarded Mimoto OIDC Client") String client_id; @NotBlank @Expose + @Schema(description = "Wellknown endpoint of the credential issuer") String wellknown_endpoint; @Expose @JsonInclude(NON_NULL) @NotBlank + @Schema(description = "Redirect URI configured while creating the OIDC Client") String redirect_uri; @JsonInclude(NON_NULL) @NotBlank + @Schema(description = "Authorization Audience for retrieving Token from token endpoint") String authorization_audience; @Expose @JsonInclude(NON_NULL) + @Schema(description = "Mimoto Token Endpoint Fetching the Token From Authorization Server with Client Assertion") String token_endpoint; @Expose @JsonInclude(NON_NULL) @NotBlank + @Schema(description = "Token Endpoint for Fetching the Token From Authorization Server") String proxy_token_endpoint; @Expose @JsonInclude(NON_NULL) @NotBlank + @Schema(description = "Client Alias of the Issuer in the keyStore file") String client_alias; QRCodeType qr_code_type; @Expose @JsonInclude(NON_NULL) @NotBlank + @Schema(description = "Toggler to Enable / Disable the Issuer", defaultValue = "false") String enabled; } diff --git a/src/main/java/io/mosip/mimoto/dto/IssuersDTO.java b/src/main/java/io/mosip/mimoto/dto/IssuersDTO.java index 5b7dcbe0..f7d5f837 100644 --- a/src/main/java/io/mosip/mimoto/dto/IssuersDTO.java +++ b/src/main/java/io/mosip/mimoto/dto/IssuersDTO.java @@ -1,6 +1,7 @@ package io.mosip.mimoto.dto; import com.google.gson.annotations.Expose; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import jakarta.validation.Valid; @@ -11,6 +12,7 @@ public class IssuersDTO { @Expose @Valid + @Schema(description = "List of Onboarded Issuers") List issuers; } diff --git a/src/main/java/io/mosip/mimoto/dto/LogoDTO.java b/src/main/java/io/mosip/mimoto/dto/LogoDTO.java index cce525a7..2793edf9 100644 --- a/src/main/java/io/mosip/mimoto/dto/LogoDTO.java +++ b/src/main/java/io/mosip/mimoto/dto/LogoDTO.java @@ -2,6 +2,7 @@ import com.google.gson.annotations.Expose; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import jakarta.validation.constraints.NotBlank; @@ -12,8 +13,10 @@ public class LogoDTO { @Expose @NotBlank @URL + @Schema(description = "Display logo uri of the Issuer") String url; @Expose @NotBlank + @Schema(description = "Display logo alt text of the Issuer") String alt_text; } diff --git a/src/main/java/io/mosip/mimoto/dto/mimoto/BindingOtpInnerReqDto.java b/src/main/java/io/mosip/mimoto/dto/mimoto/BindingOtpInnerReqDto.java index 828a49b1..45782442 100644 --- a/src/main/java/io/mosip/mimoto/dto/mimoto/BindingOtpInnerReqDto.java +++ b/src/main/java/io/mosip/mimoto/dto/mimoto/BindingOtpInnerReqDto.java @@ -1,5 +1,6 @@ package io.mosip.mimoto.dto.mimoto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import javax.validation.constraints.NotEmpty; @@ -8,9 +9,12 @@ @Data public class BindingOtpInnerReqDto { + @NotNull + @Schema(description = "Individual ID For Binding OTP") private String individualId; @NotNull @NotEmpty + @Schema(description = "Channel in which OTP is needed", allowableValues = {"PHONE", "EMAIL"}) private List otpChannels; } diff --git a/src/main/java/io/mosip/mimoto/dto/mimoto/BindingOtpRequestDto.java b/src/main/java/io/mosip/mimoto/dto/mimoto/BindingOtpRequestDto.java index f9a8bab6..c4629612 100644 --- a/src/main/java/io/mosip/mimoto/dto/mimoto/BindingOtpRequestDto.java +++ b/src/main/java/io/mosip/mimoto/dto/mimoto/BindingOtpRequestDto.java @@ -1,5 +1,6 @@ package io.mosip.mimoto.dto.mimoto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -11,9 +12,11 @@ @AllArgsConstructor @NoArgsConstructor public class BindingOtpRequestDto { + @Schema(description = "Request Time of the Binding OTP") private String requestTime; @Valid @NotNull + @Schema(description = "Binding OTP Request") private BindingOtpInnerReqDto request; } diff --git a/src/main/java/io/mosip/mimoto/dto/mimoto/BindingOtpResponseDto.java b/src/main/java/io/mosip/mimoto/dto/mimoto/BindingOtpResponseDto.java index a1f733c9..13c30dd4 100644 --- a/src/main/java/io/mosip/mimoto/dto/mimoto/BindingOtpResponseDto.java +++ b/src/main/java/io/mosip/mimoto/dto/mimoto/BindingOtpResponseDto.java @@ -1,10 +1,14 @@ package io.mosip.mimoto.dto.mimoto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @Data public class BindingOtpResponseDto { + @Schema(description = "Transaction Id of Binding OTP") private String transactionId; + @Schema(description = "Masked Email of Binding OTP") private String maskedEmail; + @Schema(description = "Masked Mobile Number of Binding OTP") private String maskedMobile; } diff --git a/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialDefinitionResponseDto.java b/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialDefinitionResponseDto.java index ac1bc541..4181e824 100644 --- a/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialDefinitionResponseDto.java +++ b/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialDefinitionResponseDto.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.gson.annotations.SerializedName; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.Valid; import jakarta.validation.constraints.NotEmpty; import lombok.Data; @@ -15,11 +16,13 @@ public class CredentialDefinitionResponseDto { @NotEmpty @SerializedName("type") @JsonProperty("type") + @Schema(description = "Type of the Credential Definition") private List<@NotEmpty String> type; @NotEmpty @Valid @SerializedName("credentialSubject") @JsonProperty("credentialSubject") + @Schema(description = "Credential Subject of the VC") private Map<@NotEmpty String, @Valid CredentialDisplayResponseDto> credentialSubject; } diff --git a/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialDisplayResponseDto.java b/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialDisplayResponseDto.java index eeec2af8..be330f46 100644 --- a/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialDisplayResponseDto.java +++ b/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialDisplayResponseDto.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.gson.annotations.SerializedName; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.Valid; import jakarta.validation.constraints.NotEmpty; import lombok.Data; @@ -15,5 +16,6 @@ public class CredentialDisplayResponseDto { @Valid @SerializedName("display") @JsonProperty("display") + @Schema(description = "Display Properties of the Credential Issuer") private List<@Valid CredentialIssuerDisplayResponse> display; } diff --git a/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialIssuerDisplayResponse.java b/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialIssuerDisplayResponse.java index 0fd6694d..cff8eb93 100644 --- a/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialIssuerDisplayResponse.java +++ b/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialIssuerDisplayResponse.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.gson.annotations.SerializedName; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; import lombok.Data; @@ -11,10 +12,12 @@ public class CredentialIssuerDisplayResponse { @NotBlank @SerializedName("name") @JsonProperty("name") + @Schema(description = "Name of the Credential Issuer") private String name; @NotBlank @SerializedName("locale") @JsonProperty("locale") + @Schema(description = "Locale of the Credential Issuer") private String locale; } diff --git a/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialIssuerWellKnownResponse.java b/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialIssuerWellKnownResponse.java index 17cb26ea..d4523c3c 100644 --- a/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialIssuerWellKnownResponse.java +++ b/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialIssuerWellKnownResponse.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.gson.annotations.SerializedName; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.Valid; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotEmpty; @@ -18,22 +19,26 @@ public class CredentialIssuerWellKnownResponse { @URL @SerializedName("credential_issuer") @JsonProperty("credential_issuer") + @Schema(description = "Unique Identifier of the Credential Issuer") private String credentialIssuer; @NotEmpty @SerializedName("authorization_servers") @JsonProperty("authorization_servers") + @Schema(description = "List of Authorization Server Endpoint") private List<@NotBlank @URL String> authorizationServers; @NotBlank @SerializedName("credential_endpoint") @Pattern(regexp = "https?://.*?/credential$") @JsonProperty("credential_endpoint") + @Schema(description = "Endpoint to download the Credential") private String credentialEndPoint; @NotEmpty @Valid @SerializedName("credential_configurations_supported") @JsonProperty("credential_configurations_supported") + @Schema(description = "List of Credential Configurations Supported") private Map<@NotBlank String, @Valid CredentialsSupportedResponse> credentialConfigurationsSupported; } diff --git a/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialSupportedDisplayResponse.java b/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialSupportedDisplayResponse.java index 53d2ea5e..97a08853 100644 --- a/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialSupportedDisplayResponse.java +++ b/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialSupportedDisplayResponse.java @@ -5,6 +5,7 @@ import com.google.gson.annotations.SerializedName; import io.mosip.mimoto.dto.BackgroundImageDTO; import io.mosip.mimoto.dto.LogoDTO; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; import lombok.Data; @@ -17,15 +18,18 @@ public class CredentialSupportedDisplayResponse { @Expose @NotBlank + @Schema(description = "Name of the Supported Credential") String name; @Expose @NotBlank + @Schema(description = "Locale of the Supported Credential") String locale; @Expose @NotNull @Valid + @Schema(description = "Logo of the Supported Credential") LogoDTO logo; @JsonProperty("background_image") @@ -33,17 +37,20 @@ public class CredentialSupportedDisplayResponse { @Expose @Valid @NotNull + @Schema(description = "Background Image of the Supported Credential") BackgroundImageDTO backgroundImage; @JsonProperty("background_color") @SerializedName("background_color") @Expose @NotBlank + @Schema(description = "Background Colour of the Supported Credential") String backgroundColor; @JsonProperty("text_color") @SerializedName("text_color") @Expose @NotBlank + @Schema(description = "Text Colour of the Supported Credential") String textColor; } diff --git a/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialsSupportedResponse.java b/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialsSupportedResponse.java index 26dee429..1422567f 100644 --- a/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialsSupportedResponse.java +++ b/src/main/java/io/mosip/mimoto/dto/mimoto/CredentialsSupportedResponse.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.gson.annotations.SerializedName; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.Valid; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotEmpty; @@ -17,33 +18,41 @@ public class CredentialsSupportedResponse { @NotBlank(message = "Format must not be blank") + @Schema(description = "Format of the Credential") private String format; @NotBlank(message = "Scope must not be blank") + @Schema(description = "Scope of the Credential") private String scope; @JsonInclude(NON_NULL) + @Schema(description = "document Type of the Credential") private String doctype; @NotEmpty(message = "Proof types supported must not be empty") @Valid @SerializedName("proof_types_supported") @JsonProperty("proof_types_supported") + @Schema(description = "List of proof types supported") private Map<@NotEmpty String, @Valid ProofTypesSupported> proofTypesSupported; @JsonInclude(NON_NULL) + @Schema(description = "List of Claims") private Map claims; @SerializedName("credential_definition") @JsonProperty("credential_definition") @JsonInclude(NON_NULL) + @Schema(description = "Credential Definition of the VC") private CredentialDefinitionResponseDto credentialDefinition; @NotEmpty(message = "Display information must not be empty") @Valid @SerializedName("display") @JsonProperty("display") + @Schema(description = "Display Properties of the Supported Credential") private List<@Valid CredentialSupportedDisplayResponse> display; + @Schema(description = "Order of the Credentials Subject Render") private List order; } diff --git a/src/main/java/io/mosip/mimoto/dto/mimoto/IdpChallangeDto.java b/src/main/java/io/mosip/mimoto/dto/mimoto/IdpChallangeDto.java index a1737c64..31b38274 100644 --- a/src/main/java/io/mosip/mimoto/dto/mimoto/IdpChallangeDto.java +++ b/src/main/java/io/mosip/mimoto/dto/mimoto/IdpChallangeDto.java @@ -1,10 +1,14 @@ package io.mosip.mimoto.dto.mimoto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @Data public class IdpChallangeDto { + @Schema(description = "Auth Factory type", allowableValues = {"OTP"}) private String authFactorType; + @Schema(description = "IDP Challenge") private String challenge; + @Schema(description = "IDP Format", allowableValues = {"jwt"}) private String format; } diff --git a/src/main/java/io/mosip/mimoto/dto/mimoto/ProofTypesSupported.java b/src/main/java/io/mosip/mimoto/dto/mimoto/ProofTypesSupported.java index cdd54087..faa6a460 100644 --- a/src/main/java/io/mosip/mimoto/dto/mimoto/ProofTypesSupported.java +++ b/src/main/java/io/mosip/mimoto/dto/mimoto/ProofTypesSupported.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.gson.annotations.SerializedName; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; import lombok.Data; @@ -15,5 +16,6 @@ public class ProofTypesSupported { @NotNull @JsonProperty("proof_signing_alg_values_supported") @SerializedName("proof_signing_alg_values_supported") + @Schema(description = "Support Alg for proof Signing") private List proofSigningAlgValuesSupported; } diff --git a/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingInnerReq.java b/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingInnerReq.java index 940b8ffb..e43998cb 100644 --- a/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingInnerReq.java +++ b/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingInnerReq.java @@ -1,14 +1,21 @@ package io.mosip.mimoto.dto.mimoto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.util.List; @Data public class WalletBindingInnerReq { + + @Schema(description = "Individual Id ") private String individualId; + @Schema(description = "List of Challenges") private List challengeList; + @Schema(description = "public key in JWK") private String publicKey; + @Schema(description = "Auth Factory type", allowableValues = {"WLA"}) private String authFactorType; + @Schema(description = "IDP format", allowableValues = {"jwt"}) private String format; } diff --git a/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingInnerRequestDto.java b/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingInnerRequestDto.java index 690447f7..a0bd3397 100644 --- a/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingInnerRequestDto.java +++ b/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingInnerRequestDto.java @@ -1,15 +1,21 @@ package io.mosip.mimoto.dto.mimoto; import com.nimbusds.jose.jwk.JWK; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.util.List; @Data public class WalletBindingInnerRequestDto { + @Schema(description = "Individual Id of the Wallet Binding") private String individualId; + @Schema(description = "Challenge List of the Wallet Binding") private List challengeList; + @Schema(description = "Public Key of the Wallet Binding in JWK") private JwkDto publicKey; + @Schema(description = "Auth Factor Type of the Wallet Binding") private String authFactorType; + @Schema(description = "Format of the Wallet Binding") private String format; } diff --git a/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingInternalRequestDTO.java b/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingInternalRequestDTO.java index 066ae184..3abcebfe 100644 --- a/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingInternalRequestDTO.java +++ b/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingInternalRequestDTO.java @@ -1,5 +1,6 @@ package io.mosip.mimoto.dto.mimoto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -8,7 +9,9 @@ @AllArgsConstructor @NoArgsConstructor public class WalletBindingInternalRequestDTO { + @Schema(description = "Request Time of the Wallet Binding") private String requestTime; + @Schema(description = "Body of the Request") private WalletBindingInnerRequestDto request; } diff --git a/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingInternalResponseDto.java b/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingInternalResponseDto.java index 5559b1f1..e008fb0e 100644 --- a/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingInternalResponseDto.java +++ b/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingInternalResponseDto.java @@ -1,10 +1,14 @@ package io.mosip.mimoto.dto.mimoto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @Data public class WalletBindingInternalResponseDto { + @Schema(description = "Certificate of the Wallet Binding") private String certificate; + @Schema(description = "Wallet User Id of the Wallet Binding") private String walletUserId; + @Schema(description = "Date Time Expiry of the Wallet Binding") private String expireDateTime; } diff --git a/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingRequestDTO.java b/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingRequestDTO.java index 9500a3f9..f74f52b1 100644 --- a/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingRequestDTO.java +++ b/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingRequestDTO.java @@ -1,10 +1,14 @@ package io.mosip.mimoto.dto.mimoto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @Data public class WalletBindingRequestDTO { + + @Schema(description = "Transaction Id of Binding OTP") private String requestTime; + @Schema(description = "Transaction Id of Binding OTP") private WalletBindingInnerReq request; } diff --git a/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingResponseDto.java b/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingResponseDto.java index fd6ad6a7..b1752ea6 100644 --- a/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingResponseDto.java +++ b/src/main/java/io/mosip/mimoto/dto/mimoto/WalletBindingResponseDto.java @@ -1,12 +1,18 @@ package io.mosip.mimoto.dto.mimoto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @Data public class WalletBindingResponseDto { + @Schema(description = "Certificate ID For Wallet Binding ") private String certificate; + @Schema(description = "Encrypted Wallet Binding ID Received in the Binding OTP") private String encryptedWalletBindingId; + @Schema(description = "Date Time of the Expiry") private String expireDateTime; + @Schema(description = "Thumbprint Received in the Binding OTP") private String thumbprint; + @Schema(description = "Key Id for Wallet Binding") private String keyId; } diff --git a/src/main/java/io/mosip/mimoto/dto/openid/VerifierDTO.java b/src/main/java/io/mosip/mimoto/dto/openid/VerifierDTO.java index 5ed8d1e7..3980902d 100644 --- a/src/main/java/io/mosip/mimoto/dto/openid/VerifierDTO.java +++ b/src/main/java/io/mosip/mimoto/dto/openid/VerifierDTO.java @@ -1,6 +1,7 @@ package io.mosip.mimoto.dto.openid; import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -14,11 +15,14 @@ @Builder public class VerifierDTO { @JsonProperty("client_id") + @Schema(description = "Client Id of the Verifier") String clientId; @JsonProperty("redirect_uris") + @Schema(description = "Redirect URIs of the Verifier") List redirectUris; @JsonProperty("response_uri") + @Schema(description = "Response URIs of the Verifier") List responseUri; } diff --git a/src/main/java/io/mosip/mimoto/dto/openid/VerifiersDTO.java b/src/main/java/io/mosip/mimoto/dto/openid/VerifiersDTO.java index 36657eb2..45f1b776 100644 --- a/src/main/java/io/mosip/mimoto/dto/openid/VerifiersDTO.java +++ b/src/main/java/io/mosip/mimoto/dto/openid/VerifiersDTO.java @@ -1,5 +1,6 @@ package io.mosip.mimoto.dto.openid; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -12,5 +13,6 @@ @AllArgsConstructor @Builder public class VerifiersDTO { + @Schema(description = "Trusted Verifiers List") List verifiers; } diff --git a/src/main/java/io/mosip/mimoto/dto/openid/datashare/DataShareResponseDTO.java b/src/main/java/io/mosip/mimoto/dto/openid/datashare/DataShareResponseDTO.java index 17662916..0b610ca1 100644 --- a/src/main/java/io/mosip/mimoto/dto/openid/datashare/DataShareResponseDTO.java +++ b/src/main/java/io/mosip/mimoto/dto/openid/datashare/DataShareResponseDTO.java @@ -1,5 +1,6 @@ package io.mosip.mimoto.dto.openid.datashare; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -10,9 +11,19 @@ @AllArgsConstructor @NoArgsConstructor public class DataShareResponseDTO { + + @Schema(description = "url of the data share") private String url; + + @Schema(description = "The valid for in minutes.") private int validForInMinutes; + + @Schema(description = "The transactions allowed") private int transactionsAllowed; + + @Schema(description = "Static policy id") private String policyId; + + @Schema(description = "Static subscriber id") private String subscriberId; } diff --git a/src/main/java/io/mosip/mimoto/exception/ExceptionUtils.java b/src/main/java/io/mosip/mimoto/exception/ExceptionUtils.java index a5933f00..eff36370 100644 --- a/src/main/java/io/mosip/mimoto/exception/ExceptionUtils.java +++ b/src/main/java/io/mosip/mimoto/exception/ExceptionUtils.java @@ -1,24 +1,21 @@ package io.mosip.mimoto.exception; +import lombok.extern.slf4j.Slf4j; + import java.io.PrintWriter; import java.io.StringWriter; -import com.fasterxml.jackson.databind.JsonNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * This utils contains exception utilities. - * + * * @author Shashank Agrawal * @author Ritesh Sinha * @since 1.0.0 * */ +@Slf4j public final class ExceptionUtils { - private static final Logger logger = LoggerFactory.getLogger(ExceptionUtils.class); - private ExceptionUtils() { } @@ -26,7 +23,7 @@ private ExceptionUtils() { /** * Returns an String object that can be used after building the exception stack * trace. - * + * * @param message the exception message * @param cause the cause * @return the exception stack @@ -47,7 +44,7 @@ public static String buildMessage(String message, Throwable cause) { /** * This method returns the stack trace - * + * * @param throwable the exception to be added to the list of exception * @return the stack trace */ @@ -59,7 +56,7 @@ public static String getStackTrace(Throwable throwable) { } public static void logRootCause(Throwable exception) { - logger.error("Exception Root Cause: {} ", exception.getMessage()); - logger.debug("Exception Root Cause:", exception); + log.error("Exception Root Cause: {} ", exception.getMessage()); + log.debug("Exception Root Cause:", exception); } } diff --git a/src/main/java/io/mosip/mimoto/service/impl/CredentialServiceImpl.java b/src/main/java/io/mosip/mimoto/service/impl/CredentialServiceImpl.java index 15b74e84..2a0b97a5 100644 --- a/src/main/java/io/mosip/mimoto/service/impl/CredentialServiceImpl.java +++ b/src/main/java/io/mosip/mimoto/service/impl/CredentialServiceImpl.java @@ -32,6 +32,7 @@ import io.mosip.vercred.CredentialsVerifier; import io.mosip.vercred.exception.*; import jakarta.annotation.PostConstruct; +import lombok.extern.slf4j.Slf4j; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.Velocity; import org.jetbrains.annotations.NotNull; @@ -54,11 +55,10 @@ import static io.mosip.mimoto.exception.ErrorConstants.*; +@Slf4j @Service public class CredentialServiceImpl implements CredentialService { - private final Logger logger = LoggerUtil.getLogger(CredentialServiceImpl.class); - @Autowired private Utilities utilities; @@ -136,7 +136,7 @@ public ByteArrayInputStream downloadCredentialAsPDF(String issuerId, String cred public VCCredentialResponse downloadCredential(String credentialEndpoint, VCCredentialRequest vcCredentialRequest, String accessToken) throws InvalidCredentialResourceException { VCCredentialResponse vcCredentialResponse = restApiClient.postApi(credentialEndpoint, MediaType.APPLICATION_JSON, vcCredentialRequest, VCCredentialResponse.class, accessToken); - logger.debug("VC Credential Response is -> " + vcCredentialResponse); + log.debug("VC Credential Response is -> " + vcCredentialResponse); if (vcCredentialResponse == null) throw new RuntimeException("VC Credential Issue API not accessible"); return vcCredentialResponse; } diff --git a/src/main/java/io/mosip/mimoto/service/impl/CredentialShareServiceImpl.java b/src/main/java/io/mosip/mimoto/service/impl/CredentialShareServiceImpl.java index e10e0f26..e5bb2cdb 100644 --- a/src/main/java/io/mosip/mimoto/service/impl/CredentialShareServiceImpl.java +++ b/src/main/java/io/mosip/mimoto/service/impl/CredentialShareServiceImpl.java @@ -16,6 +16,7 @@ import io.mosip.mimoto.service.CredentialShareService; import io.mosip.mimoto.service.RestClientService; import io.mosip.mimoto.util.*; +import lombok.extern.slf4j.Slf4j; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; @@ -41,6 +42,7 @@ import java.security.spec.InvalidKeySpecException; import java.util.*; +@Slf4j @Service public class CredentialShareServiceImpl implements CredentialShareService { public static final String VC_REQUEST_FILE_NAME = "%s.json"; @@ -81,8 +83,6 @@ public class CredentialShareServiceImpl implements CredentialShareService { /** The Constant UIN_TEXT_FILE. */ public static final String UIN_TEXT_FILE = "textFile"; - private Logger logger = LoggerUtil.getLogger(CredentialShareServiceImpl.class); - @Value("${vercred.type.vid:PCN}") private String vid; @@ -121,7 +121,7 @@ public boolean generateDocuments(EventModel eventModel) throws Exception { Path eventFilePath = Path.of(utilities.getDataPath(), String.format(EVENT_JSON_FILE_NAME, eventModel.getEvent().getTransactionId())); Files.write(eventFilePath, gson.toJson(eventModel).getBytes(), StandardOpenOption.CREATE); - logger.info("Event data saved:: " + eventFilePath.toFile().getAbsolutePath()); + log.info("Event data saved:: " + eventFilePath.toFile().getAbsolutePath()); Map byteMap = new HashMap<>(); String decodedCredential = null; @@ -158,9 +158,9 @@ public boolean generateDocuments(EventModel eventModel) throws Exception { String.format(CARD_JSON_FILE_NAME, eventModel.getEvent().getTransactionId())); Files.deleteIfExists(textFilePath); Files.write(textFilePath, byteMap.get(UIN_TEXT_FILE), StandardOpenOption.CREATE); - logger.info("Generated files from event:: " + textFilePath.toFile().getAbsolutePath()); + log.info("Generated files from event:: " + textFilePath.toFile().getAbsolutePath()); } catch (Exception e){ - logger.error(e.getMessage(), e); + log.error(e.getMessage(), e); return false; } @@ -175,7 +175,7 @@ public org.json.JSONObject decrypt(String credential, String credentialSubject, } catch (Exception e) { description.setMessage(PlatformErrorMessages.MIMOTO_VC_DECRYPTION_FAILED.getMessage()); description.setCode(PlatformErrorMessages.MIMOTO_VC_DECRYPTION_FAILED.getCode()); - logger.error(description.toString(), e); + log.error(description.toString(), e); throw new DocumentGeneratorException(DocumentGeneratorExceptionCodeConstant.VC_DECRYPTION_EXCEPTION.getErrorCode(), e.getMessage() + ExceptionUtils.getStackTrace(e)); } @@ -188,7 +188,7 @@ public Map getDocuments( String credentialType, String requestId, String sign) { - logger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), + log.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), "CredentialShareServiceImpl::getDocuments()::entry"); Map byteMap = new HashMap<>(); @@ -214,7 +214,7 @@ else if (credentialJSON.has(vid)) } catch (Exception e) { description.setMessage(PlatformErrorMessages.MIMOTO_DOCUMENT_GENERATION_FAILED.getMessage()); description.setCode(PlatformErrorMessages.MIMOTO_DOCUMENT_GENERATION_FAILED.getCode()); - logger.error(description.toString(), e); + log.error(description.toString(), e); throw new DocumentGeneratorException(DocumentGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), e.getMessage() + ExceptionUtils.getStackTrace(e)); @@ -244,7 +244,7 @@ else if (credentialJSON.has(vid)) auditLogRequestBuilder.createAuditRequestBuilder(description.getMessage(), eventId, eventName, eventType, moduleId, moduleName, id); } - logger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), "", + log.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), "", "CredentialShareServiceImpl::getDocuments()::exit"); return byteMap; @@ -304,7 +304,7 @@ public org.json.JSONObject getBiometricsDataJSON(String individualBiometric) { } } } catch (Exception e) { - logger.error("Something wrong when trying to get biometrics data", e); + log.error("Something wrong when trying to get biometrics data", e); } } @@ -402,7 +402,7 @@ public org.json.JSONObject decryptAttribute(org.json.JSONObject data, String enc cryptoWithPinResponseDto = cryptoUtil.decryptWithPin(cryptoWithPinRequestDto); } catch (InvalidKeyException | NoSuchAlgorithmException | InvalidKeySpecException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException e) { - logger.error("Error while decrypting the data", e); + log.error("Error while decrypting the data", e); throw new CryptoManagerException(PlatformErrorMessages.MIMOTO_INVALID_KEY_EXCEPTION.getCode(), PlatformErrorMessages.MIMOTO_INVALID_KEY_EXCEPTION.getMessage(), e); } diff --git a/src/main/java/io/mosip/mimoto/service/impl/DataShareServiceImpl.java b/src/main/java/io/mosip/mimoto/service/impl/DataShareServiceImpl.java index 3674b387..b65c50c5 100644 --- a/src/main/java/io/mosip/mimoto/service/impl/DataShareServiceImpl.java +++ b/src/main/java/io/mosip/mimoto/service/impl/DataShareServiceImpl.java @@ -9,6 +9,7 @@ import io.mosip.mimoto.exception.ErrorConstants; import io.mosip.mimoto.util.RestApiClient; import jakarta.annotation.PostConstruct; +import lombok.extern.slf4j.Slf4j; import org.apache.oro.text.regex.PatternMatcher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,6 +26,7 @@ import java.net.URL; +@Slf4j @Service public class DataShareServiceImpl { @@ -43,8 +45,6 @@ public class DataShareServiceImpl { @Value("${mosip.data.share.create.retry.count}") Integer maxRetryCount; - private final Logger logger = LoggerFactory.getLogger(DataShareServiceImpl.class); - @Autowired ObjectMapper objectMapper; @@ -69,7 +69,7 @@ public String getFilename() { HttpEntity> requestEntity = new HttpEntity<>(map, headers); DataShareResponseWrapperDTO dataShareResponseWrapperDTO = pushCredentialIntoDataShare(requestEntity); - logger.info("Data pushed into DataShare -> " + dataShareResponseWrapperDTO); + log.info("Data pushed into DataShare -> " + dataShareResponseWrapperDTO); return dataShareResponseWrapperDTO.getDataShare().getUrl(); } @@ -80,7 +80,7 @@ private DataShareResponseWrapperDTO pushCredentialIntoDataShare(HttpEntity " + vcCredentialResponse ); + log.info("Completed Mapping the Credential to Object => " + vcCredentialResponse ); if(vcCredentialResponse.getCredential() == null){ throw new InvalidCredentialResourceException(ErrorConstants.RESOURCE_EXPIRED.getErrorMessage()); } diff --git a/src/main/java/io/mosip/mimoto/service/impl/IssuersServiceImpl.java b/src/main/java/io/mosip/mimoto/service/impl/IssuersServiceImpl.java index 074c7b4c..8e6936e6 100644 --- a/src/main/java/io/mosip/mimoto/service/impl/IssuersServiceImpl.java +++ b/src/main/java/io/mosip/mimoto/service/impl/IssuersServiceImpl.java @@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import io.mosip.kernel.core.logger.spi.Logger; import io.mosip.mimoto.dto.IssuerDTO; import io.mosip.mimoto.dto.IssuersDTO; import io.mosip.mimoto.dto.mimoto.CredentialIssuerWellKnownResponse; @@ -15,7 +14,6 @@ import io.mosip.mimoto.exception.InvalidWellknownResponseException; import io.mosip.mimoto.service.IssuersService; import io.mosip.mimoto.util.CredentialIssuerWellknownResponseValidator; -import io.mosip.mimoto.util.LoggerUtil; import io.mosip.mimoto.util.RestApiClient; import io.mosip.mimoto.util.Utilities; import jakarta.validation.Validator; @@ -31,7 +29,6 @@ @Service public class IssuersServiceImpl implements IssuersService { - private final Logger logger = LoggerUtil.getLogger(IssuersServiceImpl.class); @Autowired private Utilities utilities; diff --git a/src/main/java/io/mosip/mimoto/service/impl/PresentationServiceImpl.java b/src/main/java/io/mosip/mimoto/service/impl/PresentationServiceImpl.java index 005183e9..409d8622 100644 --- a/src/main/java/io/mosip/mimoto/service/impl/PresentationServiceImpl.java +++ b/src/main/java/io/mosip/mimoto/service/impl/PresentationServiceImpl.java @@ -10,6 +10,7 @@ import io.mosip.mimoto.exception.VPNotCreatedException; import io.mosip.mimoto.service.PresentationService; import io.mosip.mimoto.util.RestApiClient; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -23,6 +24,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; +@Slf4j @Service public class PresentationServiceImpl implements PresentationService { @@ -44,8 +46,6 @@ public class PresentationServiceImpl implements PresentationService { @Value("${server.tomcat.max-http-response-header-size:65536}") Integer maximumResponseHeaderSize; - private final Logger logger = LoggerFactory.getLogger(PresentationServiceImpl.class); - @Override public String authorizePresentation(PresentationRequestDTO presentationRequestDTO) throws IOException { VCCredentialResponse vcCredentialResponse = dataShareService.downloadCredentialFromDataShare(presentationRequestDTO); @@ -55,7 +55,7 @@ public String authorizePresentation(PresentationRequestDTO presentationRequestDT throw new VPNotCreatedException(ErrorConstants.INVALID_REQUEST.getErrorMessage()); } - logger.info("Started the Constructing VP Token"); + log.info("Started the Constructing VP Token"); String redirectionString = presentationDefinitionDTO.getInputDescriptors() .stream() .findFirst() @@ -64,7 +64,7 @@ public String authorizePresentation(PresentationRequestDTO presentationRequestDT .stream() .anyMatch(proofType -> vcCredentialResponse.getCredential().getProof().getType().equals(proofType)); if (matchingProofTypes) { - logger.info("Started the Construction of VP token"); + log.info("Started the Construction of VP token"); try { VerifiablePresentationDTO verifiablePresentationDTO = constructVerifiablePresentationString(vcCredentialResponse.getCredential()); String presentationSubmission = constructPresentationSubmission(verifiablePresentationDTO, presentationDefinitionDTO, inputDescriptorDTO); @@ -77,7 +77,7 @@ public String authorizePresentation(PresentationRequestDTO presentationRequestDT throw new VPNotCreatedException(ErrorConstants.INVALID_REQUEST.getErrorMessage()); } } - logger.info("No Credentials Matched the VP request."); + log.info("No Credentials Matched the VP request."); throw new VPNotCreatedException(ErrorConstants.INVALID_REQUEST.getErrorMessage()); }).orElseThrow(() -> new VPNotCreatedException(ErrorConstants.INVALID_REQUEST.getErrorMessage())); if(redirectionString.length() > maximumResponseHeaderSize) { diff --git a/src/main/java/io/mosip/mimoto/service/impl/RestClientServiceImpl.java b/src/main/java/io/mosip/mimoto/service/impl/RestClientServiceImpl.java index 85ca72b8..64712373 100644 --- a/src/main/java/io/mosip/mimoto/service/impl/RestClientServiceImpl.java +++ b/src/main/java/io/mosip/mimoto/service/impl/RestClientServiceImpl.java @@ -1,8 +1,12 @@ package io.mosip.mimoto.service.impl; -import java.util.List; - +import io.mosip.mimoto.constant.ApiName; import io.mosip.mimoto.constant.LoggerFileConstant; +import io.mosip.mimoto.exception.ApisResourceAccessException; +import io.mosip.mimoto.exception.PlatformErrorMessages; +import io.mosip.mimoto.service.RestClientService; +import io.mosip.mimoto.util.RestApiClient; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.http.MediaType; @@ -12,25 +16,17 @@ import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; -import io.mosip.kernel.core.logger.spi.Logger; -import io.mosip.mimoto.constant.ApiName; -import io.mosip.mimoto.exception.ApisResourceAccessException; -import io.mosip.mimoto.exception.PlatformErrorMessages; -import io.mosip.mimoto.service.RestClientService; -import io.mosip.mimoto.util.LoggerUtil; -import io.mosip.mimoto.util.RestApiClient; +import java.util.List; /** * The Class RestClientServiceImpl. - * + * * @author Rishabh Keshari */ +@Slf4j @Service public class RestClientServiceImpl implements RestClientService { - /** The logger. */ - Logger logger = LoggerUtil.getLogger(RestClientServiceImpl.class); - /** The rest api client. */ @Autowired private RestApiClient restApiClient; @@ -41,7 +37,7 @@ public class RestClientServiceImpl implements RestClientService { /* * (non-Javadoc) - * + * * @see io.mosip.registration.processor.core.spi.restclient. * RestClientService#getApi(io.mosip.registration. * processor .core.code.ApiName, @@ -51,7 +47,7 @@ public class RestClientServiceImpl implements RestClientService { @Override public Object getApi(ApiName apiName, List pathsegments, String queryParamName, String queryParamValue, Class responseType) throws ApisResourceAccessException { - logger.debug("RestClientServiceImpl::getApi()::entry"); + log.debug("RestClientServiceImpl::getApi()::entry"); Object obj = null; String apiHostIpPort = env.getProperty(apiName.name()); @@ -71,18 +67,18 @@ public Object getApi(ApiName apiName, List pathsegments, String queryPar try { uriComponents = builder.build(false).encode(); - logger.debug(uriComponents.toUri().toString(), "URI"); + log.debug(uriComponents.toUri().toString(), "URI"); obj = restApiClient.getApi(uriComponents.toUri(), responseType); } catch (Exception e) { - logger.error(e.getMessage(), e); + log.error(e.getMessage(), e); throw new ApisResourceAccessException( PlatformErrorMessages.MIMOTO_RCT_UNKNOWN_RESOURCE_EXCEPTION.getCode(), e); } } - logger.debug("RestClientServiceImpl::getApi()::exit"); + log.debug("RestClientServiceImpl::getApi()::exit"); return obj; } @@ -90,7 +86,7 @@ public Object getApi(ApiName apiName, List pathsegments, String queryPar public Object getApi(ApiName apiName, List pathsegments, List queryParamName, List queryParamValue, Class responseType) throws ApisResourceAccessException { - logger.debug("RestClientServiceImpl::getApi()::entry"); + log.debug("RestClientServiceImpl::getApi()::entry"); Object obj = null; String apiHostIpPort = env.getProperty(apiName.name()); @@ -113,24 +109,24 @@ public Object getApi(ApiName apiName, List pathsegments, List qu try { uriComponents = builder.build(false).encode(); - logger.debug(uriComponents.toUri().toString(), "URI"); + log.debug(uriComponents.toUri().toString(), "URI"); obj = restApiClient.getApi(uriComponents.toUri(), responseType); } catch (Exception e) { - logger.error(e.getMessage(), e); + log.error(e.getMessage(), e); throw new ApisResourceAccessException( PlatformErrorMessages.MIMOTO_RCT_UNKNOWN_RESOURCE_EXCEPTION.getCode(), e); } } - logger.debug("RestClientServiceImpl::getApi()::exit"); + log.debug("RestClientServiceImpl::getApi()::exit"); return obj; } public Object postApi(ApiName apiName, String queryParamName, String queryParamValue, Object requestedData, Class responseType, MediaType mediaType) throws ApisResourceAccessException { - logger.debug(LoggerFileConstant.REST_CLIENT_SERVICE_IMPL_POST_API_ENTRY); + log.debug(LoggerFileConstant.REST_CLIENT_SERVICE_IMPL_POST_API_ENTRY); Object obj = null; String apiHostIpPort = env.getProperty(apiName.name()); @@ -147,20 +143,20 @@ public Object postApi(ApiName apiName, String queryParamName, String queryParamV obj = restApiClient.postApi(builder.toUriString(), mediaType, requestedData, responseType); } catch (Exception e) { - logger.error(e.getMessage(), e); + log.error(e.getMessage(), e); throw new ApisResourceAccessException( PlatformErrorMessages.MIMOTO_RCT_UNKNOWN_RESOURCE_EXCEPTION.getMessage(), e); } } - logger.debug(LoggerFileConstant.REST_CLIENT_SERVICE_IMPL_POST_API_EXIT); + log.debug(LoggerFileConstant.REST_CLIENT_SERVICE_IMPL_POST_API_EXIT); return obj; } /* * (non-Javadoc) - * + * * @see io.mosip.registration.processor.core.spi.restclient. * RestClientService#postApi(io.mosip.registration. * processor.core.code.ApiName, @@ -175,7 +171,7 @@ public Object postApi(ApiName apiName, String queryParamName, String queryParamV /* * (non-Javadoc) - * + * * @see io.mosip.registration.processor.core.spi.restclient. * RestClientService#postApi(io.mosip.registration. * processor.core.code.ApiName, java.util.List, java.lang.String, @@ -185,7 +181,7 @@ public Object postApi(ApiName apiName, String queryParamName, String queryParamV public Object postApi(ApiName apiName, List pathsegments, String queryParamName, String queryParamValue, Object requestedData, Class responseType) throws ApisResourceAccessException { - logger.debug(LoggerFileConstant.REST_CLIENT_SERVICE_IMPL_POST_API_ENTRY); + log.debug(LoggerFileConstant.REST_CLIENT_SERVICE_IMPL_POST_API_ENTRY); Object obj = null; String apiHostIpPort = env.getProperty(apiName.name()); UriComponentsBuilder builder = null; @@ -209,14 +205,14 @@ public Object postApi(ApiName apiName, List pathsegments, String queryPa obj = restApiClient.postApi(builder.toUriString(), null, requestedData, responseType); } catch (Exception e) { - logger.error(e.getMessage(), e); + log.error(e.getMessage(), e); throw new ApisResourceAccessException( PlatformErrorMessages.MIMOTO_RCT_UNKNOWN_RESOURCE_EXCEPTION.getMessage(), e); } } - logger.debug(LoggerFileConstant.REST_CLIENT_SERVICE_IMPL_POST_API_EXIT); + log.debug(LoggerFileConstant.REST_CLIENT_SERVICE_IMPL_POST_API_EXIT); return obj; } @@ -225,7 +221,7 @@ public Object postApi(ApiName apiName, MediaType mediaType, List pathseg List queryParamValue, Object requestedData, Class responseType) throws ApisResourceAccessException { - logger.debug(LoggerFileConstant.REST_CLIENT_SERVICE_IMPL_POST_API_ENTRY); + log.debug(LoggerFileConstant.REST_CLIENT_SERVICE_IMPL_POST_API_ENTRY); Object obj = null; String apiHostIpPort = env.getProperty(apiName.name()); UriComponentsBuilder builder = null; @@ -247,14 +243,14 @@ public Object postApi(ApiName apiName, MediaType mediaType, List pathseg obj = restApiClient.postApi(builder.toUriString(), mediaType, requestedData, responseType); } catch (Exception e) { - logger.error(e.getMessage(), e); + log.error(e.getMessage(), e); throw new ApisResourceAccessException( PlatformErrorMessages.MIMOTO_RCT_UNKNOWN_RESOURCE_EXCEPTION.getMessage(), e); } } - logger.debug(LoggerFileConstant.REST_CLIENT_SERVICE_IMPL_POST_API_EXIT); + log.debug(LoggerFileConstant.REST_CLIENT_SERVICE_IMPL_POST_API_EXIT); return obj; } @@ -262,19 +258,19 @@ public Object postApi(ApiName apiName, MediaType mediaType, List pathseg public Object postApi(ApiName apiName, Object requestedData, Class responseType, boolean useBearerToken) throws ApisResourceAccessException { - logger.debug(LoggerFileConstant.REST_CLIENT_SERVICE_IMPL_POST_API_ENTRY); + log.debug(LoggerFileConstant.REST_CLIENT_SERVICE_IMPL_POST_API_ENTRY); Object obj = null; String apiHostIpPort = env.getProperty(apiName.name()); if (apiHostIpPort != null) { try { obj = restApiClient.postApi(apiHostIpPort, MediaType.APPLICATION_JSON, requestedData, responseType, useBearerToken); } catch (Exception e) { - logger.error(e.getMessage(), e); + log.error(e.getMessage(), e); throw new ApisResourceAccessException( PlatformErrorMessages.MIMOTO_RCT_UNKNOWN_RESOURCE_EXCEPTION.getMessage(), e); } } - logger.debug(LoggerFileConstant.REST_CLIENT_SERVICE_IMPL_POST_API_EXIT); + log.debug(LoggerFileConstant.REST_CLIENT_SERVICE_IMPL_POST_API_EXIT); return obj; } @@ -293,4 +289,4 @@ private void addPathSegments(List pathSegments, UriComponentsBuilder bui } } } -} \ No newline at end of file +} diff --git a/src/main/java/io/mosip/mimoto/service/impl/VerifierServiceImpl.java b/src/main/java/io/mosip/mimoto/service/impl/VerifierServiceImpl.java index 42bdc95a..dd13c96e 100644 --- a/src/main/java/io/mosip/mimoto/service/impl/VerifierServiceImpl.java +++ b/src/main/java/io/mosip/mimoto/service/impl/VerifierServiceImpl.java @@ -9,6 +9,7 @@ import io.mosip.mimoto.exception.InvalidVerifierException; import io.mosip.mimoto.service.VerifierService; import io.mosip.mimoto.util.Utilities; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.validator.routines.UrlValidator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,7 +23,7 @@ import static org.apache.commons.validator.routines.UrlValidator.ALLOW_ALL_SCHEMES; import static org.apache.commons.validator.routines.UrlValidator.ALLOW_LOCAL_URLS; - +@Slf4j @Service public class VerifierServiceImpl implements VerifierService { @@ -61,7 +62,7 @@ public Optional getVerifierByClientId(String clientId) throws ApiNo @Override public void validateVerifier(String clientId, String redirectUri) throws ApiNotAccessibleException, JsonProcessingException { - logger.info("Started the presentation Validation"); + log.info("Started the presentation Validation"); getVerifierByClientId(clientId).ifPresentOrElse( (verifierDTO) -> { boolean isValidVerifier = verifierDTO.getRedirectUris().stream().anyMatch(registeredRedirectUri -> diff --git a/src/main/java/io/mosip/mimoto/util/AttestationOfflineVerify.java b/src/main/java/io/mosip/mimoto/util/AttestationOfflineVerify.java index 32b2355e..9c7d1c58 100644 --- a/src/main/java/io/mosip/mimoto/util/AttestationOfflineVerify.java +++ b/src/main/java/io/mosip/mimoto/util/AttestationOfflineVerify.java @@ -19,6 +19,7 @@ import com.google.api.client.json.jackson2.JacksonFactory; import com.google.api.client.json.webtoken.JsonWebSignature; +import lombok.extern.slf4j.Slf4j; import org.apache.http.conn.ssl.DefaultHostnameVerifier; import org.springframework.stereotype.Component; @@ -33,9 +34,9 @@ /** * Verify the device attestation statement offline. */ +@Slf4j @Component public class AttestationOfflineVerify { - private final Logger logger = LoggerUtil.getLogger(AttestationOfflineVerify.class); private final DefaultHostnameVerifier HOSTNAME_VERIFIER = new DefaultHostnameVerifier(); @@ -64,8 +65,8 @@ public AttestationStatement parseAndVerify(String signedAttestationStatment) thr if (!verifyHostname("attest.android.com", cert)) { throw new Exception("Certificate isn't issued for the hostname attest.android.com."); } - - logger.info("Sucessfully verified the signature of the attestation statement using offline method."); + + log.info("Sucessfully verified the signature of the attestation statement using offline method."); // Extract and use the payload data. AttestationStatement stmt = (AttestationStatement) jws.getPayload(); @@ -88,7 +89,7 @@ private boolean verifyHostname(String hostname, X509Certificate leafCert) { HOSTNAME_VERIFIER.verify(hostname, leafCert); return true; } catch (SSLException e) { - logger.error("Error when verifying hostname", e); + log.error("Error when verifying hostname", e); } return false; diff --git a/src/main/java/io/mosip/mimoto/util/AttestationOnlineVerify.java b/src/main/java/io/mosip/mimoto/util/AttestationOnlineVerify.java index c0e2a5b0..9d94361e 100644 --- a/src/main/java/io/mosip/mimoto/util/AttestationOnlineVerify.java +++ b/src/main/java/io/mosip/mimoto/util/AttestationOnlineVerify.java @@ -29,6 +29,7 @@ import com.google.api.client.json.jackson2.JacksonFactory; import com.google.api.client.util.Base64; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -47,8 +48,8 @@ * otherwise all requests will fail. */ @Component +@Slf4j public class AttestationOnlineVerify { - private final Logger logger = LoggerUtil.getLogger(AttestationOnlineVerify.class); private final HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); @@ -118,7 +119,7 @@ public AttestationStatement parseAndVerify(String signedAttestationStatment) thr throw new Exception("The cryptographic signature of the attestation statement couldn't be " + "verified."); } - logger.info("Sucessfully verified the signature of the attestation statement using online method."); + log.info("Sucessfully verified the signature of the attestation statement using online method."); // The signature is valid, extract the data JSON from the JWS signature. byte[] data = extractJwsData(signedAttestationStatment); diff --git a/src/main/java/io/mosip/mimoto/util/AuditLogRequestBuilder.java b/src/main/java/io/mosip/mimoto/util/AuditLogRequestBuilder.java index b7685895..b00255f0 100644 --- a/src/main/java/io/mosip/mimoto/util/AuditLogRequestBuilder.java +++ b/src/main/java/io/mosip/mimoto/util/AuditLogRequestBuilder.java @@ -1,11 +1,5 @@ package io.mosip.mimoto.util; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - import io.mosip.mimoto.constant.ApiName; import io.mosip.mimoto.constant.AuditLogConstant; import io.mosip.mimoto.constant.LoggerFileConstant; @@ -15,18 +9,20 @@ import io.mosip.mimoto.dto.AuditResponseDto; import io.mosip.mimoto.exception.ApisResourceAccessException; import io.mosip.mimoto.service.RestClientService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; /** * The Class AuditRequestBuilder. - * + * * @author Rishabh Keshari */ +@Slf4j @Component public class AuditLogRequestBuilder { - /** The logger. */ - private final Logger logger = LoggerFactory.getLogger(AuditLogRequestBuilder.class); - /** The registration processor rest service. */ @Autowired private RestClientService registrationProcessorRestService; @@ -55,7 +51,7 @@ public class AuditLogRequestBuilder { */ @SuppressWarnings("unchecked") public ResponseWrapper createAuditRequestBuilder(String description, String eventId, String eventName, String eventType, String registrationId, ApiName apiname) { - logger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), + log.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), registrationId, "AuditLogRequestBuilder:: createAuditRequestBuilder(String description, String eventId, String eventName, String eventType,\r\n String registrationId, ApiName apiname)::entry"); @@ -88,10 +84,10 @@ public ResponseWrapper createAuditRequestBuilder(String descri "", requestWrapper, ResponseWrapper.class); } catch (ApisResourceAccessException arae) { - logger.error(arae.getMessage()); + log.error(arae.getMessage()); } - logger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), + log.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), registrationId, "AuditLogRequestBuilder:: createAuditRequestBuilder(String description, String eventId, String eventName, String eventType,\r\n" + " String registrationId, ApiName apiname)::exit"); @@ -102,7 +98,7 @@ public ResponseWrapper createAuditRequestBuilder(String descri @SuppressWarnings("unchecked") public ResponseWrapper createAuditRequestBuilder(String description, String eventId, String eventName, String eventType, String moduleId, String moduleName, String registrationId) { - logger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), + log.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), registrationId, "AuditLogRequestBuilder:: createAuditRequestBuilder(String description, String eventId, String eventName, String eventType,String moduleId,String moduleName,\r\n" + " String registrationId)::entry"); @@ -140,10 +136,10 @@ public ResponseWrapper createAuditRequestBuilder(String descri } catch (ApisResourceAccessException arae) { - logger.error(arae.getMessage()); + log.error(arae.getMessage()); } - logger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), + log.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), registrationId, "AuditLogRequestBuilder:: createAuditRequestBuilder(String description, String eventId, String eventName, String eventType,String moduleId,String moduleName,\r\n" + " String registrationId)::exit"); diff --git a/src/main/java/io/mosip/mimoto/util/CbeffToBiometricUtil.java b/src/main/java/io/mosip/mimoto/util/CbeffToBiometricUtil.java index c2372f06..1174d03b 100644 --- a/src/main/java/io/mosip/mimoto/util/CbeffToBiometricUtil.java +++ b/src/main/java/io/mosip/mimoto/util/CbeffToBiometricUtil.java @@ -3,7 +3,6 @@ import io.mosip.kernel.biometrics.constant.BiometricType; import io.mosip.kernel.biometrics.entities.BIR; import io.mosip.kernel.biometrics.spi.CbeffUtil; -import io.mosip.kernel.core.logger.spi.Logger; import org.apache.commons.codec.binary.Base64; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -12,14 +11,12 @@ /** * The Class CbeffToBiometricUtil. - * + * * @author Monobikash Das */ @Component public class CbeffToBiometricUtil { - Logger logger = LoggerUtil.getLogger(CbeffToBiometricUtil.class); - /** The cbeffutil. */ @Autowired private CbeffUtil cbeffutil; diff --git a/src/main/java/io/mosip/mimoto/util/CredentialShareExceptionHandler.java b/src/main/java/io/mosip/mimoto/util/CredentialShareExceptionHandler.java index 934da882..89ac8213 100644 --- a/src/main/java/io/mosip/mimoto/util/CredentialShareExceptionHandler.java +++ b/src/main/java/io/mosip/mimoto/util/CredentialShareExceptionHandler.java @@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; -import io.mosip.kernel.core.logger.spi.Logger; import io.mosip.mimoto.controller.CredentialShareController; import io.mosip.mimoto.dto.CredentialShareResponse; import io.mosip.mimoto.dto.ErrorDTO; @@ -23,7 +22,7 @@ /** * The Class CredentialShareExceptionHandler. - * + * * @author M1048358 Alok */ @RestControllerAdvice(assignableTypes = CredentialShareController.class) @@ -42,8 +41,6 @@ public class CredentialShareExceptionHandler { @Autowired private Environment env; - private Logger logger = LoggerUtil.getLogger(CredentialShareExceptionHandler.class); - @ExceptionHandler(MethodArgumentNotValidException.class) public ResponseEntity badRequest(MethodArgumentNotValidException ex) { @@ -98,4 +95,4 @@ private ResponseEntity buildApiExceptionResponse(Except return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(response); } -} \ No newline at end of file +} diff --git a/src/main/java/io/mosip/mimoto/util/CryptoCoreUtil.java b/src/main/java/io/mosip/mimoto/util/CryptoCoreUtil.java index 873410d5..11fe4ad2 100644 --- a/src/main/java/io/mosip/mimoto/util/CryptoCoreUtil.java +++ b/src/main/java/io/mosip/mimoto/util/CryptoCoreUtil.java @@ -33,6 +33,7 @@ import javax.crypto.spec.PSource.PSpecified; import javax.crypto.spec.SecretKeySpec; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.digest.DigestUtils; import org.bouncycastle.crypto.InvalidCipherTextException; import org.bouncycastle.crypto.digests.SHA256Digest; @@ -47,9 +48,9 @@ import io.mosip.mimoto.exception.CryptoManagerException; import io.mosip.mimoto.exception.PlatformErrorMessages; +@Slf4j @Component public class CryptoCoreUtil { - static Logger logger = LoggerUtil.getLogger(CryptoCoreUtil.class); private final static String RSA_ECB_OAEP_PADDING = "RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING"; @@ -78,7 +79,7 @@ public String decrypt(String data) throws Exception { byte[] data1 = decryptData(dataBytes, privateKeyEntry); decryptedData = new String(data1); }catch (Exception e){ - logger.error( "Not able to decrypt the data", e); + log.error( "Not able to decrypt the data", e); } return decryptedData; } @@ -98,7 +99,7 @@ public PrivateKeyEntry loadP12(String fileName, String alias, String cyptoPasswo ProtectionParameter password = new PasswordProtection(cyptoPassword.toCharArray()); privateKeyEntry = (PrivateKeyEntry) mosipKeyStore.getEntry(alias, password); } catch (UnrecoverableEntryException | CertificateException | KeyStoreException | IOException|NoSuchAlgorithmException e) { - logger.error( "Not able to decrypt the data", e); + log.error( "Not able to decrypt the data", e); } finally { if (keystoreResourceStream != null) { keystoreResourceStream.close(); @@ -147,7 +148,7 @@ public byte[] decryptData(byte[] requestData, PrivateKeyEntry privateKey) throws return symmetricDecrypt(symmetricKey, encryptedData, null); } } catch (Exception e) { - logger.error( "Not able to decrypt the data {}", e); + log.error( "Not able to decrypt the data {}", e); } return null; } @@ -201,7 +202,7 @@ private static byte[] asymmetricDecrypt(PrivateKey privateKey, BigInteger keyMod cipher.init(Cipher.DECRYPT_MODE, privateKey, oaepParams); return cipher.doFinal(data); } catch (java.security.NoSuchAlgorithmException e) { - logger.error("Not able to decrypt the data {}", e); + log.error("Not able to decrypt the data {}", e); throw new NoSuchAlgorithmException(e); } catch (NoSuchPaddingException e) { throw new NoSuchPaddingException(e.getMessage()); @@ -245,34 +246,34 @@ public byte[] symmetricDecrypt(SecretKey key, byte[] data, byte[] nonce, byte[] } output = cipher.doFinal(data, 0, data.length); } catch (InvalidAlgorithmParameterException e) { - logger.error(PlatformErrorMessages.MIMOTO_INVALID_KEY_EXCEPTION.getCode(), + log.error(PlatformErrorMessages.MIMOTO_INVALID_KEY_EXCEPTION.getCode(), PlatformErrorMessages.MIMOTO_INVALID_KEY_EXCEPTION.getMessage(), e); throw new InvalidParamSpecException(PlatformErrorMessages.MIMOTO_INVALID_KEY_EXCEPTION.getCode(), PlatformErrorMessages.MIMOTO_INVALID_KEY_EXCEPTION.getMessage(), e); } catch (IllegalBlockSizeException e) { - logger.error(PlatformErrorMessages.MIMOTO_INVALID_KEY_EXCEPTION.getCode(), + log.error(PlatformErrorMessages.MIMOTO_INVALID_KEY_EXCEPTION.getCode(), PlatformErrorMessages.MIMOTO_INVALID_KEY_EXCEPTION.getMessage(), e); throw new CryptoManagerException(PlatformErrorMessages.MIMOTO_INVALID_KEY_EXCEPTION.getCode(), PlatformErrorMessages.MIMOTO_INVALID_KEY_EXCEPTION.getMessage(), e); } catch (BadPaddingException e) { - logger.error(PlatformErrorMessages.CERTIFICATE_THUMBPRINT_ERROR.getCode(), + log.error(PlatformErrorMessages.CERTIFICATE_THUMBPRINT_ERROR.getCode(), PlatformErrorMessages.CERTIFICATE_THUMBPRINT_ERROR.getMessage(), e); throw new CryptoManagerException(PlatformErrorMessages.CERTIFICATE_THUMBPRINT_ERROR.getCode(), PlatformErrorMessages.CERTIFICATE_THUMBPRINT_ERROR.getMessage(), e); } catch (NoSuchAlgorithmException e) { - logger.error(PlatformErrorMessages.CERTIFICATE_THUMBPRINT_ERROR.getCode(), + log.error(PlatformErrorMessages.CERTIFICATE_THUMBPRINT_ERROR.getCode(), PlatformErrorMessages.CERTIFICATE_THUMBPRINT_ERROR.getMessage(), e); throw new CryptoManagerException(PlatformErrorMessages.CERTIFICATE_THUMBPRINT_ERROR.getCode(), PlatformErrorMessages.CERTIFICATE_THUMBPRINT_ERROR.getMessage(), e); } catch (NoSuchPaddingException e) { - logger.error(PlatformErrorMessages.CERTIFICATE_THUMBPRINT_ERROR.getCode(), + log.error(PlatformErrorMessages.CERTIFICATE_THUMBPRINT_ERROR.getCode(), PlatformErrorMessages.CERTIFICATE_THUMBPRINT_ERROR.getMessage(), e); throw new CryptoManagerException(PlatformErrorMessages.CERTIFICATE_THUMBPRINT_ERROR.getCode(), PlatformErrorMessages.CERTIFICATE_THUMBPRINT_ERROR.getMessage(), e); } catch (InvalidKeyException e) { - logger.error(PlatformErrorMessages.MIMOTO_INVALID_KEY_EXCEPTION.getCode(), + log.error(PlatformErrorMessages.MIMOTO_INVALID_KEY_EXCEPTION.getCode(), PlatformErrorMessages.MIMOTO_INVALID_KEY_EXCEPTION.getMessage(), e); throw new CryptoManagerException(PlatformErrorMessages.MIMOTO_INVALID_KEY_EXCEPTION.getCode(), PlatformErrorMessages.MIMOTO_INVALID_KEY_EXCEPTION.getMessage(), e); @@ -284,7 +285,7 @@ public static byte[] getCertificateThumbprint(Certificate cert) { try { return DigestUtils.sha256(cert.getEncoded()); } catch (java.security.cert.CertificateEncodingException e) { - logger.error(PlatformErrorMessages.CERTIFICATE_THUMBPRINT_ERROR.getCode(), + log.error(PlatformErrorMessages.CERTIFICATE_THUMBPRINT_ERROR.getCode(), PlatformErrorMessages.CERTIFICATE_THUMBPRINT_ERROR.getMessage(), e); throw new CryptoManagerException(PlatformErrorMessages.CERTIFICATE_THUMBPRINT_ERROR.getCode(), PlatformErrorMessages.CERTIFICATE_THUMBPRINT_ERROR.getMessage(), e); diff --git a/src/main/java/io/mosip/mimoto/util/DataShareUtil.java b/src/main/java/io/mosip/mimoto/util/DataShareUtil.java index 68bc8681..a7456efa 100644 --- a/src/main/java/io/mosip/mimoto/util/DataShareUtil.java +++ b/src/main/java/io/mosip/mimoto/util/DataShareUtil.java @@ -1,9 +1,13 @@ package io.mosip.mimoto.util; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - +import com.fasterxml.jackson.databind.ObjectMapper; +import io.mosip.mimoto.constant.ApiName; +import io.mosip.mimoto.dto.DataShare; +import io.mosip.mimoto.dto.DataShareResponseDto; +import io.mosip.mimoto.dto.ErrorDTO; +import io.mosip.mimoto.exception.ApiNotAccessibleException; +import io.mosip.mimoto.exception.DataShareException; +import io.mosip.mimoto.service.RestClientService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ByteArrayResource; import org.springframework.http.HttpEntity; @@ -14,16 +18,9 @@ import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.HttpServerErrorException; -import io.mosip.kernel.core.logger.spi.Logger; -import io.mosip.mimoto.constant.ApiName; -import io.mosip.mimoto.dto.DataShare; -import io.mosip.mimoto.dto.DataShareResponseDto; -import io.mosip.mimoto.dto.ErrorDTO; -import io.mosip.mimoto.exception.ApiNotAccessibleException; -import io.mosip.mimoto.exception.DataShareException; -import io.mosip.mimoto.service.RestClientService; - -import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; @Component public class DataShareUtil { @@ -34,8 +31,6 @@ public class DataShareUtil { @Autowired private ObjectMapper mapper; - Logger logger = LoggerUtil.getLogger(DataShareUtil.class); - private static final String GET_DATA = "getDataShare"; private static final String DATASHARE = "DataShareUtil"; diff --git a/src/main/java/io/mosip/mimoto/util/JoseUtil.java b/src/main/java/io/mosip/mimoto/util/JoseUtil.java index f5655c0d..1abee52c 100644 --- a/src/main/java/io/mosip/mimoto/util/JoseUtil.java +++ b/src/main/java/io/mosip/mimoto/util/JoseUtil.java @@ -12,13 +12,13 @@ import com.nimbusds.jwt.SignedJWT; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; -import io.mosip.kernel.core.logger.spi.Logger; import io.mosip.kernel.core.util.CryptoUtil; import io.mosip.mimoto.core.http.ResponseWrapper; import io.mosip.mimoto.dto.mimoto.JwkDto; import io.mosip.mimoto.dto.mimoto.WalletBindingInternalResponseDto; import io.mosip.mimoto.dto.mimoto.WalletBindingResponseDto; import io.mosip.mimoto.exception.IssuerOnboardingException; +import lombok.extern.slf4j.Slf4j; import org.jose4j.jws.JsonWebSignature; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -38,10 +38,9 @@ import java.util.Map; import java.util.UUID; +@Slf4j @Component public class JoseUtil { - - private final Logger logger = LoggerUtil.getLogger(JoseUtil.class); private static final String BEGIN_KEY = "-----BEGIN PUBLIC KEY-----"; private static final String END_KEY = "-----END PUBLIC KEY-----"; private static final String ALG_RS256 = "RS256"; @@ -98,12 +97,9 @@ private static RSAPublicKeySpec getKeySpecForPublicKey(String publicKeyString) t public ResponseWrapper addThumbprintAndKeyId(ResponseWrapper responseDto) { - logger.debug("Inside addThumbprintAndKeyId "); + log.debug("Inside addThumbprintAndKeyId "); ResponseWrapper responseWrapper = new ResponseWrapper<>(); - responseWrapper.setId(responseDto.getId()); - responseWrapper.setResponsetime(responseDto.getResponsetime()); - responseWrapper.setVersion(responseDto.getVersion()); responseWrapper.setErrors(responseDto.getErrors()); try { @@ -128,7 +124,7 @@ public ResponseWrapper addThumbprintAndKeyId(ResponseW responseWrapper.setResponse(response); } } catch (Exception e) { - logger.error("Exception occured while setting thumbprint ", e); + log.error("Exception occured while setting thumbprint ", e); } return responseWrapper; @@ -150,7 +146,7 @@ public String getJWT(String clientId, String keyStorePath, String fileName, Stri } privateKey = (RSAPrivateKey) privateKeyEntry.getPrivateKey(); } catch (IOException e) { - logger.error("Exception happened while loading the p12 file for invoking token call."); + log.error("Exception happened while loading the p12 file for invoking token call."); throw e; } return JWT.create() diff --git a/src/main/java/io/mosip/mimoto/util/RequestValidator.java b/src/main/java/io/mosip/mimoto/util/RequestValidator.java index e89dc6bc..3886a4f1 100644 --- a/src/main/java/io/mosip/mimoto/util/RequestValidator.java +++ b/src/main/java/io/mosip/mimoto/util/RequestValidator.java @@ -4,6 +4,7 @@ import io.mosip.mimoto.dto.mimoto.CredentialDownloadRequestDTO; import io.mosip.mimoto.exception.InvalidInputException; import io.mosip.mimoto.exception.PlatformErrorMessages; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -17,10 +18,9 @@ @Component +@Slf4j public class RequestValidator { - private static Logger logger = LoggerFactory.getLogger(RequestValidator.class); - @Value("${mosip.notificationtype:EMAIL|PHONE}") private String notificationType; public void validateInputRequest(BindingResult result){ @@ -35,13 +35,13 @@ public void validateInputRequest(BindingResult result){ public void validateNotificationChannel(List otpChannelList) { List incorrectNotificationChannel; - logger.info("\n Notification Types from application-default.properties in mosip-config - > {}", notificationType); + log.info("\n Notification Types from application-default.properties in mosip-config - > {}", notificationType); incorrectNotificationChannel = otpChannelList .stream() .filter(otpChannel -> !notificationType.contains(otpChannel)) .collect(Collectors.toList()); if (incorrectNotificationChannel.size() > 0) { - logger.error("Invalid Input is received in otpChannels {}", String.join(",", incorrectNotificationChannel)); + log.error("Invalid Input is received in otpChannels {}", String.join(",", incorrectNotificationChannel)); throw new InvalidInputException(PlatformErrorMessages.MIMOTO_PGS_INVALID_INPUT_PARAMETER.getMessage() + " - " + "otpChannels"); } } diff --git a/src/main/java/io/mosip/mimoto/util/RestApiClient.java b/src/main/java/io/mosip/mimoto/util/RestApiClient.java index 1df44902..00034444 100644 --- a/src/main/java/io/mosip/mimoto/util/RestApiClient.java +++ b/src/main/java/io/mosip/mimoto/util/RestApiClient.java @@ -5,6 +5,7 @@ import io.mosip.mimoto.core.http.RequestWrapper; import io.mosip.mimoto.dto.SecretKeyRequest; import io.mosip.mimoto.exception.TokenGenerationFailedException; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.apache.http.Header; import org.apache.http.HttpResponse; @@ -36,15 +37,13 @@ * * @author Rishabh Keshari */ +@Slf4j @Component public class RestApiClient { public static final String TOKEN = "token"; public static final String CONTENT_TYPE = "Content-Type"; - /** - * The logger. - */ - private Logger logger = LoggerUtil.getLogger(RestApiClient.class); + private static final String AUTHORIZATION = "Authorization="; /** * The builder. @@ -98,11 +97,11 @@ public T getApi(URI uri, Class responseType) throws Exception { rt = plainRestTemplate; } try { - logger.info("RestApiClient::getApi()::entry uri: {}", uri); + log.info("RestApiClient::getApi()::entry uri: {}", uri); result = (T) rt.exchange(uri, HttpMethod.GET, setRequestHeader(null, null), responseType) .getBody(); } catch (Exception e) { - logger.error("RestApiClient::getApi()::error uri: {} {} {}", uri, e.getMessage(), e); + log.error("RestApiClient::getApi()::error uri: {} {} {}", uri, e.getMessage(), e); } return result; } @@ -125,7 +124,7 @@ public T getApi(String url, Class responseType) { try { result = (T) rt.getForObject(url, responseType); } catch (Exception e) { - logger.error("RestApiClient::getApi()::error uri:{} {} {}", url, e.getMessage(), e); + log.error("RestApiClient::getApi()::error uri:{} {} {}", url, e.getMessage(), e); } return result; } @@ -149,10 +148,10 @@ public T postApi(String uri, MediaType mediaType, Object requestType, Class< rt = plainRestTemplate; } try { - logger.info("RestApiClient::postApi()::entry uri: {}", uri); + log.info("RestApiClient::postApi()::entry uri: {}", uri); result = (T) rt.postForObject(uri, setRequestHeader(requestType, mediaType), responseClass); } catch (Exception e) { - logger.error("RestApiClient::postApi()::error uri: {} {} {}", uri, e.getMessage(), e); + log.error("RestApiClient::postApi()::error uri: {} {} {}", uri, e.getMessage(), e); } return result; } @@ -160,10 +159,10 @@ public T postApi(String uri, MediaType mediaType, Object requestType, Class< public T postApi(String uri, MediaType mediaType, Object requestType, Class responseClass, boolean useBearerToken) throws Exception { T result = null; try { - logger.info("RestApiClient::postApi()::entry uri: {}", uri); + log.info("RestApiClient::postApi()::entry uri: {}", uri); result = (T) plainRestTemplate.postForObject(uri, setRequestHeader(requestType, mediaType, useBearerToken), responseClass); } catch (Exception e) { - logger.error("RestApiClient::postApi()::error uri: {} {} {}", uri, e.getMessage(), e); + log.error("RestApiClient::postApi()::error uri: {} {} {}", uri, e.getMessage(), e); if (e instanceof HttpClientErrorException) { HttpClientErrorException ex = (HttpClientErrorException)e; if (ex.getStatusCode().value() == 401) { @@ -181,10 +180,10 @@ public T postApi(String uri, MediaType mediaType, Object requestType, Class< public T postApi(String uri, MediaType mediaType, Object requestType, Class responseClass, String bearerToken){ T result = null; try { - logger.info("RestApiClient::postApi()::entry uri: {}", uri); + log.info("RestApiClient::postApi()::entry uri: {}", uri); result = (T) plainRestTemplate.postForObject(uri, setRequestHeader(requestType, mediaType, bearerToken), responseClass); } catch (Exception e) { - logger.error("RestApiClient::postApi()::error uri: {} {} {}", uri, e.getMessage(), e); + log.error("RestApiClient::postApi()::error uri: {} {} {}", uri, e.getMessage(), e); } return result; } diff --git a/src/main/java/io/mosip/mimoto/util/ServerUtil.java b/src/main/java/io/mosip/mimoto/util/ServerUtil.java index 7b60710b..af97f3de 100644 --- a/src/main/java/io/mosip/mimoto/util/ServerUtil.java +++ b/src/main/java/io/mosip/mimoto/util/ServerUtil.java @@ -1,29 +1,26 @@ package io.mosip.mimoto.util; +import lombok.extern.slf4j.Slf4j; + import java.net.InetAddress; import java.net.UnknownHostException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * This class provides Server IP and Name. * * @author Kiran Raj M1048860 */ +@Slf4j public class ServerUtil { /** The server instance. */ private static ServerUtil serverInstance = null; - /** The Constant LOGGER. */ - private static final Logger LOGGER = LoggerFactory.getLogger(ServerUtil.class); - /** The host not found. */ private String noHost = "HOST_NOT_FOUND"; /** - * + * * Instantiates a new server util. */ private ServerUtil() { @@ -57,7 +54,7 @@ public String getServerIp() { try { return InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { - LOGGER.error(noHost, e.getMessage()); + log.error(noHost, e.getMessage()); return "UNKNOWN-HOST"; } @@ -73,7 +70,7 @@ public String getServerName() { try { return InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { - LOGGER.error(noHost, e.getMessage()); + log.error(noHost, e.getMessage()); return "UNKNOWN-HOST"; } } diff --git a/src/main/java/io/mosip/mimoto/util/TokenHandlerUtil.java b/src/main/java/io/mosip/mimoto/util/TokenHandlerUtil.java index 6aa06197..e721153e 100644 --- a/src/main/java/io/mosip/mimoto/util/TokenHandlerUtil.java +++ b/src/main/java/io/mosip/mimoto/util/TokenHandlerUtil.java @@ -3,6 +3,7 @@ import java.time.LocalDateTime; import java.util.Map; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,13 +15,13 @@ import com.auth0.jwt.interfaces.DecodedJWT; /** - * + * * @author Srinivasan * */ +@Slf4j public class TokenHandlerUtil { - private static Logger LOGGER = LoggerFactory.getLogger(TokenHandlerUtil.class); private TokenHandlerUtil() { @@ -28,7 +29,7 @@ private TokenHandlerUtil() { /** * Validates the token offline based on the Oauth2 standards. - * + * * @param accessToken * - Bearer token * @param issuerUrl @@ -55,10 +56,10 @@ public static boolean isValidBearerToken(String accessToken, String issuerUrl, S return true; } } catch (JWTDecodeException e) { - LOGGER.error("JWT DECODE EXCEPTION ::".concat(e.getMessage()).concat(ExceptionUtils.getStackTrace(e))); + log.error("JWT DECODE EXCEPTION ::".concat(e.getMessage()).concat(ExceptionUtils.getStackTrace(e))); return false; } catch (Exception e) { - LOGGER.error(e.getMessage().concat(ExceptionUtils.getStackTrace(e))); + log.error(e.getMessage().concat(ExceptionUtils.getStackTrace(e))); return false; } diff --git a/src/main/java/io/mosip/mimoto/util/Utilities.java b/src/main/java/io/mosip/mimoto/util/Utilities.java index 1b78bcec..acdf38a7 100644 --- a/src/main/java/io/mosip/mimoto/util/Utilities.java +++ b/src/main/java/io/mosip/mimoto/util/Utilities.java @@ -2,13 +2,16 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Lists; import io.mosip.kernel.core.logger.spi.Logger; import io.mosip.mimoto.core.http.ResponseWrapper; +import io.mosip.mimoto.dto.ErrorDTO; import io.mosip.mimoto.exception.ExceptionUtils; import io.mosip.mimoto.exception.PlatformErrorMessages; import io.mosip.mimoto.service.impl.CredentialShareServiceImpl; import jakarta.annotation.PostConstruct; import lombok.Data; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.json.simple.JSONObject; import org.springframework.beans.factory.annotation.Autowired; @@ -29,9 +32,9 @@ import java.util.List; import static io.mosip.mimoto.constant.LoggerFileConstant.DELIMITER; -import static io.mosip.mimoto.controller.IdpController.getErrorResponse; @Component +@Slf4j @Data public class Utilities { private ClassLoader classLoader = Utilities.class.getClassLoader(); @@ -50,9 +53,6 @@ public class Utilities { // Sample VC websub event private String SAMPLE_EVENT = "%s_EVENT.json"; - private Logger logger = LoggerUtil.getLogger(Utilities.class); - - @Autowired private RestApiClient restApiClient; @@ -151,7 +151,7 @@ public void removeCacheData(String requestId) throws IOException { try { Files.delete(filePath); } catch (Exception e) { - logger.error("Cannot delete file: " + filePath, e); + log.error("Cannot delete file: " + filePath, e); } } } @@ -171,7 +171,7 @@ public String getJson(String configString, String resourcePath) { json = restApiClient.getApi(URI.create(configServerFileStorageURL + resourcePath), String.class); } } catch (Exception e) { - logger.error(ExceptionUtils.getStackTrace(e)); + log.error(ExceptionUtils.getStackTrace(e)); } return json; } @@ -185,7 +185,7 @@ public String getTrustedVerifiersJsonValue() { public String getCredentialSupportedTemplateString() { return getJson(credentialTemplateHtmlString, credentialTemplatePath); } - public static ResponseWrapper handleExceptionWithErrorCode(Exception exception) { + public static String[] handleExceptionWithErrorCode(Exception exception) { String errorMessage = exception.getMessage(); String errorCode = PlatformErrorMessages.MIMOTO_IDP_GENERIC_EXCEPTION.getCode(); @@ -194,6 +194,11 @@ public static ResponseWrapper handleExceptionWithErrorCode(Exception exc errorCode = errorSections[0]; errorMessage = errorSections[1]; } - return getErrorResponse(errorCode, errorMessage); + return new String[]{errorCode, errorMessage}; + } + + public static List getErrors(String errorCode, String errorMessage) { + ErrorDTO errorDTO = new ErrorDTO(errorCode, errorMessage); + return Lists.newArrayList(errorDTO); } } diff --git a/src/main/java/io/mosip/mimoto/util/WebSubSubscriptionHelper.java b/src/main/java/io/mosip/mimoto/util/WebSubSubscriptionHelper.java index 591572c5..4396d16c 100644 --- a/src/main/java/io/mosip/mimoto/util/WebSubSubscriptionHelper.java +++ b/src/main/java/io/mosip/mimoto/util/WebSubSubscriptionHelper.java @@ -1,5 +1,12 @@ package io.mosip.mimoto.util; +import io.mosip.kernel.core.websub.spi.PublisherClient; +import io.mosip.kernel.core.websub.spi.SubscriptionClient; +import io.mosip.kernel.websub.api.exception.WebSubClientException; +import io.mosip.kernel.websub.api.model.SubscriptionChangeRequest; +import io.mosip.kernel.websub.api.model.SubscriptionChangeResponse; +import io.mosip.kernel.websub.api.model.UnsubscriptionRequest; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.annotation.Cacheable; @@ -8,14 +15,7 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import io.mosip.kernel.core.logger.spi.Logger; -import io.mosip.kernel.core.websub.spi.PublisherClient; -import io.mosip.kernel.core.websub.spi.SubscriptionClient; -import io.mosip.kernel.websub.api.exception.WebSubClientException; -import io.mosip.kernel.websub.api.model.SubscriptionChangeRequest; -import io.mosip.kernel.websub.api.model.SubscriptionChangeResponse; -import io.mosip.kernel.websub.api.model.UnsubscriptionRequest; - +@Slf4j @Component public class WebSubSubscriptionHelper { @@ -40,14 +40,12 @@ public class WebSubSubscriptionHelper { @Autowired private PublisherClient pb; - private Logger logger = LoggerUtil.getLogger(WebSubSubscriptionHelper.class); - @Scheduled( fixedDelayString = "${websub-resubscription-delay-millisecs}", initialDelayString = "${mosip.event.delay-millisecs}" ) public void initSubscriptions() { - logger.info("Initializing subscriptions..."); + log.info("Initializing subscriptions..."); subscribeEvent(topic, callBackUrl, webSubSecret); } @@ -57,10 +55,10 @@ public SubscriptionChangeResponse unSubscribeEvent(String topic, String callBack unsubscriptionRequest.setCallbackURL(callBackUrl); unsubscriptionRequest.setHubURL(webSubHubSubUrl); unsubscriptionRequest.setTopic(topic); - logger.info("Unsubscription request : {}", unsubscriptionRequest); + log.info("Unsubscription request : {}", unsubscriptionRequest); return sb.unSubscribe(unsubscriptionRequest); } catch (WebSubClientException e) { - logger.info("Websub unsubscription error: {} ", e.getMessage()); + log.info("Websub unsubscription error: {} ", e.getMessage()); } return null; } @@ -72,10 +70,10 @@ public SubscriptionChangeResponse subscribeEvent(String topic, String callBackUr subscriptionRequest.setHubURL(webSubHubSubUrl); subscriptionRequest.setSecret(secret); subscriptionRequest.setTopic(topic); - logger.info("Subscription request : {}", subscriptionRequest); + log.info("Subscription request : {}", subscriptionRequest); return sb.subscribe(subscriptionRequest); } catch (WebSubClientException e) { - logger.info("Websub subscription error: {}", e.getMessage()); + log.info("Websub subscription error: {}", e.getMessage()); } return null; } @@ -85,7 +83,7 @@ public void publish(String topic, Object payload) { HttpHeaders headers = new HttpHeaders(); pb.publishUpdate(topic, payload, MediaType.APPLICATION_JSON_UTF8_VALUE, headers, webSubHubPubUrl); } catch (WebSubClientException e) { - logger.info("Websub publish update error: {}", e.getMessage()); + log.info("Websub publish update error: {}", e.getMessage()); } } @@ -95,7 +93,7 @@ public void registerTopic(String topic) { try { pb.registerTopic(topic, webSubHubPubUrl); } catch (WebSubClientException e) { - logger.info("Topic already registered: {}", e.getMessage()); + log.info("Topic already registered: {}", e.getMessage()); } } @@ -105,7 +103,7 @@ public void unRegisterTopic(String topic) { try { pb.unregisterTopic(topic, webSubHubPubUrl); } catch (WebSubClientException e) { - logger.info("Topic already unregistered: {}", e.getMessage()); + log.info("Topic already unregistered: {}", e.getMessage()); } } diff --git a/src/test/resources/responses/InjiConfig.json b/src/test/resources/responses/InjiConfig.json index c2d95737..f4590fd9 100644 --- a/src/test/resources/responses/InjiConfig.json +++ b/src/test/resources/responses/InjiConfig.json @@ -1,8 +1,4 @@ { - "id": "mosip.inji.properties", - "version": "v1", - "str": null, - "metadata": null, "response": { "allowedAuthType": "demo,otp,bio-Finger,bio-Iris,bio-Face", "allowedEkycAuthType": "demo,otp,bio-Finger,bio-Iris,bio-Face",