aboutsummaryrefslogtreecommitdiff
path: root/id/server/idserverlib/src/main
diff options
context:
space:
mode:
authorThomas Lenz <tlenz@iaik.tugraz.at>2013-09-09 11:21:10 +0200
committerThomas Lenz <tlenz@iaik.tugraz.at>2013-09-09 11:21:10 +0200
commit73da4672b980e97555ebe60d0059d86b2e5bdb74 (patch)
treeb6444140d96293d271c4988368bf1d48c78837df /id/server/idserverlib/src/main
parent3345275ad40fefb928908199b666d959bf5fb362 (diff)
downloadmoa-id-spss-73da4672b980e97555ebe60d0059d86b2e5bdb74.tar.gz
moa-id-spss-73da4672b980e97555ebe60d0059d86b2e5bdb74.tar.bz2
moa-id-spss-73da4672b980e97555ebe60d0059d86b2e5bdb74.zip
add MonitoringServlet for MOA-ID-Auth
- add two TestModules - test Database connectivity - test IdentityLink verification (inkl. MOA-SP test)
Diffstat (limited to 'id/server/idserverlib/src/main')
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/servlet/MonitoringServlet.java66
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/monitoring/DatabaseTestModule.java83
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/monitoring/IdentityLinkTestModule.java67
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/monitoring/TestManager.java47
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/monitoring/TestModuleInterface.java8
5 files changed, 271 insertions, 0 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/servlet/MonitoringServlet.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/servlet/MonitoringServlet.java
new file mode 100644
index 000000000..4ba282dc1
--- /dev/null
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/servlet/MonitoringServlet.java
@@ -0,0 +1,66 @@
+package at.gv.egovernment.moa.id.auth.servlet;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import at.gv.egovernment.moa.id.config.ConfigurationException;
+import at.gv.egovernment.moa.id.config.auth.AuthConfigurationProvider;
+import at.gv.egovernment.moa.id.monitoring.TestManager;
+import at.gv.egovernment.moa.logging.Logger;
+import at.gv.egovernment.moa.util.MiscUtil;
+
+public class MonitoringServlet extends AuthServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+
+ try {
+ AuthConfigurationProvider config = AuthConfigurationProvider.getInstance();
+
+ if (config.isMonitoringActive()) {
+ Logger.debug("Monitoring Servlet received request");
+
+ TestManager tests = TestManager.getInstance();
+
+
+ List<String> error = tests.executeTests();
+ if (error != null && error.size() > 0) {
+ createErrorMessage(req, resp, error);
+
+ } else {
+ resp.setStatus(HttpServletResponse.SC_OK);
+ Logger.info("Monitoring Servlet finished without errors");
+ }
+
+ }
+
+ } catch (ConfigurationException e) {
+ createErrorMessage(req, resp, Arrays.asList(e.getMessage()));
+ }
+ }
+
+ private void createErrorMessage(HttpServletRequest req, HttpServletResponse resp, List<String> errorMessage) {
+ Logger.warn("Monitoring Servlet found some Error: " + errorMessage);
+ resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ resp.setContentType("text/html;charset=UTF-8");
+ PrintWriter out;
+ try {
+ out = new PrintWriter(resp.getOutputStream());
+ for (String error : errorMessage)
+ out.write(error + "<br>");
+ out.flush();
+
+ } catch (IOException e) {
+ Logger.warn("Internal Monitoring Servlet Error. ", e);
+ }
+ }
+}
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/monitoring/DatabaseTestModule.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/monitoring/DatabaseTestModule.java
new file mode 100644
index 000000000..24261780a
--- /dev/null
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/monitoring/DatabaseTestModule.java
@@ -0,0 +1,83 @@
+package at.gv.egovernment.moa.id.monitoring;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.hibernate.Query;
+import org.hibernate.Session;
+
+import at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead;
+import at.gv.egovernment.moa.id.commons.db.ConfigurationDBUtils;
+import at.gv.egovernment.moa.id.commons.db.MOASessionDBUtils;
+import at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration;
+import at.gv.egovernment.moa.id.commons.db.dao.session.AssertionStore;
+import at.gv.egovernment.moa.id.config.auth.AuthConfigurationProvider;
+import at.gv.egovernment.moa.logging.Logger;
+import at.gv.egovernment.moa.util.MiscUtil;
+
+public class DatabaseTestModule implements TestModuleInterface{
+
+ public List<String> performTests() throws Exception {
+ Logger.trace("Start MOA-ID Database Test.");
+
+ List<String> errors = new ArrayList<String>();
+
+ AuthConfigurationProvider config = AuthConfigurationProvider.getInstance();
+
+ String error = testMOAConfigurationDatabase();
+ if (MiscUtil.isNotEmpty(error))
+ errors.add(error);
+
+ error = testMOASessionDatabase();
+ if (MiscUtil.isNotEmpty(error))
+ errors.add(error);
+
+ if (config.isAdvancedLoggingActive()) {
+ error = testMOAAdvancedLoggingDatabase();
+ if (MiscUtil.isNotEmpty(error))
+ errors.add(error);
+ }
+
+ return errors;
+ }
+
+
+ private String testMOASessionDatabase() throws Exception{
+ Logger.trace("Start Test: MOASessionDatabase");
+
+ Date expioredate = new Date(new Date().getTime() - 120);
+
+ List<AssertionStore> results;
+ Session session = MOASessionDBUtils.getCurrentSession();
+
+ synchronized (session) {
+ session.beginTransaction();
+ Query query = session.getNamedQuery("getAssertionWithTimeOut");
+ query.setTimestamp("timeout", expioredate);
+ results = query.list();
+ session.getTransaction().commit();
+ }
+
+ Logger.trace("Finish Test: MOASessionDatabase");
+ return null;
+ }
+
+ private String testMOAConfigurationDatabase() throws Exception{
+
+ MOAIDConfiguration moaidconfig = ConfigurationDBRead.getMOAIDConfiguration();
+ ConfigurationDBUtils.closeSession();
+
+ if (moaidconfig == null)
+ return ("MOA-ID 2.x configuration can not be loaded from Database.");
+
+ return null;
+ }
+
+ private String testMOAAdvancedLoggingDatabase() {
+
+ //TODO: insert advanced Logging Database Tests
+
+ return null;
+ }
+}
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/monitoring/IdentityLinkTestModule.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/monitoring/IdentityLinkTestModule.java
new file mode 100644
index 000000000..9b81d197f
--- /dev/null
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/monitoring/IdentityLinkTestModule.java
@@ -0,0 +1,67 @@
+package at.gv.egovernment.moa.id.monitoring;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.List;
+
+import org.w3c.dom.Element;
+
+import at.gv.egovernment.moa.id.auth.builder.VerifyXMLSignatureRequestBuilder;
+import at.gv.egovernment.moa.id.auth.data.IdentityLink;
+import at.gv.egovernment.moa.id.auth.data.VerifyXMLSignatureResponse;
+import at.gv.egovernment.moa.id.auth.invoke.SignatureVerificationInvoker;
+import at.gv.egovernment.moa.id.auth.parser.IdentityLinkAssertionParser;
+import at.gv.egovernment.moa.id.auth.parser.InfoboxReadResponseParser;
+import at.gv.egovernment.moa.id.auth.parser.VerifyXMLSignatureResponseParser;
+import at.gv.egovernment.moa.id.auth.validator.IdentityLinkValidator;
+import at.gv.egovernment.moa.id.auth.validator.VerifyXMLSignatureResponseValidator;
+import at.gv.egovernment.moa.id.config.auth.AuthConfigurationProvider;
+import at.gv.egovernment.moa.logging.Logger;
+import at.gv.egovernment.moa.util.MiscUtil;
+
+public class IdentityLinkTestModule implements TestModuleInterface {
+
+ public List<String> performTests() throws Exception{
+ Logger.trace("Start MOA-ID IdentityLink Test");
+
+ AuthConfigurationProvider config = AuthConfigurationProvider.getInstance();
+
+ String idlurl = config.getTestIdentityLinkURL();
+
+ if (MiscUtil.isNotEmpty(idlurl)) {
+ File idlfile = new File(idlurl);
+ InputStream idlstream = new FileInputStream(idlfile);
+
+ IdentityLink identityLink = new IdentityLinkAssertionParser(idlstream).parseIdentityLink();
+
+ IdentityLinkValidator.getInstance().validate(identityLink);
+ // builds a <VerifyXMLSignatureRequest> for a call of MOA-SP
+ Element domVerifyXMLSignatureRequest = new VerifyXMLSignatureRequestBuilder()
+ .build(identityLink, config
+ .getMoaSpIdentityLinkTrustProfileID());
+
+ // invokes the call
+ Element domVerifyXMLSignatureResponse = new SignatureVerificationInvoker()
+ .verifyXMLSignature(domVerifyXMLSignatureRequest);
+ // parses the <VerifyXMLSignatureResponse>
+ VerifyXMLSignatureResponse verifyXMLSignatureResponse = new VerifyXMLSignatureResponseParser(
+ domVerifyXMLSignatureResponse).parseData();
+
+ VerifyXMLSignatureResponseValidator.getInstance().validate(
+ verifyXMLSignatureResponse,
+ config.getIdentityLinkX509SubjectNames(),
+ VerifyXMLSignatureResponseValidator.CHECK_IDENTITY_LINK,
+ true);
+
+ Logger.trace("Finished MOA-ID IdentityLink Test without errors");
+
+ return null;
+
+ } else {
+ Logger.warn("MOA-ID IdentityLink Test can not performed without IdentityLink. Insert IdentityLink file to MOA-ID configuration");
+ return null;
+ }
+ }
+
+}
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/monitoring/TestManager.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/monitoring/TestManager.java
new file mode 100644
index 000000000..bbebbed57
--- /dev/null
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/monitoring/TestManager.java
@@ -0,0 +1,47 @@
+package at.gv.egovernment.moa.id.monitoring;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import at.gv.egovernment.moa.logging.Logger;
+
+public class TestManager {
+
+ private static TestManager instance;
+
+ private List<TestModuleInterface> tests = new ArrayList<TestModuleInterface>();
+
+ public static TestManager getInstance() {
+ if (instance == null)
+ instance = new TestManager();
+
+ return instance;
+ }
+
+ private TestManager() {
+ tests.add(new DatabaseTestModule());
+ tests.add(new IdentityLinkTestModule());
+ }
+
+ public List<String> executeTests() {
+ Logger.debug("Start MOA-ID-Auth testing");
+
+
+ List<String> errors;
+
+ for (TestModuleInterface test : tests) {
+ try {
+ errors = test.performTests();
+ if (errors != null && errors.size() > 0)
+ return errors;
+
+ } catch (Exception e) {
+ Logger.warn("General Testing Eception during Test " + test.getClass() + ": ", e);
+ return Arrays.asList(e.getMessage());
+ }
+ }
+
+ return null;
+ }
+}
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/monitoring/TestModuleInterface.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/monitoring/TestModuleInterface.java
new file mode 100644
index 000000000..f4e94fee0
--- /dev/null
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/monitoring/TestModuleInterface.java
@@ -0,0 +1,8 @@
+package at.gv.egovernment.moa.id.monitoring;
+
+import java.util.List;
+
+public interface TestModuleInterface {
+
+ public List<String> performTests() throws Exception;
+}