aboutsummaryrefslogtreecommitdiff
path: root/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/advancedlogging/StatisticLogger.java
diff options
context:
space:
mode:
authorThomas Lenz <tlenz@iaik.tugraz.at>2013-10-01 14:18:25 +0200
committerThomas Lenz <tlenz@iaik.tugraz.at>2013-10-01 14:18:25 +0200
commita49bdd53d713a73f706d120f3e386a1ed71ae67e (patch)
tree55160b6d3157e29460c215fa40afccfe5731df5a /id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/advancedlogging/StatisticLogger.java
parent1dbab6b07a8996a7f291e0ddc4b02c0d3e15a64d (diff)
downloadmoa-id-spss-a49bdd53d713a73f706d120f3e386a1ed71ae67e.tar.gz
moa-id-spss-a49bdd53d713a73f706d120f3e386a1ed71ae67e.tar.bz2
moa-id-spss-a49bdd53d713a73f706d120f3e386a1ed71ae67e.zip
@MOA-ID ConfigWebTool:
--update commercial-register number input validator --some short bugfixes @MOA-ID: --update advanced statistic logger --Move Exception classes to a special package --add to Exception types
Diffstat (limited to 'id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/advancedlogging/StatisticLogger.java')
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/advancedlogging/StatisticLogger.java243
1 files changed, 221 insertions, 22 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
index 18d0748af..9b498a475 100644
--- 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
@@ -10,20 +10,48 @@ import javax.xml.bind.Unmarshaller;
import org.apache.commons.lang3.StringEscapeUtils;
+
import at.gv.e_government.reference.namespace.mandates._20040701_.Mandate;
+import at.gv.e_government.reference.namespace.mandates._20040701_.Mandator;
+import at.gv.e_government.reference.namespace.persondata._20020228_.CorporateBodyType;
import at.gv.egovernment.moa.id.auth.data.AuthenticationSession;
+import at.gv.egovernment.moa.id.auth.exception.BKUException;
+import at.gv.egovernment.moa.id.auth.exception.MISSimpleClientException;
+import at.gv.egovernment.moa.id.auth.exception.MOAIDException;
+import at.gv.egovernment.moa.id.auth.exception.ServiceException;
+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.StatisticLogDBUtils;
+import at.gv.egovernment.moa.id.commons.db.dao.config.AuthComponentOA;
+import at.gv.egovernment.moa.id.commons.db.dao.config.BKUURLS;
+import at.gv.egovernment.moa.id.commons.db.dao.config.OnlineApplication;
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.config.auth.OAAuthParameter;
import at.gv.egovernment.moa.id.moduls.IRequest;
+import at.gv.egovernment.moa.id.storage.AuthenticationSessionStoreage;
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 final String GENERIC_LOCALBKU = ":3496/https-security-layer-request";
+ private static final String GENERIC_HANDYBKU = "https://www.handy-signatur.at/";
+
+ private static final String MANTATORTYPE_JUR = "jur";
+ private static final String MANTATORTYPE_NAT = "nat";
+
+ private static final int MAXERRORLENGTH = 250;
+
+ private static final String ERRORTYPE_UNKNOWN = "unkown";
+ private static final String ERRORTYPE_BKU = "bku";
+ private static final String ERRORTYPE_MOASP = "moa-sp";
+ private static final String ERRORTYPE_MANDATE = "mandate";
+ private static final String ERRORTYPE_MOAID = "moa-id";
+
private static StatisticLogger instance;
private boolean isAktive = false;
@@ -50,20 +78,37 @@ public class StatisticLogger {
public void logSuccessOperation(IRequest protocolRequest, AuthenticationSession moasession, boolean isSSOSession) {
if ( isAktive && protocolRequest != null && moasession != null) {
+
+ OnlineApplication dbOA = ConfigurationDBRead.getOnlineApplication(protocolRequest.getOAURL());
+
+ if (dbOA == null) {
+ Logger.warn("Advanced logging failed: OA can not be found in database.");
+ return;
+ }
+
+
StatisticLog dblog = new StatisticLog();
//set actual date and time
dblog.setTimestamp(new Date());
+ //set OA databaseID
+ dblog.setOaID(dbOA.getHjid());
+
//log basic AuthInformation
- dblog.setBkuurl(moasession.getBkuURL());
dblog.setOaurlprefix(protocolRequest.getOAURL());
+ dblog.setOafriendlyName(dbOA.getFriendlyName());
+ dblog.setOatarget(dbOA.getTarget());
+ dblog.setBusinessservice(isBusinessService(dbOA));
+
+ dblog.setBkuurl(moasession.getBkuURL());
+ dblog.setBkutype(findBKUType(moasession.getBkuURL(), dbOA));
+
dblog.setProtocoltype(protocolRequest.requestedModule());
dblog.setProtocolsubtype(protocolRequest.requestedAction());
dblog.setSsosession(isSSOSession);
- dblog.setBusinessservice(moasession.getBusinessService());
-
+
//log MandateInforamtion
if (moasession.getUseMandate()) {
dblog.setMandatelogin(moasession.getUseMandate());
@@ -71,32 +116,50 @@ public class StatisticLogger {
MISMandate mandate = moasession.getMISMandate();
if (mandate != null) {
- if (MiscUtil.isNotEmpty(mandate.getProfRep()))
+ if (MiscUtil.isNotEmpty(mandate.getProfRep())) {
dblog.setMandatetype(mandate.getProfRep());
+ dblog.setPv(true);
+ dblog.setPvOID(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);
+ } else {
+ dblog.setPv(false);
+ }
+
+ 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;
- if (mismandateobj != null && mismandateobj instanceof Mandate) {
- Mandate mismandate = (Mandate) mismandateobj;
+ if (MiscUtil.isEmpty(mandate.getProfRep()))
dblog.setMandatetype(mismandate.getAnnotation());
+
+ Mandator mandator = mismandate.getMandator();
+ CorporateBodyType corp = mandator.getCorporateBody();
+ if (corp != null) {
+ dblog.setMandatortype(MANTATORTYPE_JUR);
} else {
- Logger.warn("Advancted logging can not unmarshall MISMandate");
+ dblog.setMandatortype(MANTATORTYPE_NAT);
}
-
- } catch (JAXBException e) {
- Logger.warn("Advancted logging can not parse mandate.", e);
+
+
+ } else {
+ Logger.warn("Advancted logging can not unmarshall MISMandate");
}
+
+ } catch (JAXBException e) {
+ Logger.warn("Advancted logging can not parse mandate.", e);
}
}
}
+ ConfigurationDBUtils.closeSession();
+
try {
StatisticLogDBUtils.saveOrUpdate(dblog);
@@ -106,14 +169,22 @@ public class StatisticLogger {
}
}
- public void logErrorOperation(String errorMessage) {
- if ( isAktive && MiscUtil.isNotEmpty(errorMessage) ) {
+ public void logErrorOperation(Throwable throwable) {
+ if ( isAktive ) {
StatisticLog dblog = new StatisticLog();
//set actual date and time
dblog.setTimestamp(new Date());
- dblog.setErrormessage(StringEscapeUtils.escapeXml(errorMessage));
+ if (throwable != null)
+ generateErrorLogFormThrowable(throwable, dblog);
+
+ else {
+ dblog.setErrormessage("UNKOWN ERROR DETECTED!");
+ dblog.setErrortype(ERRORTYPE_UNKNOWN);
+ }
+
+
try {
StatisticLogDBUtils.saveOrUpdate(dblog);
@@ -133,10 +204,29 @@ public class StatisticLogger {
//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()));
+
+ OnlineApplication dbOA = ConfigurationDBRead.getOnlineApplication(errorRequest.getOAURL());
+ if (dbOA != null) {
+ dblog.setOafriendlyName(dbOA.getFriendlyName());
+ dblog.setOatarget(dbOA.getTarget());
+ dblog.setOaID(dbOA.getHjid());
+ dblog.setBusinessservice(isBusinessService(dbOA));
+ }
+
+ AuthenticationSession moasession = AuthenticationSessionStoreage.getSessionWithPendingRequestID(errorRequest.getRequestID());
+ if (moasession != null) {
+ dblog.setBkuurl(moasession.getBkuURL());
+ dblog.setBkutype(findBKUType(moasession.getBkuURL(), dbOA));
+ dblog.setMandatelogin(moasession.getUseMandate());
+ }
+
+ generateErrorLogFormThrowable(throwable, dblog);
+
+ ConfigurationDBUtils.closeSession();
try {
StatisticLogDBUtils.saveOrUpdate(dblog);
@@ -147,4 +237,113 @@ public class StatisticLogger {
}
}
+ private boolean isBusinessService(OnlineApplication oa) {
+
+ if (oa.getType().equals("businessService"))
+ return true;
+ else
+ return false;
+ }
+
+
+ private String getErrorMessageWithMaxLength(String error, int maxlength) {
+ if (error != null) {
+ if (error.length() > maxlength)
+ return StringEscapeUtils.escapeHtml4(error.substring(0, maxlength));
+
+ else
+ return StringEscapeUtils.escapeHtml4(error);
+
+ } else
+ return new String();
+
+ }
+
+ private void generateErrorLogFormThrowable(Throwable throwable, StatisticLog dblog) {
+ if (throwable instanceof BKUException) {
+ BKUException error = (BKUException) throwable;
+ dblog.setErrortype(ERRORTYPE_BKU);
+ dblog.setErrorcode(error.getBkuErrorCode());
+ dblog.setErrormessage(getErrorMessageWithMaxLength(error.getBkuErrorMessage(), MAXERRORLENGTH));
+
+ }else if (throwable instanceof MISSimpleClientException) {
+ MISSimpleClientException error = (MISSimpleClientException) throwable;
+ dblog.setErrortype(ERRORTYPE_MANDATE);
+ dblog.setErrorcode(error.getMISErrorCode());
+ if (MiscUtil.isEmpty(error.getMISErrorMessage()))
+ dblog.setErrormessage(getErrorMessageWithMaxLength(error.getMessage(), MAXERRORLENGTH));
+ else
+ dblog.setErrormessage(getErrorMessageWithMaxLength(error.getMISErrorMessage(), MAXERRORLENGTH));
+
+ } else if (throwable instanceof ServiceException) {
+ ServiceException error = (ServiceException) throwable;
+ dblog.setErrortype(ERRORTYPE_MOASP);
+ dblog.setErrorcode(error.getMessageId());
+ dblog.setErrormessage(getErrorMessageWithMaxLength(error.getMessage(), MAXERRORLENGTH));
+
+ } else if (throwable instanceof MOAIDException) {
+ MOAIDException error = (MOAIDException) throwable;
+ dblog.setErrortype(ERRORTYPE_MOAID);
+ dblog.setErrorcode(error.getMessageId());
+ dblog.setErrormessage(getErrorMessageWithMaxLength(error.getMessage(), MAXERRORLENGTH));
+
+ } else {
+ dblog.setErrortype(ERRORTYPE_UNKNOWN);
+ dblog.setErrormessage(getErrorMessageWithMaxLength(throwable.getMessage(), MAXERRORLENGTH));
+ }
+
+ }
+
+ private String findBKUType(String bkuURL, OnlineApplication dbOA) {
+
+ if (dbOA != null) {
+ AuthComponentOA oaAuth = dbOA.getAuthComponentOA();
+ if (oaAuth != null) {
+ BKUURLS bkuurls = oaAuth.getBKUURLS();
+ if (bkuurls != null) {
+ if (bkuURL.equals(bkuurls.getHandyBKU()))
+ return OAAuthParameter.HANDYBKU;
+
+ if (bkuURL.equals(bkuurls.getLocalBKU()))
+ return OAAuthParameter.LOCALBKU;
+
+ if (bkuURL.equals(bkuurls.getOnlineBKU()))
+ return OAAuthParameter.ONLINEBKU;
+ }
+ }
+ }
+
+ Logger.trace("Staticic Log search BKUType from DefaultBKUs");
+
+ try {
+ AuthConfigurationProvider authconfig = AuthConfigurationProvider.getInstance();
+ if (bkuURL.equals(authconfig.getDefaultBKUURL(OAAuthParameter.ONLINEBKU)))
+ return OAAuthParameter.ONLINEBKU;
+
+ if (bkuURL.equals(authconfig.getDefaultBKUURL(OAAuthParameter.LOCALBKU)))
+ return OAAuthParameter.LOCALBKU;
+
+ if (bkuURL.equals(authconfig.getDefaultBKUURL(OAAuthParameter.HANDYBKU)))
+ return OAAuthParameter.HANDYBKU;
+
+ } catch (ConfigurationException e) {
+ Logger.info("Advanced Logging: Default BKUs read failed");
+ }
+
+ Logger.debug("Staticic Log search BKUType from generneric Parameters");
+
+ if (bkuURL.endsWith(GENERIC_LOCALBKU)) {
+ Logger.debug("BKUURL " + bkuURL + " is mapped to " + OAAuthParameter.LOCALBKU);
+ return OAAuthParameter.LOCALBKU;
+ }
+
+ if (bkuURL.startsWith(GENERIC_HANDYBKU)) {
+ Logger.debug("BKUURL " + bkuURL + " is mapped to " + OAAuthParameter.HANDYBKU);
+ return OAAuthParameter.HANDYBKU;
+ }
+
+ Logger.debug("BKUURL " + bkuURL + " is mapped to " + OAAuthParameter.ONLINEBKU);
+ return OAAuthParameter.ONLINEBKU;
+ }
+
}