aboutsummaryrefslogtreecommitdiff
path: root/id/server/idserverlib/src/main/java/at
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/idserverlib/src/main/java/at')
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/advancedlogging/StatisticLogger.java150
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/servlet/AuthServlet.java6
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java38
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/DispatcherServlet.java14
4 files changed, 193 insertions, 15 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/advancedlogging/StatisticLogger.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/advancedlogging/StatisticLogger.java
new file mode 100644
index 000000000..18d0748af
--- /dev/null
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/advancedlogging/StatisticLogger.java
@@ -0,0 +1,150 @@
+package at.gv.egovernment.moa.id.advancedlogging;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.Date;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+
+import org.apache.commons.lang3.StringEscapeUtils;
+
+import at.gv.e_government.reference.namespace.mandates._20040701_.Mandate;
+import at.gv.egovernment.moa.id.auth.data.AuthenticationSession;
+import at.gv.egovernment.moa.id.commons.db.StatisticLogDBUtils;
+import at.gv.egovernment.moa.id.commons.db.dao.statistic.StatisticLog;
+import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException;
+import at.gv.egovernment.moa.id.config.ConfigurationException;
+import at.gv.egovernment.moa.id.config.auth.AuthConfigurationProvider;
+import at.gv.egovernment.moa.id.moduls.IRequest;
+import at.gv.egovernment.moa.id.util.client.mis.simple.MISMandate;
+import at.gv.egovernment.moa.logging.Logger;
+import at.gv.egovernment.moa.util.MiscUtil;
+
+public class StatisticLogger {
+
+ private static StatisticLogger instance;
+
+ private boolean isAktive = false;
+
+ public static StatisticLogger getInstance() {
+ if (instance == null)
+ instance = new StatisticLogger();
+
+ return instance;
+ }
+
+ private StatisticLogger() {
+ try {
+ AuthConfigurationProvider config = AuthConfigurationProvider.getInstance();
+
+ if (config != null)
+ isAktive = config.isAdvancedLoggingActive();
+
+ } catch (ConfigurationException e) {
+ Logger.error("StatisticLogger can not be inizialized", e);
+ }
+ }
+
+ public void logSuccessOperation(IRequest protocolRequest, AuthenticationSession moasession, boolean isSSOSession) {
+
+ if ( isAktive && protocolRequest != null && moasession != null) {
+ StatisticLog dblog = new StatisticLog();
+
+ //set actual date and time
+ dblog.setTimestamp(new Date());
+
+ //log basic AuthInformation
+ dblog.setBkuurl(moasession.getBkuURL());
+ dblog.setOaurlprefix(protocolRequest.getOAURL());
+ dblog.setProtocoltype(protocolRequest.requestedModule());
+ dblog.setProtocolsubtype(protocolRequest.requestedAction());
+ dblog.setSsosession(isSSOSession);
+ dblog.setBusinessservice(moasession.getBusinessService());
+
+
+ //log MandateInforamtion
+ if (moasession.getUseMandate()) {
+ dblog.setMandatelogin(moasession.getUseMandate());
+
+ MISMandate mandate = moasession.getMISMandate();
+ if (mandate != null) {
+
+ if (MiscUtil.isNotEmpty(mandate.getProfRep()))
+ dblog.setMandatetype(mandate.getProfRep());
+
+ else {
+ try {
+ InputStream is = new ByteArrayInputStream(mandate.getMandate());
+
+ JAXBContext jc = JAXBContext.newInstance(Mandate.class);
+ Unmarshaller u = jc.createUnmarshaller();
+ Object mismandateobj = u.unmarshal(is);
+
+ if (mismandateobj != null && mismandateobj instanceof Mandate) {
+ Mandate mismandate = (Mandate) mismandateobj;
+ dblog.setMandatetype(mismandate.getAnnotation());
+
+ } else {
+ Logger.warn("Advancted logging can not unmarshall MISMandate");
+ }
+
+ } catch (JAXBException e) {
+ Logger.warn("Advancted logging can not parse mandate.", e);
+ }
+ }
+ }
+ }
+
+ try {
+ StatisticLogDBUtils.saveOrUpdate(dblog);
+
+ } catch (MOADatabaseException e) {
+ Logger.warn("Statistic Log can not be stored into Database", e);
+ }
+ }
+ }
+
+ public void logErrorOperation(String errorMessage) {
+ if ( isAktive && MiscUtil.isNotEmpty(errorMessage) ) {
+ StatisticLog dblog = new StatisticLog();
+
+ //set actual date and time
+ dblog.setTimestamp(new Date());
+
+ dblog.setErrormessage(StringEscapeUtils.escapeXml(errorMessage));
+
+ try {
+ StatisticLogDBUtils.saveOrUpdate(dblog);
+
+ } catch (MOADatabaseException e) {
+ Logger.warn("Statistic Log can not be stored into Database", e);
+ }
+ }
+
+ }
+
+ public void logErrorOperation(Throwable throwable, IRequest errorRequest) {
+
+ if (isAktive && throwable != null && errorRequest != null) {
+ StatisticLog dblog = new StatisticLog();
+
+ //set actual date and time
+ dblog.setTimestamp(new Date());
+
+ dblog.setOaurlprefix(errorRequest.getOAURL());
+ dblog.setProtocoltype(errorRequest.requestedModule());
+ dblog.setProtocolsubtype(errorRequest.requestedAction());
+ dblog.setErrormessage(StringEscapeUtils.escapeXml(throwable.getMessage()));
+
+ try {
+ StatisticLogDBUtils.saveOrUpdate(dblog);
+
+ } catch (MOADatabaseException e) {
+ Logger.warn("Statistic Log can not be stored into Database", e);
+ }
+ }
+ }
+
+}
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/servlet/AuthServlet.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/servlet/AuthServlet.java
index 022f21491..551af43c3 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/servlet/AuthServlet.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/servlet/AuthServlet.java
@@ -46,6 +46,7 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import at.gv.egovernment.moa.id.AuthenticationException;
+import at.gv.egovernment.moa.id.advancedlogging.StatisticLogger;
import at.gv.egovernment.moa.id.auth.MOAIDAuthConstants;
import at.gv.egovernment.moa.id.auth.WrongParametersException;
import at.gv.egovernment.moa.id.config.ConfigurationException;
@@ -101,6 +102,11 @@ public class AuthServlet extends HttpServlet implements MOAIDAuthConstants {
req.setAttribute("LogLevel", "debug");
}
+
+ StatisticLogger logger = StatisticLogger.getInstance();
+ logger.logErrorOperation(errorMessage);
+
+
// forward this to errorpage-auth.jsp where the HTML error page is
// generated
ServletContext context = getServletContext();
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java
index e87d360f2..f2b068568 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java
@@ -56,6 +56,7 @@ import at.gv.egovernment.moa.id.auth.AuthenticationServer;
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.StatisticLogDBUtils;
import at.gv.egovernment.moa.id.commons.db.dao.config.AuthComponentGeneral;
import at.gv.egovernment.moa.id.commons.db.dao.config.ChainingModes;
import at.gv.egovernment.moa.id.commons.db.dao.config.Contact;
@@ -81,6 +82,7 @@ import at.gv.egovernment.moa.id.commons.db.dao.session.AssertionStore;
import at.gv.egovernment.moa.id.commons.db.dao.session.AuthenticatedSessionStore;
import at.gv.egovernment.moa.id.commons.db.dao.session.OASessionStore;
import at.gv.egovernment.moa.id.commons.db.dao.session.OldSSOSessionIDStore;
+import at.gv.egovernment.moa.id.commons.db.dao.statistic.StatisticLog;
import at.gv.egovernment.moa.id.config.legacy.BuildFromLegacyConfig;
import at.gv.egovernment.moa.id.config.ConfigurationException;
import at.gv.egovernment.moa.id.config.ConfigurationProvider;
@@ -272,7 +274,6 @@ public class AuthConfigurationProvider extends ConfigurationProvider {
fis = new FileInputStream(propertiesFile);
props.load(fis);
- //TODO: maybe some general hibnerate config!!!
// read MOAID Session Hibernate properties
Properties moaSessionProp = new Properties();
for (Object key : props.keySet()) {
@@ -292,6 +293,16 @@ public class AuthConfigurationProvider extends ConfigurationProvider {
configProp.put(propertyName, props.get(key.toString()));
}
}
+
+ // read advanced logging properties
+ Properties statisticProps = new Properties();
+ for (Object key : props.keySet()) {
+ String propPrefix = "advancedlogging.";
+ if (key.toString().startsWith(propPrefix+"hibernate")) {
+ String propertyName = key.toString().substring(propPrefix.length());
+ statisticProps.put(propertyName, props.get(key.toString()));
+ }
+ }
// initialize hibernate
synchronized (AuthConfigurationProvider.class) {
@@ -308,6 +319,16 @@ public class AuthConfigurationProvider extends ConfigurationProvider {
config.addProperties(moaSessionProp);
MOASessionDBUtils.initHibernate(config, moaSessionProp);
+ //initial advanced logging
+ if (isAdvancedLoggingActive()) {
+ Logger.info("Advanced statistic log is activated, starting initialization process ...");
+ Configuration statisticconfig = new Configuration();
+ statisticconfig.addAnnotatedClass(StatisticLog.class);
+ statisticconfig.addProperties(statisticProps);
+ StatisticLogDBUtils.initHibernate(statisticconfig, statisticProps);
+ Logger.info("Advanced statistic log is initialized.");
+ }
+
}
Logger.trace("Hibernate initialization finished.");
@@ -864,10 +885,7 @@ public class AuthConfigurationProvider extends ConfigurationProvider {
public boolean isIdentityLinkResigning() {
String prop = props.getProperty("configuration.resignidentitylink.active", "false");
- if (Boolean.valueOf(prop))
- return true;
- else
- return false;
+ return Boolean.valueOf(prop);
}
public String getIdentityLinkResigningKey() {
@@ -880,10 +898,7 @@ public class AuthConfigurationProvider extends ConfigurationProvider {
public boolean isMonitoringActive() {
String prop = props.getProperty("configuration.monitoring.active", "false");
- if (Boolean.valueOf(prop))
- return true;
- else
- return false;
+ return Boolean.valueOf(prop);
}
public String getTestIdentityLinkURL() {
@@ -896,10 +911,7 @@ public class AuthConfigurationProvider extends ConfigurationProvider {
public boolean isAdvancedLoggingActive() {
String prop = props.getProperty("configuration.advancedlogging.active", "false");
- if (Boolean.valueOf(prop))
- return true;
- else
- return false;
+ return Boolean.valueOf(prop);
}
/**
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/DispatcherServlet.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/DispatcherServlet.java
index db6564d5a..75695d2db 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/DispatcherServlet.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/DispatcherServlet.java
@@ -20,6 +20,7 @@ import javax.swing.ListModel;
import at.gv.egovernment.moa.id.AuthenticationException;
import at.gv.egovernment.moa.id.MOAIDException;
+import at.gv.egovernment.moa.id.advancedlogging.StatisticLogger;
import at.gv.egovernment.moa.id.auth.MOAIDAuthInitializer;
import at.gv.egovernment.moa.id.auth.WrongParametersException;
import at.gv.egovernment.moa.id.auth.data.AuthenticationSession;
@@ -130,8 +131,14 @@ public class DispatcherServlet extends AuthServlet{
.getModuleByPath(errorRequest
.requestedModule());
if (handlingModule != null) {
+
if (handlingModule.generateErrorMessage(
throwable, req, resp, errorRequest)) {
+
+ //log Error Message
+ StatisticLogger logger = StatisticLogger.getInstance();
+ logger.logErrorOperation(throwable, errorRequest);
+
return;
}
}
@@ -154,7 +161,7 @@ public class DispatcherServlet extends AuthServlet{
handleErrorNoRedirect("UNKOWN ERROR DETECTED!", null, req,
resp);
}
-
+
return;
}
}
@@ -457,7 +464,10 @@ public class DispatcherServlet extends AuthServlet{
authmanager.logout(req, resp, moasessionID);
}
- //authmanager.logout(req, resp);
+ //Advanced statistic logging
+ StatisticLogger logger = StatisticLogger.getInstance();
+ logger.logSuccessOperation(protocolRequest, moasession, isSSOSession);
+
}
} catch (Throwable e) {