diff options
author | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2018-09-12 12:53:57 +0200 |
---|---|---|
committer | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2018-09-12 12:53:57 +0200 |
commit | 29072690ca2afe6b8282214e4b7aab53337f6f55 (patch) | |
tree | c7a946e87c3f9775ac07abe11ae17624a4cea0b3 /connector/src | |
parent | d1cfa0cf4975387f808de22f99d1c5dc7a515457 (diff) | |
download | National_eIDAS_Gateway-29072690ca2afe6b8282214e4b7aab53337f6f55.tar.gz National_eIDAS_Gateway-29072690ca2afe6b8282214e4b7aab53337f6f55.tar.bz2 National_eIDAS_Gateway-29072690ca2afe6b8282214e4b7aab53337f6f55.zip |
add basic monitoring
Diffstat (limited to 'connector/src')
-rw-r--r-- | connector/src/main/java/at/asitplus/eidas/specific/connector/controller/MonitoringController.java | 176 | ||||
-rw-r--r-- | connector/src/main/resources/specific_eIDAS_connector.beans.xml | 9 |
2 files changed, 184 insertions, 1 deletions
diff --git a/connector/src/main/java/at/asitplus/eidas/specific/connector/controller/MonitoringController.java b/connector/src/main/java/at/asitplus/eidas/specific/connector/controller/MonitoringController.java new file mode 100644 index 00000000..3ec7244d --- /dev/null +++ b/connector/src/main/java/at/asitplus/eidas/specific/connector/controller/MonitoringController.java @@ -0,0 +1,176 @@ +package at.asitplus.eidas.specific.connector.controller; + +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.transform.TransformerFactoryConfigurationError; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.text.StringEscapeUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import at.asitplus.eidas.specific.connector.MSeIDASNodeConstants; +import at.gv.egiz.eaaf.core.api.data.EAAFConstants; +import at.gv.egiz.eaaf.core.api.idp.IConfiguration; +import at.gv.egiz.eaaf.core.api.storage.ITransactionStorage; +import at.gv.egiz.eaaf.core.exceptions.EAAFException; +import at.gv.egiz.eaaf.core.impl.utils.Random; +import at.gv.egiz.eaaf.modules.pvp2.api.metadata.IPVPMetadataBuilderConfiguration; +import at.gv.egiz.eaaf.modules.pvp2.api.metadata.IPVPMetadataConfigurationFactory; +import at.gv.egiz.eaaf.modules.pvp2.impl.builder.PVPMetadataBuilder; +import at.gv.egiz.eaaf.modules.pvp2.impl.utils.AbstractCredentialProvider; + +@Controller +public class MonitoringController { + private static final Logger log = LoggerFactory.getLogger(MonitoringController.class); + + private static final String MESSAGE_OK = "OK"; + private static final String MESSAGE_ERROR = "ERROR"; + + private static final String TEST_STORAGE = "Storage: "; + private static final String TEST_CONFIG = "Config: "; + private static final String TEST_PVPMETADATA = "PVP_metadata: "; + + @Autowired private ITransactionStorage storage; + @Autowired private IConfiguration config; + + @Autowired private PVPMetadataBuilder metadatabuilder; + @Autowired private IPVPMetadataConfigurationFactory configFactory; + private AbstractCredentialProvider pvpIDPCredentials; + + /** + * Sets a specific credential provider for PVP S-Profile IDP component. + * @param pvpIDPCredentials credential provider + */ + public void setPvpIDPCredentials(AbstractCredentialProvider pvpIDPCredentials) { + this.pvpIDPCredentials = pvpIDPCredentials; + + } + + @ExceptionHandler({Throwable.class}) + public void genericExceptionHandler(HttpServletResponse resp, Exception exception) throws IOException { + log.error("Monitoring Servlet receives an error." , exception); + resp.setContentType(EAAFConstants.CONTENTTYPE_HTML_UTF8); + resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + resp.getWriter().write("Reason: " + + StringEscapeUtils.escapeHtml4(StringEscapeUtils.escapeEcmaScript(exception.getMessage()))); + return; + + } + + @RequestMapping(value = {MSeIDASNodeConstants.ENDPOINT_MONITORING_MONITOR}, + method = {RequestMethod.GET} ) + public void startFullTest(HttpServletRequest req, HttpServletResponse resp) throws IOException { + resp.setContentType(EAAFConstants.CONTENTTYPE_HTML_UTF8); + + try { + testConfig(); + testStorage(); + testPVPMetadata(); + resp.setStatus(HttpServletResponse.SC_OK); + resp.getWriter().write(MESSAGE_OK); + + } catch (Exception e) { + resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + resp.getWriter().write(MESSAGE_ERROR); + + } + + + } + + @RequestMapping(value = {MSeIDASNodeConstants.ENDPOINT_MONITORING_VERIFY}, + method = {RequestMethod.GET} ) + + public void startSingleTests(HttpServletRequest req, HttpServletResponse resp) throws IOException { + String result = StringUtils.EMPTY; + try { + result += testConfig() + "<br>"; + } catch (Exception e) { + result += e.getMessage() + "<br>"; + } + + try { + result += testStorage() + "<br>"; + } catch (Exception e) { + result += e.getMessage() + "<br>"; + } + + try { + result += testPVPMetadata() + "<br>"; + } catch (Exception e) { + result += e.getMessage() + "<br>"; + } + + resp.setContentType(EAAFConstants.CONTENTTYPE_HTML_UTF8); + resp.setStatus(HttpServletResponse.SC_OK); + resp.getWriter().write(result); + + } + + private String testStorage( ) throws Exception { + try { + String key = Random.nextHexRandom16(); + String value = Random.nextHexRandom16(); + + storage.put(key, value, -1); + String result = storage.get(key, String.class); + storage.remove(key); + + if (result != null && result.equals(value)) + return TEST_STORAGE + MESSAGE_OK; + else + log.warn("Montioring: TestValue: " + value + " does NOT match in Storage test"); + + } catch (EAAFException e) { + log.warn("Montioring: Can not read/write to storage.", e); + + } + + throw new Exception(TEST_STORAGE + MESSAGE_ERROR); + + } + + private String testConfig( ) throws Exception { + try { + if (config.getFullConfigurationProperties() != null + && config.getFullConfigurationProperties().size() > 0) + return TEST_CONFIG + MESSAGE_OK; + + else + log.warn("Montioring: Can not read from configuration file."); + + } catch (Exception e) { + log.warn("Montioring: Can not read from configuration file.", e); + } + + throw new Exception(TEST_CONFIG + MESSAGE_ERROR); + + } + + private String testPVPMetadata() throws Exception { + try { + //build metadata + IPVPMetadataBuilderConfiguration metadataConfig = + configFactory.generateMetadataBuilderConfiguration( + "http://localhost/monitoring", + pvpIDPCredentials); + metadatabuilder.buildPVPMetadata(metadataConfig); + return TEST_PVPMETADATA + MESSAGE_OK; + + } catch (Exception | TransformerFactoryConfigurationError e) { + log.warn("Monitoring: Has an error in '" + TEST_PVPMETADATA + "': " + e.getMessage(), e); + throw new Exception(TEST_PVPMETADATA + MESSAGE_ERROR, e); + + } + + } + +} diff --git a/connector/src/main/resources/specific_eIDAS_connector.beans.xml b/connector/src/main/resources/specific_eIDAS_connector.beans.xml index 7722b8e8..8756c55f 100644 --- a/connector/src/main/resources/specific_eIDAS_connector.beans.xml +++ b/connector/src/main/resources/specific_eIDAS_connector.beans.xml @@ -16,7 +16,14 @@ <mvc:default-servlet-handler/> <bean id="ProcessEngineSignalController" - class="at.asitplus.eidas.specific.connector.controller.ProcessEngineSignalController"/> + class="at.asitplus.eidas.specific.connector.controller.ProcessEngineSignalController" /> + + <bean id="MonitoringController" + class="at.asitplus.eidas.specific.connector.controller.MonitoringController"> + <property name="pvpIDPCredentials"> + <ref bean="PVPEndPointCredentialProvider" /> + </property> + </bean> <bean id="AuthenticationManager" class="at.asitplus.eidas.specific.connector.auth.AuthenticationManager" /> |