diff --git a/docker-compose.yml b/docker-compose.yml index fc051f857..42d713bc1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -55,11 +55,13 @@ services: - sunbird_sso_admin_client_id=${KEYCLOAK_ADMIN_CLIENT_ID-admin-api} - sunbird_sso_client_id=${KEYCLOAK_CLIENT_ID-registry-frontend} - sunbird_sso_admin_client_secret=${KEYCLOAK_SECRET} + - claims_enabled=false - claims_url=http://claim-ms:8082 + - signature_enabled=false - sign_url=http://certificate-signer:8079/sign - verify_url=http://certificate-signer:8079/verify - sign_health_check_url=http://certificate-signer:8079/health - - signature_enabled=true + - certificate_enabled=false - pdf_url=http://certificate-api:8078/api/v1/certificatePDF - certificate_health_check_url=http://certificate-api:8078/health - template_base_url=http://registry:8081/api/v1/templates/ #Looks for certificate templates for pdf copy of the signed certificate diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/controller/RegistryClaimsController.java b/java/registry/src/main/java/dev/sunbirdrc/registry/controller/RegistryClaimsController.java index edad915bf..9e1135178 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/controller/RegistryClaimsController.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/controller/RegistryClaimsController.java @@ -16,6 +16,7 @@ import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -29,6 +30,7 @@ import static dev.sunbirdrc.registry.middleware.util.Constants.USER_ID; @RestController +@ConditionalOnProperty(name = "claims.enabled", havingValue = "true") public class RegistryClaimsController extends AbstractController{ private static final Logger logger = LoggerFactory.getLogger(RegistryClaimsController.class); private final ClaimRequestClient claimRequestClient; diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/controller/RegistryEntityController.java b/java/registry/src/main/java/dev/sunbirdrc/registry/controller/RegistryEntityController.java index ae143af8d..6a9075f2c 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/controller/RegistryEntityController.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/controller/RegistryEntityController.java @@ -49,8 +49,8 @@ import java.util.*; import static dev.sunbirdrc.registry.Constants.*; +import static dev.sunbirdrc.registry.helper.RegistryHelper.ServiceNotEnabledResponse; import static dev.sunbirdrc.registry.middleware.util.Constants.ENTITY_TYPE; -import static dev.sunbirdrc.registry.service.SignatureHelper.SignatureNotEnabledResponse; @RestController public class RegistryEntityController extends AbstractController { @@ -60,6 +60,8 @@ public class RegistryEntityController extends AbstractController { @Value("${signature.enabled}") private boolean signatureEnabled; + @Value("${certificate.enabled}") + private boolean certificateEnabled; @Autowired(required = false) private ICertificateService certificateService; @@ -509,8 +511,8 @@ public ResponseEntity getEntityType(@PathVariable String entityName, @RequestHeader(required = false) String viewTemplateId) { ResponseParams responseParams = new ResponseParams(); Response response ; - if (!signatureEnabled) { - return SignatureNotEnabledResponse(null, responseParams); + if (!certificateEnabled) { + return ServiceNotEnabledResponse("Certificate service",null, responseParams); } if (registryHelper.doesEntityOperationRequireAuthorization(entityName) && securityEnabled) { try { @@ -817,7 +819,7 @@ public ResponseEntity getSignedEntityByToken(@PathVariable String entity ResponseParams responseParams = new ResponseParams(); Response response = new Response(Response.API_ID.SEARCH, "OK", responseParams); if (!signatureEnabled) { - return SignatureNotEnabledResponse(response, responseParams); + return ServiceNotEnabledResponse("Signature service", response, responseParams); } try { checkEntityNameInDefinitionManager(entityName); @@ -849,8 +851,8 @@ public ResponseEntity getSignedEntityByToken(@PathVariable String entity public ResponseEntity getAttestationCertificate(HttpServletRequest request, @PathVariable String entityName, @PathVariable String entityId, @PathVariable String attestationName, @PathVariable String attestationId) { ResponseParams responseParams = new ResponseParams(); - if (!signatureEnabled) { - return SignatureNotEnabledResponse(null, responseParams); + if (!certificateEnabled) { + return ServiceNotEnabledResponse("Certificate service", null, responseParams); } try { checkEntityNameInDefinitionManager(entityName); diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/helper/RegistryHelper.java b/java/registry/src/main/java/dev/sunbirdrc/registry/helper/RegistryHelper.java index d05d30ab1..c24b8851c 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/helper/RegistryHelper.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/helper/RegistryHelper.java @@ -55,6 +55,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.lang.Nullable; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; @@ -1232,4 +1234,15 @@ public boolean checkIfCredentialIsRevoked(String signedData) throws Exception { JsonNode searchResponse = searchEntity(searchNode); return searchResponse.get(REVOKED_CREDENTIAL) != null && searchResponse.get(REVOKED_CREDENTIAL).size() > 0; } + + public static ResponseEntity ServiceNotEnabledResponse(String message, Response response, ResponseParams responseParams) { + responseParams.setErrmsg(message + " not enabled!"); + responseParams.setStatus(Response.Status.UNSUCCESSFUL); + if (response != null) { + response.setResponseCode("SERVICE_UNAVAILABLE"); + } else { + response = new Response(Response.API_ID.GET, "SERVICE_UNAVAILABLE", responseParams); + } + return new ResponseEntity<>(response, HttpStatus.SERVICE_UNAVAILABLE); + } } diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/service/SignatureHelper.java b/java/registry/src/main/java/dev/sunbirdrc/registry/service/SignatureHelper.java index 9cdcbd6b5..3dc85c85c 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/service/SignatureHelper.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/service/SignatureHelper.java @@ -155,15 +155,4 @@ public String removeEntitySignature(String entityNodeType, ObjectNode node) { } return entitySignatureUUID; } - - public static ResponseEntity SignatureNotEnabledResponse(Response response, ResponseParams responseParams) { - responseParams.setErrmsg("Signature service not enabled!"); - responseParams.setStatus(Response.Status.UNSUCCESSFUL); - if (response != null) { - response.setResponseCode("SERVICE_UNAVAILABLE"); - } else { - response = new Response(Response.API_ID.GET, "SERVICE_UNAVAILABLE", responseParams); - } - return new ResponseEntity<>(response, HttpStatus.SERVICE_UNAVAILABLE); - } } \ No newline at end of file diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/service/impl/CertificateServiceImpl.java b/java/registry/src/main/java/dev/sunbirdrc/registry/service/impl/CertificateServiceImpl.java index 6c7c0bf7c..f871d8a31 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/service/impl/CertificateServiceImpl.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/service/impl/CertificateServiceImpl.java @@ -26,7 +26,7 @@ import static dev.sunbirdrc.registry.middleware.util.Constants.SUNBIRD_CERTIFICATE_SERVICE_NAME; @Component -@ConditionalOnProperty(name = "signature.enabled", havingValue = "true") +@ConditionalOnProperty(name = "certificate.enabled", havingValue = "true") public class CertificateServiceImpl implements ICertificateService { private final String templateBaseUrl; private final String certificateUrl; diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/util/ClaimRequestClient.java b/java/registry/src/main/java/dev/sunbirdrc/registry/util/ClaimRequestClient.java index b18e4b7b0..5f0102c1d 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/util/ClaimRequestClient.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/util/ClaimRequestClient.java @@ -8,6 +8,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.http.HttpEntity; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpMethod; @@ -18,6 +19,7 @@ import java.util.HashMap; @Component +@ConditionalOnProperty(name = "claims.enabled", havingValue = "true") public class ClaimRequestClient { private static Logger logger = LoggerFactory.getLogger(RegistryController.class); private final String claimRequestUrl; diff --git a/java/registry/src/main/resources/application.yml b/java/registry/src/main/resources/application.yml index 87aa6369d..4ff75516a 100644 --- a/java/registry/src/main/resources/application.yml +++ b/java/registry/src/main/resources/application.yml @@ -211,6 +211,7 @@ signature: name: SignatureShape certificate: + enabled: ${certificate_enabled:true} templateBaseUrl: ${template_base_url:http://localhost:8081/api/v1/templates/} healthCheckURL: ${certificate_health_check_url:http://localhost:8078/health} apiUrl: ${pdf_url:http://localhost:8078/api/v1/certificate} @@ -246,6 +247,7 @@ keycloak-user: # email details should be configured in keycloak realm settings email-actions: ${keycloack_user_email_actions:} claims: + enabled: ${claims_enabled:true} url: ${claims_url:http://localhost:8082} authentication: enabled: ${authentication_enabled:true}