Skip to content

Commit

Permalink
[INJIWEB-758] : swagger config update
Browse files Browse the repository at this point in the history
Signed-off-by: Vijay <[email protected]>
  • Loading branch information
vijay151096 committed Sep 30, 2024
1 parent 939e5f7 commit 6d6d146
Show file tree
Hide file tree
Showing 63 changed files with 634 additions and 419 deletions.
8 changes: 4 additions & 4 deletions src/main/java/io/mosip/mimoto/MimotoServiceApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -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"),
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/io/mosip/mimoto/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,7 +23,6 @@
@EnableMethodSecurity
@Order(1)
public class Config {
private Logger logger = LoggerUtil.getLogger(Config.class);

@Value("${mosipbox.public.url}")
private String baseUrl;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,6 +17,7 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;

@Slf4j
@Component
public class IssuersValidationConfig implements ApplicationRunner {
@Autowired
Expand All @@ -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> errors = new AtomicReference<>();
Expand All @@ -47,11 +46,11 @@ public void run(ApplicationArguments args) throws ApiNotAccessibleException, IOE
String[] tokenEndpointArray = issuerDTO.getToken_endpoint().split("/");
Set<String> 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);
Expand All @@ -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");
}
}
6 changes: 3 additions & 3 deletions src/main/java/io/mosip/mimoto/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
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;
import org.springframework.beans.factory.annotation.Autowired;
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;

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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": []
}
""";
}
Original file line number Diff line number Diff line change
@@ -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" ;

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -35,6 +35,7 @@ public class AttestationServiceController {
* @param attestation
* @return
*/
@Operation(hidden = true)
@PostMapping(path = "/offline/verify", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> processOffline(@RequestBody String attestation)
{
Expand All @@ -45,7 +46,7 @@ public ResponseEntity<Object> processOffline(@RequestBody String attestation)
GenericResponseDTO responseDTO = new GenericResponseDTO();
responseDTO.setStatus("Error");
responseDTO.setMessage(e.getMessage());

return new ResponseEntity<>(responseDTO, HttpStatus.OK);
}
}
Expand All @@ -56,6 +57,7 @@ public ResponseEntity<Object> processOffline(@RequestBody String attestation)
* @param attestation
* @return
*/
@Operation(hidden = true)
@PostMapping(path = "/online/verify", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> processOnline(@RequestBody String attestation)
{
Expand All @@ -66,7 +68,7 @@ public ResponseEntity<Object> processOnline(@RequestBody String attestation)
GenericResponseDTO responseDTO = new GenericResponseDTO();
responseDTO.setStatus("Error");
responseDTO.setMessage(e.getMessage());

return new ResponseEntity<>(responseDTO, HttpStatus.OK);
}
}
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/io/mosip/mimoto/controller/CommonInjiController.java
Original file line number Diff line number Diff line change
@@ -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<String, String> 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<Object> getAllProperties() {
public ResponseEntity<ResponseWrapper<Map<String, String>>> getAllProperties() {
ResponseWrapper<Map<String, String>> 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);
}
Expand Down
Loading

0 comments on commit 6d6d146

Please sign in to comment.