aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Lenz <tlenz@iaik.tugraz.at>2013-07-26 17:06:11 +0200
committerThomas Lenz <tlenz@iaik.tugraz.at>2013-07-26 17:06:11 +0200
commitcc2e2e4ecf5bd8c4bbe16edba5a7d63fa808adcb (patch)
tree21707a6f7248c0955eee6bba34621fdaee29730e
parent59fd2c0ea0649c94340d67b735a2d53696065e4c (diff)
downloadmoa-id-spss-cc2e2e4ecf5bd8c4bbe16edba5a7d63fa808adcb.tar.gz
moa-id-spss-cc2e2e4ecf5bd8c4bbe16edba5a7d63fa808adcb.tar.bz2
moa-id-spss-cc2e2e4ecf5bd8c4bbe16edba5a7d63fa808adcb.zip
Bugfix:
Database Session management
-rw-r--r--id/server/auth/.settings/org.eclipse.wst.common.component3
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java3
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/DispatcherServlet.java41
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/AuthenticationManager.java32
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/RequestImpl.java6
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/RequestStorage.java5
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/SSOManager.java6
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/AuthenticationSessionStoreage.java2
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/util/HTTPSessionUtils.java116
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBRead.java70
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBUtils.java38
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java18
-rw-r--r--id/server/moa-id-commons/src/main/resources/config/persistence_template.xml12
13 files changed, 219 insertions, 133 deletions
diff --git a/id/server/auth/.settings/org.eclipse.wst.common.component b/id/server/auth/.settings/org.eclipse.wst.common.component
index fa80111cf..b4ffa88f6 100644
--- a/id/server/auth/.settings/org.eclipse.wst.common.component
+++ b/id/server/auth/.settings/org.eclipse.wst.common.component
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="moa-id-auth">
+ <dependent-module archiveName="moa-spss-lib-1.5.2.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/moa-spss-lib/moa-spss-lib">
+ <dependency-type>uses</dependency-type>
+ </dependent-module>
<dependent-module archiveName="moa-common-1.5.2.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/moa-common/moa-common">
<dependency-type>uses</dependency-type>
</dependent-module>
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 ffcb85044..c71b6f8c7 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
@@ -387,8 +387,7 @@ public class AuthConfigurationProvider extends ConfigurationProvider {
//set TrustManagerRevocationChecking
setTrustManagerRevocationChecking();
-
-
+
} catch (Throwable t) {
throw new ConfigurationException("config.02", null, t);
}
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 e7b41e3c9..f70596949 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
@@ -123,8 +123,6 @@ public class DispatcherServlet extends AuthServlet{
}
-
-
if (errorRequest != null) {
try {
@@ -240,11 +238,22 @@ public class DispatcherServlet extends AuthServlet{
if (protocolRequests.containsKey(protocolRequestID)) {
protocolRequest = protocolRequests.get(protocolRequestID);
+
+
+ Logger.debug(DispatcherServlet.class.getName()+": Found PendingRequest with ID " + protocolRequestID);
+
//RequestStorage.setPendingRequest(httpSession, protocolRequests);
} else {
- resp.sendError(HttpServletResponse.SC_CONFLICT);
- Logger.error("No PendingRequest with ID " + protocolRequestID + " found for this session!");
+ Logger.error("No PendingRequest with ID " + protocolRequestID + " found.!");
+
+ Set<String> mapkeys = protocolRequests.keySet();
+ for (String el : mapkeys)
+ Logger.debug("PendingRequest| ID=" + el + " OAIdentifier=" + protocolRequests.get(el));
+
+ handleErrorNoRedirect("Während des Anmeldevorgangs ist ein Fehler aufgetreten. Bitte versuchen Sie es noch einmal.",
+ null, req, resp);
+ //resp.sendError(HttpServletResponse.SC_CONFLICT);
return;
}
// }
@@ -265,12 +274,10 @@ public class DispatcherServlet extends AuthServlet{
if (value.getOAURL().equals(protocolRequest.getOAURL())) {
if(!AuthenticationSessionStoreage.deleteSessionWithPendingRequestID(el)) {
- Logger.warn("NO MOASession with PendingRequestID " + el + " found. Delete all user sessions!");
+ Logger.warn(DispatcherServlet.class.getName()+": NO MOASession with PendingRequestID " + el + " found. Delete all user sessions!");
RequestStorage.removeAllPendingRequests(req.getSession());
} else {
-
-
RequestStorage.removePendingRequest(protocolRequests, el);
}
}
@@ -291,6 +298,7 @@ public class DispatcherServlet extends AuthServlet{
protocolRequestID = Random.nextRandom();
protocolRequest.setRequestID(protocolRequestID);
protocolRequests.put(protocolRequestID, protocolRequest);
+ Logger.debug(DispatcherServlet.class.getName()+": Create PendingRequest with ID " + protocolRequestID + ".");
}
}
}
@@ -312,7 +320,8 @@ public class DispatcherServlet extends AuthServlet{
//load Parameters from OnlineApplicationConfiguration
OAAuthParameter oaParam = AuthConfigurationProvider.getInstance()
- .getOnlineApplicationParameter(protocolRequest.getOAURL());
+ .getOnlineApplicationParameter(protocolRequest.getOAURL());
+
if (oaParam == null) {
throw new AuthenticationException("auth.00", new Object[] { protocolRequest.getOAURL() });
}
@@ -402,8 +411,11 @@ public class DispatcherServlet extends AuthServlet{
else {
//TODO: maybe transmit moasessionID with http GET to handle more then one PendingRequest!
- moasessionID = HTTPSessionUtils.getHTTPSessionString(req.getSession(),
- AuthenticationManager.MOA_SESSION, null);
+ moasessionID = (String) req.getParameter(PARAM_SESSIONID);
+
+// moasessionID = HTTPSessionUtils.getHTTPSessionString(req.getSession(),
+// AuthenticationManager.MOA_SESSION, null);
+
moasession = AuthenticationSessionStoreage.getSession(moasessionID);
}
@@ -418,8 +430,11 @@ public class DispatcherServlet extends AuthServlet{
}
} else {
- moasessionID = HTTPSessionUtils.getHTTPSessionString(req.getSession(),
- AuthenticationManager.MOA_SESSION, null);
+// moasessionID = HTTPSessionUtils.getHTTPSessionString(req.getSession(),
+// AuthenticationManager.MOA_SESSION, null);
+
+ moasessionID = (String) req.getParameter(PARAM_SESSIONID);
+
moasession = AuthenticationSessionStoreage.getSession(moasessionID);
}
@@ -437,7 +452,7 @@ public class DispatcherServlet extends AuthServlet{
authmanager.logout(req, resp, moasessionID);
}
-// ConfigurationDBUtils.closeSession();
+ ConfigurationDBUtils.closeSession();
//authmanager.logout(req, resp);
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/AuthenticationManager.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/AuthenticationManager.java
index b9f0b2144..be0132c14 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/AuthenticationManager.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/AuthenticationManager.java
@@ -48,20 +48,20 @@ public class AuthenticationManager extends AuthServlet {
}
- public AuthenticationSession getAuthenticationSession(
- HttpSession session) {
- String sessionID = HTTPSessionUtils.getHTTPSessionString(session,
- MOA_SESSION, null);
- if (sessionID != null) {
- try {
- return AuthenticationSessionStoreage.getSession(sessionID);
-
- } catch (MOADatabaseException e) {
- return null;
- }
- }
- return null;
- }
+// public AuthenticationSession getAuthenticationSession(
+// HttpSession session) {
+// String sessionID = HTTPSessionUtils.getHTTPSessionString(session,
+// MOA_SESSION, null);
+// if (sessionID != null) {
+// try {
+// return AuthenticationSessionStoreage.getSession(sessionID);
+//
+// } catch (MOADatabaseException e) {
+// return null;
+// }
+// }
+// return null;
+// }
// /**
// * Checks if the session is authenticated
@@ -134,8 +134,8 @@ public class AuthenticationManager extends AuthServlet {
AuthenticationSessionStoreage.storeSession(authSession);
- HTTPSessionUtils.setHTTPSessionString(session, MOA_SESSION,
- sessionID);
+// HTTPSessionUtils.setHTTPSessionString(session, MOA_SESSION,
+// sessionID);
return true; // got authenticated
}
}
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/RequestImpl.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/RequestImpl.java
index 420f11622..d47e8df05 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/RequestImpl.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/RequestImpl.java
@@ -1,7 +1,11 @@
package at.gv.egovernment.moa.id.moduls;
-public class RequestImpl implements IRequest {
+import java.io.Serializable;
+public class RequestImpl implements IRequest, Serializable{
+
+ private static final long serialVersionUID = 1L;
+
private String oaURL;
private boolean passiv = false;
private boolean force = false;
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/RequestStorage.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/RequestStorage.java
index 35481a0a1..d33d4693d 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/RequestStorage.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/RequestStorage.java
@@ -41,6 +41,9 @@ public class RequestStorage {
}
public static void removeAllPendingRequests(HttpSession session) {
+
+ Logger.debug(RequestStorage.class.getName()+": Remove all PendingRequests");
+
session.setAttribute(PENDING_REQUEST, null);
}
@@ -54,7 +57,7 @@ public class RequestStorage {
if (requestmap.containsKey(requestID)) {
requestmap.remove(requestID);
- Logger.debug("Remove PendingRequest with ID " + requestID);
+ Logger.debug(RequestStorage.class.getName()+": Remove PendingRequest with ID " + requestID);
}
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/SSOManager.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/SSOManager.java
index 82273da83..18eeae58e 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/SSOManager.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/SSOManager.java
@@ -59,10 +59,10 @@ public class SSOManager {
return false;
}
- String moaSessionId =HTTPSessionUtils.getHTTPSessionString(httpReq.getSession(),
- AuthenticationManager.MOA_SESSION, null);
+// String moaSessionId =HTTPSessionUtils.getHTTPSessionString(httpReq.getSession(),
+// AuthenticationManager.MOA_SESSION, null);
- return AuthenticationSessionStoreage.isValidSessionWithSSOID(ssoSessionID, moaSessionId);
+ return AuthenticationSessionStoreage.isValidSessionWithSSOID(ssoSessionID, null);
}
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/AuthenticationSessionStoreage.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/AuthenticationSessionStoreage.java
index 1f71bf8bf..498188ffe 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/AuthenticationSessionStoreage.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/AuthenticationSessionStoreage.java
@@ -346,7 +346,7 @@ public class AuthenticationSessionStoreage {
public static boolean isValidSessionWithSSOID(String SSOId, String moaSessionId) {
- MiscUtil.assertNotNull(SSOId, "moasessionID");
+ MiscUtil.assertNotNull(SSOId, "SSOSessionID");
Logger.trace("Get authenticated session with SSOID " + SSOId + " from database.");
Session session = MOASessionDBUtils.getCurrentSession();
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/util/HTTPSessionUtils.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/util/HTTPSessionUtils.java
index 896fc6d5d..1e9cb9024 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/util/HTTPSessionUtils.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/util/HTTPSessionUtils.java
@@ -9,62 +9,62 @@ import javax.servlet.http.HttpSession;
public class HTTPSessionUtils {
- public static HashMap<String, Object> extractAllProperties(HttpSession session) {
- @SuppressWarnings("unchecked")
- Enumeration<String> keys = (Enumeration<String>)session.getAttributeNames();
- HashMap<String, Object> properties = new HashMap<String, Object>();
-
- while(keys.hasMoreElements()) {
- Object keyObject = keys.nextElement();
- String key = keyObject.toString();
- Object value = session.getAttribute(key);
- properties.put(key, value);
- }
-
- return properties;
- }
-
- public static void pushAllProperties(HttpSession session, HashMap<String, Object> properties) {
- Set<String> keys = properties.keySet();
- Iterator<String> keysIterator = keys.iterator();
- while(keysIterator.hasNext()) {
- String key = keysIterator.next();
- session.setAttribute(key, properties.get(key));
- }
- }
-
- public static boolean getHTTPSessionBoolean(HttpSession session, String name, boolean fallback) {
- Object obj = session.getAttribute(name);
- if(obj == null) {
- return fallback;
- }
-
- if(obj instanceof Boolean) {
- Boolean b = (Boolean)obj;
- if(b != null) {
- return b.booleanValue();
- }
- }
- return fallback;
- }
-
- public static void setHTTPSessionBoolean(HttpSession session, String name, boolean value) {
- session.setAttribute(name, new Boolean(value));
- }
-
- public static String getHTTPSessionString(HttpSession session, String name, String fallback) {
- Object obj = session.getAttribute(name);
- if(obj == null) {
- return fallback;
- }
-
- if(obj instanceof String) {
- return (String)obj;
- }
- return fallback;
- }
-
- public static void setHTTPSessionString(HttpSession session, String name, String value) {
- session.setAttribute(name, value);
- }
+// public static HashMap<String, Object> extractAllProperties(HttpSession session) {
+// @SuppressWarnings("unchecked")
+// Enumeration<String> keys = (Enumeration<String>)session.getAttributeNames();
+// HashMap<String, Object> properties = new HashMap<String, Object>();
+//
+// while(keys.hasMoreElements()) {
+// Object keyObject = keys.nextElement();
+// String key = keyObject.toString();
+// Object value = session.getAttribute(key);
+// properties.put(key, value);
+// }
+//
+// return properties;
+// }
+//
+// public static void pushAllProperties(HttpSession session, HashMap<String, Object> properties) {
+// Set<String> keys = properties.keySet();
+// Iterator<String> keysIterator = keys.iterator();
+// while(keysIterator.hasNext()) {
+// String key = keysIterator.next();
+// session.setAttribute(key, properties.get(key));
+// }
+// }
+//
+// public static boolean getHTTPSessionBoolean(HttpSession session, String name, boolean fallback) {
+// Object obj = session.getAttribute(name);
+// if(obj == null) {
+// return fallback;
+// }
+//
+// if(obj instanceof Boolean) {
+// Boolean b = (Boolean)obj;
+// if(b != null) {
+// return b.booleanValue();
+// }
+// }
+// return fallback;
+// }
+//
+// public static void setHTTPSessionBoolean(HttpSession session, String name, boolean value) {
+// session.setAttribute(name, new Boolean(value));
+// }
+//
+// public static String getHTTPSessionString(HttpSession session, String name, String fallback) {
+// Object obj = session.getAttribute(name);
+// if(obj == null) {
+// return fallback;
+// }
+//
+// if(obj instanceof String) {
+// return (String)obj;
+// }
+// return fallback;
+// }
+//
+// public static void setHTTPSessionString(HttpSession session, String name, String value) {
+// session.setAttribute(name, value);
+// }
}
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 7a6efc5ac..80d95628e 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
@@ -8,6 +8,7 @@ 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;
@@ -16,8 +17,11 @@ public class ConfigurationDBRead {
private static Map<String, String> QUERIES = new HashMap<String, String>();
static {
- QUERIES.put("getOnlineApplicationWithID", "select onlineapplication from OnlineApplication onlineapplication where onlineapplication.publicURLPrefix like SUBSTRING(:id, 1, LENGTH(onlineapplication.publicURLPrefix))");
+ QUERIES.put("getOnlineApplicationWithID", "select onlineapplication from OnlineApplication onlineapplication where onlineapplication.publicURLPrefix like SUBSTRING(:id, 1, LENGTH(onlineapplication.publicURLPrefix)) and onlineapplication.isActive = '1'");
QUERIES.put("getMOAIDConfiguration", "select moaidconfiguration from MOAIDConfiguration moaidconfiguration");
+ QUERIES.put("getAllOnlineApplications", "select onlineapplication from OnlineApplication onlineapplication");
+ QUERIES.put("getUserWithUserID", "select userdatabase from UserDatabase userdatabase where userdatabase.id = :id");
+
}
@SuppressWarnings("rawtypes")
@@ -26,20 +30,21 @@ public class ConfigurationDBRead {
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();
+ EntityManager session = ConfigurationDBUtils.getCurrentSession();
- Logger.trace("Found entries: " + result.size());
-
- if (result.size() == 0) {
- Logger.trace("No entries found.");
- return null;
- }
- return (OnlineApplication) result.get(0);
+ 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);
}
public static MOAIDConfiguration getMOAIDConfiguration() {
@@ -57,8 +62,45 @@ public class ConfigurationDBRead {
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 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);
+ }
}
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 4bb0a08ea..d3ee1442e 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,6 +8,7 @@ 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;
@@ -44,10 +45,8 @@ public final class ConfigurationDBUtils {
entitymanagerfactory =
Persistence.createEntityManagerFactory("at.gv.egovernment.moa.id.commons.db.dao.config",
props);
-
-
-
- Logger.debug("Initial session factory successfully created.");
+
+ Logger.debug("Initial ConfigDB session factory successfully created.");
} catch (Throwable ex) {
@@ -72,10 +71,21 @@ public final class ConfigurationDBUtils {
}
EntityManager session = (EntityManager) THREAD_LOCAL_CONFIG.get();
- // Open a new Session, if this Thread has none yet
- if (session == null || !session.isOpen()) {
- session = getNewSession();
- }
+
+ 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) {
+ session = getNewSession();
+ }
+
+ } else
+ session = getNewSession();
+
return session;
}
@@ -88,10 +98,10 @@ public final class ConfigurationDBUtils {
}
EntityManager session = (EntityManager) THREAD_LOCAL_CONFIG.get();
if (session != null ) {
- Logger.warn("Previous session has not been closed; closing session now.");
+ Logger.warn("Previous session has not been closed; closing ConfigDB session now.");
closeSession();
}
- Logger.debug("Opening new hibernate session...");
+ Logger.debug("Opening new ConfigDB hibernate session...");
try {
session = entitymanagerfactory.createEntityManager();
THREAD_LOCAL_CONFIG.set(session);
@@ -114,7 +124,7 @@ public final class ConfigurationDBUtils {
Logger.warn("Session is being automatically handled by hibernate. Therefore the current session cannot be closed on demand.");
return;
}
- Logger.debug("Closing current hibernate session...");
+ Logger.debug("Closing current ConfigDB hibernate session...");
EntityManager session = (EntityManager) THREAD_LOCAL_CONFIG.get();
THREAD_LOCAL_CONFIG.set(null);
if (session != null) {
@@ -144,7 +154,7 @@ public final class ConfigurationDBUtils {
return true;
} catch(HibernateException e) {
- Logger.warn("Error during database saveOrUpdate. Rollback.", e);
+ Logger.warn("Error during Config database saveOrUpdate. Rollback.", e);
tx.rollback();
throw new MOADatabaseException(e);
}
@@ -171,7 +181,7 @@ public final class ConfigurationDBUtils {
return true;
} catch(HibernateException e) {
- Logger.warn("Error during database saveOrUpdate. Rollback.", e);
+ Logger.warn("Error during Config database saveOrUpdate. Rollback.", e);
tx.rollback();
throw new MOADatabaseException(e);
}
@@ -194,7 +204,7 @@ public final class ConfigurationDBUtils {
return true;
} catch(HibernateException e) {
- Logger.warn("Error during database delete. Rollback.", 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
index a89ede528..5e4ec0f13 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
@@ -38,7 +38,7 @@ public final class MOASessionDBUtils {
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;
+ 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) {
@@ -48,15 +48,15 @@ public final class MOASessionDBUtils {
}
try {
//Create the SessionFactory
- Logger.debug("Creating initial session factory...");
+ Logger.debug("Creating initial MOASession session factory...");
config.configure();
serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
sessionFactory = config.buildSessionFactory(serviceRegistry);
- Logger.debug("Initial session factory successfully created.");
+ Logger.debug("Initial MOASession session factory successfully created.");
} catch (Throwable ex) {
- Logger.error("Initial session factory creation failed: " + ex.getMessage());
+ Logger.error("Initial MOASession session factory creation failed: " + ex.getMessage());
throw new ExceptionInInitializerError(ex);
}
}
@@ -89,10 +89,10 @@ public final class MOASessionDBUtils {
}
Session session = (Session) THREAD_LOCAL.get();
if (session != null) {
- Logger.warn("Previous session has not been closed; closing session now.");
+ Logger.warn("Previous MOASession session has not been closed; closing session now.");
closeSession();
}
- Logger.debug("Opening new hibernate session...");
+ Logger.debug("Opening new MOASession hibernate session...");
try {
session = sessionFactory.openSession();
THREAD_LOCAL.set(session);
@@ -115,7 +115,7 @@ public final class MOASessionDBUtils {
Logger.warn("Session is being automatically handled by hibernate. Therefore the current session cannot be closed on demand.");
return;
}
- Logger.debug("Closing current hibernate session...");
+ Logger.debug("Closing current MOASession hibernate session...");
Session session = (Session) THREAD_LOCAL.get();
THREAD_LOCAL.set(null);
if (session != null) {
@@ -141,7 +141,7 @@ public final class MOASessionDBUtils {
return true;
} catch(HibernateException e) {
- Logger.warn("Error during database saveOrUpdate. Rollback.", e);
+ Logger.warn("Error during MOASession database saveOrUpdate. Rollback.", e);
tx.rollback();
throw new MOADatabaseException(e);
}
@@ -161,7 +161,7 @@ public final class MOASessionDBUtils {
return true;
} catch(HibernateException e) {
- Logger.warn("Error during database delete. Rollback.", e);
+ Logger.warn("Error during MOASession database delete. Rollback.", e);
tx.rollback();
return false;
}
diff --git a/id/server/moa-id-commons/src/main/resources/config/persistence_template.xml b/id/server/moa-id-commons/src/main/resources/config/persistence_template.xml
index 727be25ec..bd60f5a46 100644
--- a/id/server/moa-id-commons/src/main/resources/config/persistence_template.xml
+++ b/id/server/moa-id-commons/src/main/resources/config/persistence_template.xml
@@ -2,6 +2,16 @@
<persistence version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:orm="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<persistence-unit name="##generated">
- <class>at.gv.egovernment.moa.id.commons.db.dao.config.UserDatabase</class>
+ <class>at.gv.egovernment.moa.id.commons.db.dao.config.UserDatabase</class>
+
+<!-- <properties>
+ C3p0 connection pooling configuration
+ <property name="hibernate.connection.provider_class" value="org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider"/>
+ <property name="hibernate.connection.provider_class" value="org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider"/>
+ <property name="acquireRetryDelay" value="5000"/>
+ <property name="breakAfterAcquireFailure" value="true"/>
+ <property name="checkoutTimeout" value="1"/>
+ <property name="testConnectionOnCheckin" value="1" />
+ </properties> -->
</persistence-unit>
</persistence>