Skip to content

Commit

Permalink
enabling certificate and claims only when enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
holashchand committed Sep 6, 2023
1 parent 9f2c1ee commit 17c824a
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 19 deletions.
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;

Expand Down Expand Up @@ -509,8 +511,8 @@ public ResponseEntity<Object> 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 {
Expand Down Expand Up @@ -817,7 +819,7 @@ public ResponseEntity<Object> 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);
Expand Down Expand Up @@ -849,8 +851,8 @@ public ResponseEntity<Object> getSignedEntityByToken(@PathVariable String entity
public ResponseEntity<Object> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Object> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,4 @@ public String removeEntitySignature(String entityNodeType, ObjectNode node) {
}
return entitySignatureUUID;
}

public static ResponseEntity<Object> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions java/registry/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 17c824a

Please sign in to comment.