aboutsummaryrefslogtreecommitdiff
path: root/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa')
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBRead.java238
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBUtils.java214
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java170
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/AssertionStore.java92
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/AuthenticatedSessionStore.java187
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/OASessionStore.java87
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/OldSSOSessionIDStore.java69
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ex/MOADatabaseException.java22
8 files changed, 1079 insertions, 0 deletions
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
new file mode 100644
index 000000000..795981777
--- /dev/null
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBRead.java
@@ -0,0 +1,238 @@
+package at.gv.egovernment.moa.id.commons.db;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+
+import at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration;
+import at.gv.egovernment.moa.id.commons.db.dao.config.OnlineApplication;
+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;
+
+public class ConfigurationDBRead {
+
+ private static Map<String, String> QUERIES = new HashMap<String, String>();
+ static {
+ QUERIES.put("getActiveOnlineApplicationWithID", "select onlineapplication from OnlineApplication onlineapplication where onlineapplication.publicURLPrefix like SUBSTRING(:id, 1, LENGTH(onlineapplication.publicURLPrefix)) and onlineapplication.isActive = '1'");
+ QUERIES.put("getOnlineApplicationWithID", "select onlineapplication from OnlineApplication onlineapplication where onlineapplication.publicURLPrefix like SUBSTRING(:id, 1, LENGTH(onlineapplication.publicURLPrefix))");
+ QUERIES.put("getOnlineApplicationWithDBID", "select onlineapplication from OnlineApplication onlineapplication where onlineapplication.hjid = :id");
+ QUERIES.put("getAllOnlineApplications", "select onlineapplication from OnlineApplication onlineapplication");
+ QUERIES.put("getAllActiveOnlineApplications", "select onlineapplication from OnlineApplication onlineapplication where onlineapplication.isActive = '1'");
+ QUERIES.put("getMOAIDConfiguration", "select moaidconfiguration from MOAIDConfiguration moaidconfiguration");
+ QUERIES.put("getUserWithUserID", "select userdatabase from UserDatabase userdatabase where userdatabase.hjid = :id");
+ QUERIES.put("getUserWithUserUsername", "select userdatabase from UserDatabase userdatabase where userdatabase.username = :username");
+ QUERIES.put("getAllUsers", "select userdatabase from UserDatabase userdatabase");
+ 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.");
+
+ List result;
+ EntityManager session = ConfigurationDBUtils.getCurrentSession();
+
+ javax.persistence.Query query = session.createQuery(QUERIES.get("getActiveOnlineApplicationWithID"));
+ //query.setParameter("id", id+"%");
+ query.setParameter("id", id);
+ result = query.getResultList();
+
+ Logger.trace("Found entries: " + result.size());
+
+ if (result.size() == 0) {
+ Logger.trace("No entries found.");
+ return null;
+ }
+
+ 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.");
+
+ List result;
+ EntityManager session = ConfigurationDBUtils.getCurrentSession();
+
+ javax.persistence.Query query = session.createQuery(QUERIES.get("getOnlineApplicationWithID"));
+ //query.setParameter("id", id+"%");
+ query.setParameter("id", id);
+ result = query.getResultList();
+
+ Logger.trace("Found entries: " + result.size());
+
+ if (result.size() == 0) {
+ Logger.trace("No entries found.");
+ return null;
+ }
+
+ 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.");
+
+ List result;
+ EntityManager session = ConfigurationDBUtils.getCurrentSession();
+
+ javax.persistence.Query query = session.createQuery(QUERIES.get("getOnlineApplicationWithDBID"));
+ //query.setParameter("id", id+"%");
+ query.setParameter("id", dbid);
+ result = query.getResultList();
+
+ Logger.trace("Found entries: " + result.size());
+
+ if (result.size() == 0) {
+ Logger.trace("No entries found.");
+ return null;
+ }
+
+ return (OnlineApplication) result.get(0);
+ }
+
+ public static MOAIDConfiguration getMOAIDConfiguration() {
+ Logger.trace("Load MOAID Configuration from database.");
+
+ List result;
+ EntityManager session = ConfigurationDBUtils.getCurrentSession();
+
+ javax.persistence.Query query = session.createQuery(QUERIES.get("getMOAIDConfiguration"));
+ result = query.getResultList();
+
+ Logger.trace("Found entries: " + result.size());
+
+ if (result.size() == 0) {
+ Logger.trace("No entries found.");
+ return null;
+ }
+
+ return (MOAIDConfiguration) result.get(0);
+ }
+
+ public static List<OnlineApplication> getAllOnlineApplications() {
+ Logger.trace("Get All OnlineApplications from database.");
+
+ List<OnlineApplication> result;
+ EntityManager session = ConfigurationDBUtils.getCurrentSession();
+
+ javax.persistence.Query query = session.createQuery(QUERIES.get("getAllOnlineApplications"));
+ result = query.getResultList();
+
+ Logger.trace("Found entries: " + result.size());
+
+ if (result.size() == 0) {
+ Logger.trace("No entries found.");
+ return null;
+ }
+ return result;
+ }
+
+ public static List<UserDatabase> getAllUsers() {
+ Logger.trace("Get All OnlineApplications from database.");
+
+ List<UserDatabase> result;
+ EntityManager session = ConfigurationDBUtils.getCurrentSession();
+
+ javax.persistence.Query query = session.createQuery(QUERIES.get("getAllUsers"));
+ result = query.getResultList();
+
+ Logger.trace("Found entries: " + result.size());
+
+ if (result.size() == 0) {
+ Logger.trace("No entries found.");
+ return null;
+ }
+ return result;
+ }
+
+ public static List<OnlineApplication> getAllActiveOnlineApplications() {
+ Logger.trace("Get All active OnlineApplications from database.");
+
+ List<OnlineApplication> result;
+ EntityManager session = ConfigurationDBUtils.getCurrentSession();
+
+ javax.persistence.Query query = session.createQuery(QUERIES.get("getAllActiveOnlineApplications"));
+ result = query.getResultList();
+
+ Logger.trace("Found entries: " + result.size());
+
+ if (result.size() == 0) {
+ Logger.trace("No entries found.");
+ return null;
+ }
+ return result;
+ }
+
+ @SuppressWarnings("rawtypes")
+ public static List<OnlineApplication> searchOnlineApplications(String id) {
+ MiscUtil.assertNotNull(id, "OnlineApplictionID");
+ Logger.trace("Getting OnlineApplication with ID " + id + " from database.");
+
+ List<OnlineApplication> result;
+ EntityManager session = ConfigurationDBUtils.getCurrentSession();
+
+ javax.persistence.Query query = session.createQuery(QUERIES.get("searchOnlineApplicationsWithID"));
+ query.setParameter("id", "%"+id+"%");
+
+ result = query.getResultList();
+
+ Logger.trace("Found entries: " + result.size());
+
+ if (result.size() == 0) {
+ Logger.trace("No entries found.");
+ return null;
+ }
+
+ return result;
+ }
+
+ public static UserDatabase getUserWithID(long id) {
+ MiscUtil.assertNotNull(id, "UserID");
+ Logger.trace("Getting Userinformation with ID " + id + " from database.");
+
+ List<UserDatabase> result;
+ EntityManager session = ConfigurationDBUtils.getCurrentSession();
+
+ javax.persistence.Query query = session.createQuery(QUERIES.get("getUserWithUserID"));
+ query.setParameter("id", id);
+ result = query.getResultList();
+
+ Logger.trace("Found entries: " + result.size());
+
+ if (result.size() == 0) {
+ Logger.trace("No entries found.");
+ return null;
+ }
+ return (UserDatabase) result.get(0);
+ }
+
+
+
+ public static UserDatabase getUserWithUserName(String username) {
+ MiscUtil.assertNotNull(username, "UserName");
+ Logger.trace("Getting Userinformation with ID " + username + " from database.");
+
+ List<UserDatabase> result;
+ EntityManager session = ConfigurationDBUtils.getCurrentSession();
+
+ javax.persistence.Query query = session.createQuery(QUERIES.get("getUserWithUserUsername"));
+ query.setParameter("username", username);
+ result = query.getResultList();
+
+ Logger.trace("Found entries: " + result.size());
+
+ if (result.size() == 0) {
+ Logger.trace("No entries found.");
+ return null;
+ }
+ return (UserDatabase) result.get(0);
+ }
+}
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
new file mode 100644
index 000000000..16cea07d8
--- /dev/null
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBUtils.java
@@ -0,0 +1,214 @@
+package at.gv.egovernment.moa.id.commons.db;
+
+import java.util.Properties;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+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;
+
+public final class ConfigurationDBUtils {
+
+ private static EntityManagerFactory entitymanagerfactory;
+
+ @SuppressWarnings("rawtypes")
+ private static final ThreadLocal THREAD_LOCAL_CONFIG = new ThreadLocal();
+ private static boolean automaticSessionHandling = false;
+
+ protected 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",
+ props);
+
+ Logger.debug("Initial ConfigDB session factory successfully created.");
+
+
+ } catch (Throwable ex) {
+ Logger.error("Initial session factory creation failed: " + ex.getMessage());
+ throw new MOADatabaseException("Initialization of Configuration Hibernate session factory failed.",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 EntityManager getCurrentSession() {
+ if (automaticSessionHandling) {
+
+ return entitymanagerfactory.createEntityManager();
+ }
+
+ EntityManager session = (EntityManager) THREAD_LOCAL_CONFIG.get();
+
+ if (session != null && session.isOpen()) {
+
+ //maybe a hack, but sometimes we do not know if the session is closed (session already closed but isOpen()=true)
+ try {
+ javax.persistence.Query query = session.createQuery("select userdatabase from UserDatabase userdatabase");
+ query.getResultList();
+
+ } catch (Throwable e) {
+ Logger.warn("JPA Session Handling Warning!!!! - This error should not occur.");
+ session = getNewSession();
+ }
+
+ } else
+ session = getNewSession();
+
+ return session;
+ }
+
+ @SuppressWarnings("unchecked")
+ 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();
+ if (session != null ) {
+ Logger.warn("Previous session has not been closed; closing ConfigDB session now.");
+ closeSession();
+ }
+ Logger.debug("Opening new ConfigDB hibernate session...");
+ try {
+ session = entitymanagerfactory.createEntityManager();
+ THREAD_LOCAL_CONFIG.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 ConfigDB hibernate session...");
+ EntityManager session = (EntityManager) THREAD_LOCAL_CONFIG.get();
+ THREAD_LOCAL_CONFIG.set(null);
+ if (session != null) {
+ try {
+ session.close();
+
+ } catch (HibernateException hex) {
+ Logger.error(hex.getMessage());
+ }
+ }
+ }
+
+ public static boolean save(Object dbo) throws MOADatabaseException {
+ EntityTransaction tx = null;
+
+ try {
+ EntityManager session = ConfigurationDBUtils.getCurrentSession();
+ tx = session.getTransaction();
+
+ synchronized (session) {
+ tx.begin();
+ session.persist(dbo);
+ tx.commit();
+
+ //session.clear();
+ }
+ return true;
+
+ } catch(HibernateException e) {
+ Logger.warn("Error during Config database saveOrUpdate. Rollback.", e);
+ tx.rollback();
+ throw new MOADatabaseException(e);
+ }
+ }
+
+
+ public static boolean saveOrUpdate(Object dbo) throws MOADatabaseException {
+ EntityTransaction tx = null;
+
+ try {
+ EntityManager session = ConfigurationDBUtils.getCurrentSession();
+ tx = session.getTransaction();
+
+ synchronized (session) {
+ tx.begin();
+
+ session.merge(dbo);
+ session.flush();
+
+ tx.commit();
+
+ //session.clear();
+ }
+ return true;
+
+ } catch(HibernateException e) {
+ Logger.warn("Error during Config database saveOrUpdate. Rollback.", e);
+ tx.rollback();
+ throw new MOADatabaseException(e);
+ }
+ }
+
+ public static boolean delete(Object dbo) {
+ EntityTransaction tx = null;
+ try {
+ EntityManager session = ConfigurationDBUtils.getCurrentSession();
+ tx = session.getTransaction();
+
+ synchronized (session) {
+ tx.begin();
+ session.remove(session.contains(dbo) ? dbo : session.merge(dbo));
+ tx.commit();
+
+ //session.clear();
+ }
+
+ return true;
+
+ } catch(HibernateException e) {
+ Logger.warn("Error during Config 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/MOASessionDBUtils.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java
new file mode 100644
index 000000000..5e4ec0f13
--- /dev/null
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java
@@ -0,0 +1,170 @@
+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.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;
+
+public final class MOASessionDBUtils {
+
+ private static SessionFactory sessionFactory;
+ private static ServiceRegistry serviceRegistry;
+
+ @SuppressWarnings("rawtypes")
+ private static final ThreadLocal THREAD_LOCAL = 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";
+
+ private static Configuration configuration;
+
+ protected MOASessionDBUtils() { }
+
+ 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 MOASession session factory...");
+
+ config.configure();
+ serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
+ sessionFactory = config.buildSessionFactory(serviceRegistry);
+ Logger.debug("Initial MOASession session factory successfully created.");
+
+ } catch (Throwable ex) {
+ Logger.error("Initial MOASession 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.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.get();
+ if (session != null) {
+ Logger.warn("Previous MOASession session has not been closed; closing session now.");
+ closeSession();
+ }
+ Logger.debug("Opening new MOASession hibernate session...");
+ try {
+ session = sessionFactory.openSession();
+ THREAD_LOCAL.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 MOASession hibernate session...");
+ Session session = (Session) THREAD_LOCAL.get();
+ THREAD_LOCAL.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 = MOASessionDBUtils.getCurrentSession();
+
+ synchronized (session) {
+ tx = session.beginTransaction();
+ session.saveOrUpdate(dbo);
+ tx.commit();
+ }
+ return true;
+
+ } catch(HibernateException e) {
+ Logger.warn("Error during MOASession database saveOrUpdate. Rollback.", e);
+ tx.rollback();
+ throw new MOADatabaseException(e);
+ }
+ }
+
+ public static boolean delete(Object dbo) {
+ Transaction tx = null;
+ try {
+ Session session = MOASessionDBUtils.getCurrentSession();
+
+ synchronized (session) {
+ tx = session.beginTransaction();
+ session.delete(dbo);
+ tx.commit();
+ }
+
+ return true;
+
+ } catch(HibernateException e) {
+ Logger.warn("Error during MOASession 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/AssertionStore.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/AssertionStore.java
new file mode 100644
index 000000000..50c156c4e
--- /dev/null
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/AssertionStore.java
@@ -0,0 +1,92 @@
+package at.gv.egovernment.moa.id.commons.db.dao.session;
+
+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.Lob;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
+
+import org.hibernate.annotations.DynamicUpdate;
+
+
+
+@Entity
+@DynamicUpdate(value=true)
+@Table(name = "assertionstore")
+@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 AssertionStore 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 = "artifact", unique=true, nullable=false)
+ private String artifact;
+
+ @Column(name = "type", nullable=false)
+ private String type;
+
+ @Column(name = "assertion", nullable=false)
+ @Lob private byte [] assertion;
+
+ @Column(name = "timestamp", nullable=false)
+ Date timestamp;
+
+
+
+ public String getArtifact() {
+ return artifact;
+ }
+
+ public void setArtifact(String artifact) {
+ this.artifact = artifact;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public byte[] getAssertion() {
+ return assertion;
+ }
+
+ public void setAssertion(byte[] assertion) {
+ this.assertion = assertion;
+ }
+
+ public Date getDatatime() {
+ return timestamp;
+ }
+
+ public void setDatatime(Date datatime) {
+ this.timestamp = datatime;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+
+}
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/AuthenticatedSessionStore.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/AuthenticatedSessionStore.java
new file mode 100644
index 000000000..ed865d70f
--- /dev/null
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/AuthenticatedSessionStore.java
@@ -0,0 +1,187 @@
+package at.gv.egovernment.moa.id.commons.db.dao.session;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Lob;
+import javax.persistence.OneToMany;
+import javax.persistence.PrePersist;
+import javax.persistence.PreUpdate;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+
+import org.hibernate.annotations.DynamicUpdate;
+
+
+@Entity
+@DynamicUpdate(value=true)
+@Table(name = "authenticatedsessionstore")
+@NamedQueries({
+ @NamedQuery(name="getSessionWithID", query = "select authenticatedsessionstore from AuthenticatedSessionStore authenticatedsessionstore where authenticatedsessionstore.sessionid = :sessionid"),
+ @NamedQuery(name="getSessionWithSSOID", query = "select authenticatedsessionstore from AuthenticatedSessionStore authenticatedsessionstore where authenticatedsessionstore.SSOsessionid = :sessionid"),
+ @NamedQuery(name="getSessionWithPendingRequestID", query = "select authenticatedsessionstore from AuthenticatedSessionStore authenticatedsessionstore where authenticatedsessionstore.pendingRequestID = :sessionid"),
+ @NamedQuery(name="getMOAISessionsWithTimeOut", query = "select authenticatedsessionstore from AuthenticatedSessionStore authenticatedsessionstore where authenticatedsessionstore.created < :timeoutcreate or authenticatedsessionstore.updated < :timeoutupdate")
+})
+
+public class AuthenticatedSessionStore implements Serializable{
+
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ @Column(name = "id", unique=true, nullable=false)
+ private long id;
+
+ @Column(name = "sessionid", unique=true, nullable=false)
+ private String sessionid;
+
+ @Column(name = "SSOsessionid")
+ private String SSOsessionid;
+
+ @Column(name = "session", nullable=false)
+ @Lob private byte [] session;
+
+ @Column(name = "isAuthenticated", nullable=false)
+ private boolean isAuthenticated = false;
+
+ @Column(name = "isSSOSession", nullable=false)
+ private boolean isSSOSession = false;
+
+ @Column(name = "pendingRequestID", nullable=false)
+ private String pendingRequestID = "";
+
+ @Column(name = "created", updatable=false, nullable=false)
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date created;
+
+ @Column(name = "updated")
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date updated;
+
+ @OneToMany(mappedBy="moasession", cascade=CascadeType.ALL)
+ private List<OASessionStore> activeOAsessions = null;
+
+ @OneToMany(mappedBy="moasession", cascade=CascadeType.ALL)
+ private List<OldSSOSessionIDStore> oldssosessionids = null;
+
+ @PrePersist
+ protected void created() {
+ this.updated = this.created = new Date();
+ }
+
+ @PreUpdate
+ protected void lastUpdate() {
+ this.updated = new Date();
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getSessionid() {
+ return sessionid;
+ }
+
+ public void setSessionid(String sessionid) {
+ this.sessionid = sessionid;
+ }
+
+ public String getSSOsessionid() {
+ return SSOsessionid;
+ }
+
+ public void setSSOsessionid(String sSOsessionid) {
+ SSOsessionid = sSOsessionid;
+ }
+
+ public byte[] getSession() {
+ return session;
+ }
+
+ public void setSession(byte[] session) {
+ this.session = session;
+ }
+
+ public boolean isAuthenticated() {
+ return isAuthenticated;
+ }
+
+ public void setAuthenticated(boolean isAuthenticated) {
+ this.isAuthenticated = isAuthenticated;
+ }
+
+ public boolean isSSOSession() {
+ return isSSOSession;
+ }
+
+ public void setSSOSession(boolean isSSOSession) {
+ this.isSSOSession = isSSOSession;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+
+ public void setCreated(Date created) {
+ this.created = created;
+ }
+
+ public Date getUpdated() {
+ return updated;
+ }
+
+ public void setUpdated(Date updated) {
+ this.updated = updated;
+ }
+
+ public List<OASessionStore> getActiveOAsessions() {
+ return activeOAsessions;
+ }
+
+ public void setActiveOAsessions(List<OASessionStore> activeOAsessions) {
+ if (activeOAsessions == null) {
+ this.activeOAsessions = new ArrayList<OASessionStore>();
+ }
+
+ this.activeOAsessions = activeOAsessions;
+ }
+
+ public List<OldSSOSessionIDStore> getOldssosessionids() {
+ return oldssosessionids;
+ }
+
+ public void setOldssosessionids(List<OldSSOSessionIDStore> oldssosessionids) {
+ this.oldssosessionids = oldssosessionids;
+ }
+
+ /**
+ * @return the pendingRequestID
+ */
+ public String getPendingRequestID() {
+ return pendingRequestID;
+ }
+
+ /**
+ * @param pendingRequestID the pendingRequestID to set
+ */
+ public void setPendingRequestID(String pendingRequestID) {
+ this.pendingRequestID = pendingRequestID;
+ }
+
+
+}
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
new file mode 100644
index 000000000..6e0f47805
--- /dev/null
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/OASessionStore.java
@@ -0,0 +1,87 @@
+package at.gv.egovernment.moa.id.commons.db.dao.session;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+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)
+@Table(name = "oasessionstore")
+
+public class OASessionStore implements Serializable{
+
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "idOASession", unique=true, nullable=false)
+ private long idOASession;
+
+ @Column(name = "oaurlprefix", unique=false, nullable=false)
+ private String oaurlprefix;
+
+ @Column(name = "created", updatable=false, nullable=false)
+// @Temporal(TemporalType.TIMESTAMP)
+ private Date created;
+
+// @PrePersist
+// protected void created() {
+// this.created = new Date();
+// }
+
+ @ManyToOne(fetch=FetchType.LAZY)
+ @JoinColumn(name = "moasession")
+ private AuthenticatedSessionStore moasession;
+
+ public long getIdOASession() {
+ return idOASession;
+ }
+
+ public void setIdOASession(long idOASession) {
+ this.idOASession = idOASession;
+ }
+
+ public String getOaurlprefix() {
+ return oaurlprefix;
+ }
+
+ public void setOaurlprefix(String oaurlprefix) {
+ this.oaurlprefix = oaurlprefix;
+ }
+
+ public AuthenticatedSessionStore getMoasession() {
+ return moasession;
+ }
+
+ public void setMoasession(AuthenticatedSessionStore moasession) {
+ this.moasession = moasession;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+
+ public void setCreated(Date created) {
+ this.created = created;
+ }
+
+
+
+}
+
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/OldSSOSessionIDStore.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/OldSSOSessionIDStore.java
new file mode 100644
index 000000000..3ec2babad
--- /dev/null
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/OldSSOSessionIDStore.java
@@ -0,0 +1,69 @@
+package at.gv.egovernment.moa.id.commons.db.dao.session;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+import org.hibernate.annotations.DynamicUpdate;
+import org.hibernate.annotations.NamedQueries;
+import org.hibernate.annotations.NamedQuery;
+
+@Entity
+@DynamicUpdate(value=true)
+@Table(name = "oldssosessionid")
+
+@NamedQueries({
+ @NamedQuery(name="getSSOSessionWithOldSessionID", query = "select oldssosessionid from OldSSOSessionIDStore oldssosessionid where oldssosessionid.oldsessionid = :sessionid")
+})
+
+public class OldSSOSessionIDStore implements Serializable{
+
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "idOldSSOSession", unique=true, nullable=false)
+ private long idOldSSOSession;
+
+ @Column(name = "oldsessionid", unique=true, nullable=false)
+ private String oldsessionid;
+
+ //@ManyToOne(fetch=FetchType.LAZY)
+ @ManyToOne(fetch=FetchType.LAZY)
+ @JoinColumn(name = "moasession")
+ private AuthenticatedSessionStore moasession;
+
+ public long getIdOldSSOSession() {
+ return idOldSSOSession;
+ }
+
+ public void setIdOldSSOSession(long idOldSSOSession) {
+ this.idOldSSOSession = idOldSSOSession;
+ }
+
+ public String getOldsessionid() {
+ return oldsessionid;
+ }
+
+ public void setOldsessionid(String oldsessionid) {
+ this.oldsessionid = oldsessionid;
+ }
+
+ public AuthenticatedSessionStore getMoasession() {
+ return moasession;
+ }
+
+ public void setMoasession(AuthenticatedSessionStore moasession) {
+ this.moasession = moasession;
+ }
+
+
+}
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ex/MOADatabaseException.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ex/MOADatabaseException.java
new file mode 100644
index 000000000..169d31aac
--- /dev/null
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ex/MOADatabaseException.java
@@ -0,0 +1,22 @@
+package at.gv.egovernment.moa.id.commons.db.ex;
+
+public class MOADatabaseException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public MOADatabaseException() {
+ super();
+ }
+
+ public MOADatabaseException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public MOADatabaseException(String message) {
+ super(message);
+ }
+
+ public MOADatabaseException(Throwable cause) {
+ super(cause);
+ }
+}