diff options
author | Thomas Lenz <tlenz@iaik.tugraz.at> | 2013-09-24 11:39:46 +0200 |
---|---|---|
committer | Thomas Lenz <tlenz@iaik.tugraz.at> | 2013-09-24 11:39:46 +0200 |
commit | cd1a5f3b69f38c1aa7bad2826f2be2df45f75346 (patch) | |
tree | 493326f3eace0b173d15bb7fe4627bfdb7914ce6 /id/server | |
parent | 816bd3d051a7c8fc7aba535361550d62fb5af2cc (diff) | |
download | moa-id-spss-cd1a5f3b69f38c1aa7bad2826f2be2df45f75346.tar.gz moa-id-spss-cd1a5f3b69f38c1aa7bad2826f2be2df45f75346.tar.bz2 moa-id-spss-cd1a5f3b69f38c1aa7bad2826f2be2df45f75346.zip |
implement advanced statistic logger
Diffstat (limited to 'id/server')
10 files changed, 599 insertions, 52 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) { diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBRead.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBRead.java index d281eebbc..47136d162 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBRead.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBRead.java @@ -15,6 +15,7 @@ import at.gv.egovernment.moa.id.commons.db.dao.config.UserDatabase; import at.gv.egovernment.moa.logging.Logger; import at.gv.egovernment.moa.util.MiscUtil; +@SuppressWarnings("rawtypes") public class ConfigurationDBRead { private static Map<String, String> QUERIES = new HashMap<String, String>(); @@ -36,20 +37,16 @@ public class ConfigurationDBRead { QUERIES.put("getUsersWithOADBID", "select userdatabase from UserDatabase userdatabase inner join userdatabase.onlineApplication oa where oa.hjid = :id"); QUERIES.put("searchOnlineApplicationsWithID", "select onlineapplication from OnlineApplication onlineapplication where onlineapplication.friendlyName like :id"); } - @SuppressWarnings("rawtypes") public static OnlineApplication getActiveOnlineApplication(String id) { MiscUtil.assertNotNull(id, "OnlineApplictionID"); Logger.trace("Getting OnlineApplication with ID " + id + " from database."); - - //TODO: check!!! - id = StringEscapeUtils.escapeHtml(id); List result; EntityManager session = ConfigurationDBUtils.getCurrentSession(); javax.persistence.Query query = session.createQuery(QUERIES.get("getActiveOnlineApplicationWithID")); //query.setParameter("id", id+"%"); - query.setParameter("id", id); + query.setParameter("id", StringEscapeUtils.escapeHtml(id)); result = query.getResultList(); Logger.trace("Found entries: " + result.size()); @@ -62,8 +59,6 @@ public class ConfigurationDBRead { return (OnlineApplication) result.get(0); } - - @SuppressWarnings("rawtypes") public static OnlineApplication getOnlineApplication(String id) { MiscUtil.assertNotNull(id, "OnlineApplictionID"); Logger.trace("Getting OnlineApplication with ID " + id + " from database."); @@ -86,7 +81,6 @@ public class ConfigurationDBRead { return (OnlineApplication) result.get(0); } - @SuppressWarnings("rawtypes") public static OnlineApplication getOnlineApplication(long dbid) { MiscUtil.assertNotNull(dbid, "OnlineApplictionID"); Logger.trace("Getting OnlineApplication with DBID " + dbid + " from database."); @@ -112,7 +106,7 @@ public class ConfigurationDBRead { public static MOAIDConfiguration getMOAIDConfiguration() { Logger.trace("Load MOAID Configuration from database."); - List result; + List<MOAIDConfiguration> result; EntityManager session = ConfigurationDBUtils.getCurrentSession(); javax.persistence.Query query = session.createQuery(QUERIES.get("getMOAIDConfiguration")); diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBUtils.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBUtils.java index 16cea07d8..a177ea938 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBUtils.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBUtils.java @@ -8,8 +8,6 @@ import javax.persistence.EntityTransaction; import javax.persistence.Persistence; import org.hibernate.HibernateException; -import org.hibernate.Session; - import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException; import at.gv.egovernment.moa.logging.Logger; @@ -27,20 +25,8 @@ public final class ConfigurationDBUtils { public static void initHibernate(Properties props) throws MOADatabaseException { try { - - //add Hibernate annotations -// Configuration hibernateConfig = new Configuration(); -// hibernateConfig.addAnnotatedClass(AssertionStore.class); -// hibernateConfig.addAnnotatedClass(AuthenticatedSessionStore.class); -// hibernateConfig.addAnnotatedClass(OASessionStore.class); -// hibernateConfig.addAnnotatedClass(OldSSOSessionIDStore.class); -// hibernateConfig.addProperties(props); - Logger.debug("Creating initial session factory..."); -// entitymanagerfactory = -// Persistence.createEntityManagerFactory("at.gv.egovernment.moa.id.commons.db.dao.config", -// hibernateConfig.getProperties()); entitymanagerfactory = Persistence.createEntityManagerFactory("at.gv.egovernment.moa.id.commons.db.dao.config", @@ -94,7 +80,6 @@ public final class ConfigurationDBUtils { public static EntityManager getNewSession() { if (automaticSessionHandling) { Logger.warn("Session is being automatically handled by hibernate. Therefore this session maybe not being newly created. Use HibernateUtil.getCurrentSession() instead."); - //return sessionFactory.getCurrentSession(); return entitymanagerfactory.createEntityManager(); } EntityManager session = (EntityManager) THREAD_LOCAL_CONFIG.get(); @@ -198,8 +183,6 @@ public final class ConfigurationDBUtils { tx.begin(); session.remove(session.contains(dbo) ? dbo : session.merge(dbo)); tx.commit(); - - //session.clear(); } return true; diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java index 5e4ec0f13..057ccdef7 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java @@ -11,10 +11,6 @@ import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder; -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.ex.MOADatabaseException; import at.gv.egovernment.moa.logging.Logger; @@ -29,8 +25,6 @@ public final class MOASessionDBUtils { private static final String[] AUTOMATIC_SESSION_HANDLING_VALUES = new String[] { "jta", "thread" }; private static final String SESSION_HANDLING_KEY = "hibernate.current_session_context_class"; - - private static Configuration configuration; protected MOASessionDBUtils() { } diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/StatisticLogDBUtils.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/StatisticLogDBUtils.java new file mode 100644 index 000000000..b60075788 --- /dev/null +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/StatisticLogDBUtils.java @@ -0,0 +1,166 @@ +package at.gv.egovernment.moa.id.commons.db; + +import java.util.Properties; + +import org.apache.commons.lang3.StringUtils; +import org.hibernate.HibernateException; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.cfg.Configuration; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.service.ServiceRegistryBuilder; + +import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException; +import at.gv.egovernment.moa.logging.Logger; + +public final class StatisticLogDBUtils { + + private static SessionFactory sessionFactory; + private static ServiceRegistry serviceRegistry; + + @SuppressWarnings("rawtypes") + private static final ThreadLocal THREAD_LOCAL_STATISTIC = new ThreadLocal(); + private static boolean automaticSessionHandling = false; + + private static final String[] AUTOMATIC_SESSION_HANDLING_VALUES = new String[] { "jta", "thread" }; + private static final String SESSION_HANDLING_KEY = "hibernate.current_session_context_class"; + + protected StatisticLogDBUtils() { } + + public static void initHibernate(Configuration config, Properties hibernateProperties) { + + String scm = StringUtils.trimToNull(hibernateProperties.getProperty(SESSION_HANDLING_KEY)); + if (scm != null) { + automaticSessionHandling = scm.indexOf(AUTOMATIC_SESSION_HANDLING_VALUES[0]) != -1 || scm.indexOf(AUTOMATIC_SESSION_HANDLING_VALUES[1]) != -1; + } + Logger.debug("Evaluating hibernate property \"" + SESSION_HANDLING_KEY + "\"."); + if (automaticSessionHandling) { + Logger.info("Hibernate is automatically handling session context management."); + } else { + Logger.info("Hibernate is NOT automatically handling session context management. Using build-in ThreadLocal session handling."); + } + try { + //Create the SessionFactory + Logger.debug("Creating initial StatisicLogger session factory..."); + + config.configure(); + serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry(); + sessionFactory = config.buildSessionFactory(serviceRegistry); + Logger.debug("Initial StatisicLogger session factory successfully created."); + + } catch (Throwable ex) { + Logger.error("Initial StatisicLogger session factory creation failed: " + ex.getMessage()); + throw new ExceptionInInitializerError(ex); + } + } + + /** + * Checks if a session factory is currently available. If necessary a new + * session factory is created. + * + * @return current (or new) session factory + * @throws HibernateException + * thrown if a hibernate error occurs + */ + public static Session getCurrentSession() { + if (automaticSessionHandling) { + return sessionFactory.getCurrentSession(); + } + Session session = (Session) THREAD_LOCAL_STATISTIC.get(); + // Open a new Session, if this Thread has none yet + if (session == null || !session.isConnected()) { + session = getNewSession(); + } + return session; + } + + @SuppressWarnings("unchecked") + public static Session getNewSession() { + if (automaticSessionHandling) { + Logger.warn("Session is being automatically handled by hibernate. Therefore this session maybe not being newly created. Use HibernateUtil.getCurrentSession() instead."); + return sessionFactory.getCurrentSession(); + } + Session session = (Session) THREAD_LOCAL_STATISTIC.get(); + if (session != null) { + Logger.warn("Previous StatisicLogger session has not been closed; closing session now."); + closeSession(); + } + Logger.debug("Opening new StatisicLogger hibernate session..."); + try { + session = sessionFactory.openSession(); + THREAD_LOCAL_STATISTIC.set(session); + } catch (HibernateException hex) { + Logger.error(hex.getMessage()); + } + return session; + } + + /** + * Closes the current session. + * + * @throws HibernateException + * thrown if session is already closed or a hibernate error + * occurs. + */ + @SuppressWarnings("unchecked") + public static void closeSession() { + if (automaticSessionHandling) { + Logger.warn("Session is being automatically handled by hibernate. Therefore the current session cannot be closed on demand."); + return; + } + Logger.debug("Closing current StatisicLogger hibernate session..."); + Session session = (Session) THREAD_LOCAL_STATISTIC.get(); + THREAD_LOCAL_STATISTIC.set(null); + if (session != null) { + try { + session.close(); + + } catch (HibernateException hex) { + Logger.error(hex.getMessage()); + } + } + } + + public static boolean saveOrUpdate(Object dbo) throws MOADatabaseException { + Transaction tx = null; + try { + Session session = StatisticLogDBUtils.getCurrentSession(); + + synchronized (session) { + tx = session.beginTransaction(); + session.saveOrUpdate(dbo); + tx.commit(); + } + + Logger.info("Insert advanced statistic log entry into database"); + return true; + + } catch(HibernateException e) { + Logger.warn("Error during StatisicLogger database saveOrUpdate. Rollback.", e); + tx.rollback(); + throw new MOADatabaseException(e); + } + } + + public static boolean delete(Object dbo) { + Transaction tx = null; + try { + Session session = StatisticLogDBUtils.getCurrentSession(); + + synchronized (session) { + tx = session.beginTransaction(); + session.delete(dbo); + tx.commit(); + } + + return true; + + } catch(HibernateException e) { + Logger.warn("Error during StatisicLogger database delete. Rollback.", e); + tx.rollback(); + return false; + } + } + +} diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/OASessionStore.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/OASessionStore.java index 6e0f47805..3872397f7 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/OASessionStore.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/OASessionStore.java @@ -11,14 +11,9 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; -import javax.persistence.PrePersist; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import org.hibernate.annotations.DynamicUpdate; -import org.hibernate.annotations.NamedQueries; -import org.hibernate.annotations.NamedQuery; @Entity @DynamicUpdate(value=true) diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/statistic/StatisticLog.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/statistic/StatisticLog.java new file mode 100644 index 000000000..643136e70 --- /dev/null +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/statistic/StatisticLog.java @@ -0,0 +1,237 @@ +package at.gv.egovernment.moa.id.commons.db.dao.statistic; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.hibernate.annotations.DynamicUpdate; + + + +@Entity +@DynamicUpdate(value=true) +@Table(name = "statisiclog") +//@NamedQueries({ +// @NamedQuery(name="getAssertionWithArtifact", query = "select assertionstore from AssertionStore assertionstore where assertionstore.artifact = :artifact"), +// @NamedQuery(name="getAssertionWithTimeOut", query = "select assertionstore from AssertionStore assertionstore where assertionstore.timestamp < :timeout") +//}) + +public class StatisticLog implements Serializable{ + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", unique=true, nullable=false) + private long id; + + @Column(name = "timestamp", nullable=false) + Date timestamp; + + @Column(name = "OAURLPrefix", unique=false) + private String oaurlprefix; + + @Column(name = "BKUURL", unique=false) + private String bkuurl; + + @Column(name = "isSSOLogin", unique=false) + private boolean ssosession; + + @Column(name = "isBusinessService", unique=false) + private boolean businessservice; + + @Column(name = "isMandateLogin", unique=false) + private boolean mandatelogin; + + @Column(name = "MandateType", unique=false) + private String mandatetype; + + @Column(name = "ProtocolSubType", unique=false) + private String protocolsubtype; + + @Column(name = "ProtocolType", unique=false) + private String protocoltype; + + @Column(name = "ExceptionCode", unique=false) + private String errorcode; + + @Column(name = "ExceptionMessage", unique=false) + private String errormessage; + + /** + * @return the id + */ + public long getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(long id) { + this.id = id; + } + + /** + * @return the timestamp + */ + public Date getTimestamp() { + return timestamp; + } + + /** + * @param timestamp the timestamp to set + */ + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + /** + * @return the oaurlprefix + */ + public String getOaurlprefix() { + return oaurlprefix; + } + + /** + * @param oaurlprefix the oaurlprefix to set + */ + public void setOaurlprefix(String oaurlprefix) { + this.oaurlprefix = oaurlprefix; + } + + /** + * @return the bkuurl + */ + public String getBkuurl() { + return bkuurl; + } + + /** + * @param bkuurl the bkuurl to set + */ + public void setBkuurl(String bkuurl) { + this.bkuurl = bkuurl; + } + + /** + * @return the ssosession + */ + public boolean isSsosession() { + return ssosession; + } + + /** + * @param ssosession the ssosession to set + */ + public void setSsosession(boolean ssosession) { + this.ssosession = ssosession; + } + + /** + * @return the mandatelogin + */ + public boolean isMandatelogin() { + return mandatelogin; + } + + /** + * @param mandatelogin the mandatelogin to set + */ + public void setMandatelogin(boolean mandatelogin) { + this.mandatelogin = mandatelogin; + } + + /** + * @return the mandatetype + */ + public String getMandatetype() { + return mandatetype; + } + + /** + * @param mandatetype the mandatetype to set + */ + public void setMandatetype(String mandatetype) { + this.mandatetype = mandatetype; + } + + /** + * @return the mandatesubtype + */ + public String getProtocolsubtype() { + return protocolsubtype; + } + + /** + * @param mandatesubtype the mandatesubtype to set + */ + public void setProtocolsubtype(String mandatesubtype) { + this.protocolsubtype = mandatesubtype; + } + + /** + * @return the protocoltype + */ + public String getProtocoltype() { + return protocoltype; + } + + /** + * @param protocoltype the protocoltype to set + */ + public void setProtocoltype(String protocoltype) { + this.protocoltype = protocoltype; + } + + /** + * @return the errorcode + */ + public String getErrorcode() { + return errorcode; + } + + /** + * @param errorcode the errorcode to set + */ + public void setErrorcode(String errorcode) { + this.errorcode = errorcode; + } + + /** + * @return the errormessage + */ + public String getErrormessage() { + return errormessage; + } + + /** + * @param errormessage the errormessage to set + */ + public void setErrormessage(String errormessage) { + this.errormessage = errormessage; + } + + /** + * @return the businessservice + */ + public boolean isBusinessservice() { + return businessservice; + } + + /** + * @param businessservice the businessservice to set + */ + public void setBusinessservice(boolean businessservice) { + this.businessservice = businessservice; + } + + + +} |