From 62cb461196bae02c9898fe62d2bf8be06d7e1dae Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Thu, 22 Apr 2021 09:09:16 +0000 Subject: [PATCH] [Trunk | Admin Tools Library]: 1. AdminToolsLibraryCheckDeployController.java: a. In "hello()" method added @RequestMapping (except for existing ""), "/health_check". b. Added method "checkEverything()" (/health_chech/advanced) only accessible by PORTAL ADMINS which checks connection with db and prints properties. 2. PortalPage.java: Added default value "false" for position fields (top, bottom, left, right). --- ...dminToolsLibraryCheckDeployController.java | 35 ++++++++++++++++++- .../entities/fullEntities/PortalPage.java | 8 ++--- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/dnetlib/uoaadmintoolslibrary/controllers/AdminToolsLibraryCheckDeployController.java b/src/main/java/eu/dnetlib/uoaadmintoolslibrary/controllers/AdminToolsLibraryCheckDeployController.java index b90a383..c53c31e 100644 --- a/src/main/java/eu/dnetlib/uoaadmintoolslibrary/controllers/AdminToolsLibraryCheckDeployController.java +++ b/src/main/java/eu/dnetlib/uoaadmintoolslibrary/controllers/AdminToolsLibraryCheckDeployController.java @@ -1,21 +1,54 @@ package eu.dnetlib.uoaadmintoolslibrary.controllers; +import com.mongodb.BasicDBObject; +import com.mongodb.CommandResult; +import com.mongodb.DBObject; +import eu.dnetlib.uoaadmintoolslibrary.configuration.properties.GoogleConfig; +import eu.dnetlib.uoaadmintoolslibrary.configuration.properties.MailConfig; import org.apache.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import java.util.HashMap; +import java.util.Map; + @RestController @CrossOrigin(origins = "*") @RequestMapping("/admin-tools-library") public class AdminToolsLibraryCheckDeployController { + @Autowired + private MailConfig mailConfig; + + @Autowired + private GoogleConfig googleConfig; + private final Logger log = Logger.getLogger(this.getClass()); - @RequestMapping(value = "", method = RequestMethod.GET) + @RequestMapping(value = {"", "/health_check"}, method = RequestMethod.GET) public String hello() { log.debug("Hello from uoa-admin-tools-library!"); return "Hello from uoa-admin-tools-library!"; } + + @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)") + @RequestMapping(value = "/health_check/advanced", method = RequestMethod.GET) + public Map checkEverything() { + Map response = new HashMap<>(); + response.put("admintoolslibrary.mail.auth",mailConfig.getAuth()); + response.put("admintoolslibrary.mail.from", mailConfig.getAuth()); + response.put("admintoolslibrary.mail.host", mailConfig.getHost()); + response.put("admintoolslibrary.mail.port", mailConfig.getPort()); + response.put("admintoolslibrary.mail.username", mailConfig.getUsername() == null ? null : "[unexposed value]"); + response.put("admintoolslibrary.mail.password", mailConfig.getPassword() == null ? null : "[unexposed value]"); + response.put("admintoolslibrary.google.secret", googleConfig.getSecret() == null ? null : "[unexposed value]"); + +// response.put("Define also", "admintoolslibrary.mail.username, " + +// "admintoolslibrary.mail.password, admintoolslibrary.google.secret"); + return response; + } } diff --git a/src/main/java/eu/dnetlib/uoaadmintoolslibrary/entities/fullEntities/PortalPage.java b/src/main/java/eu/dnetlib/uoaadmintoolslibrary/entities/fullEntities/PortalPage.java index 6970c84..80764ee 100644 --- a/src/main/java/eu/dnetlib/uoaadmintoolslibrary/entities/fullEntities/PortalPage.java +++ b/src/main/java/eu/dnetlib/uoaadmintoolslibrary/entities/fullEntities/PortalPage.java @@ -27,10 +27,10 @@ public class PortalPage { // private Boolean openaire; // Posiitions where help texts are allowed for this page - private Boolean top; - private Boolean bottom; - private Boolean left; - private Boolean right; + private Boolean top = false; + private Boolean bottom = false; + private Boolean left = false; + private Boolean right = false; public PortalPage() {}