From a433efb6ed9cbc9ce2e68700e68af586f3ad4435 Mon Sep 17 00:00:00 2001 From: Gcolon021 <34667267+Gcolon021@users.noreply.github.com> Date: Tue, 1 Oct 2024 15:47:58 -0400 Subject: [PATCH] Check for open access enabled (#218) --- .../dbmi/avillach/auth/rest/OpenAccessController.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pic-sure-auth-services/src/main/java/edu/harvard/hms/dbmi/avillach/auth/rest/OpenAccessController.java b/pic-sure-auth-services/src/main/java/edu/harvard/hms/dbmi/avillach/auth/rest/OpenAccessController.java index 96a6c105f..4d265be12 100644 --- a/pic-sure-auth-services/src/main/java/edu/harvard/hms/dbmi/avillach/auth/rest/OpenAccessController.java +++ b/pic-sure-auth-services/src/main/java/edu/harvard/hms/dbmi/avillach/auth/rest/OpenAccessController.java @@ -3,6 +3,7 @@ import edu.harvard.hms.dbmi.avillach.auth.service.impl.authorization.AuthorizationService; import io.swagger.v3.oas.annotations.Parameter; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; @@ -15,16 +16,22 @@ public class OpenAccessController { private final AuthorizationService authorizationService; + private final boolean openIdpProviderIsEnabled; @Autowired - public OpenAccessController(AuthorizationService authorizationService) { + public OpenAccessController(AuthorizationService authorizationService, @Value("${open.idp.provider.is.enabled}") boolean openIdpProviderIsEnabled) { this.authorizationService = authorizationService; + this.openIdpProviderIsEnabled = openIdpProviderIsEnabled; } @RequestMapping(value = "/validate", produces = "application/json") public ResponseEntity validate(@Parameter(required = true, description = "A JSON object that at least" + " include a user the token for validation") @RequestBody Map inputMap) { + if (!openIdpProviderIsEnabled) { + return ResponseEntity.ok(false); + } + boolean isValid = authorizationService.openAccessRequestIsValid(inputMap); return ResponseEntity.ok(isValid); }