details:   https://code.openbravo.com/erp/devel/pi/rev/275afe71cbfd
changeset: 31996:275afe71cbfd
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Apr 27 10:18:39 2017 +0200
summary:   related to bug 35855: requests borrow more than one connection from 
DB

  Solved Login window + HSAS infrastructure by using only connection obtained
  for DAL.

details:   https://code.openbravo.com/erp/devel/pi/rev/0135d8bfedaa
changeset: 31997:0135d8bfedaa
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Apr 27 10:48:37 2017 +0200
summary:   related to bug 35855: requests borrow more than one connection from 
DB

  Usage audit is now inserted within the same DAL transaction.

details:   https://code.openbravo.com/erp/devel/pi/rev/4c129bcea4c0
changeset: 31998:4c129bcea4c0
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Apr 27 14:37:18 2017 +0200
summary:   fixed bug 35855: requests borrow more than one connection from DB

  Prevent double connection when generating dynamic js for 2.50 windows

details:   https://code.openbravo.com/erp/devel/pi/rev/14c7240bde7a
changeset: 31999:14c7240bde7a
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Apr 27 15:21:17 2017 +0200
summary:   fixed bug 35865: remove unused UsageAudit methods

details:   https://code.openbravo.com/erp/devel/pi/rev/d19e0b10bb45
changeset: 32000:d19e0b10bb45
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Apr 27 16:50:24 2017 +0200
summary:   fixed bug 35855: requests borrow more than one connection from DB

  Some more cases in login

details:   https://code.openbravo.com/erp/devel/pi/rev/6d6a1ff11e48
changeset: 32001:6d6a1ff11e48
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Apr 27 17:50:23 2017 +0200
summary:   fixed bug 35855: requests borrow more than one connection from DB

  More cases in login page

details:   https://code.openbravo.com/erp/devel/pi/rev/6fb8997012e9
changeset: 32002:6fb8997012e9
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Fri Apr 28 09:37:24 2017 +0200
summary:   fixed bug 35855: requests borrow more than one connection from DB

  Partially revererted changes in AuthenticationManager. DalConnectionProvider
  is not thread safe, if accessed by 2 threads it is possible T1 to acquire a
  connection that's closed by T2 while still in use by T1.

  So DCP is not cached in AuthenticationManager but cached pool is not used in
  DefaultAuthenticationManger, instead it creates its own DCP in authenticate
  method.

details:   https://code.openbravo.com/erp/devel/pi/rev/ae4c54d915ad
changeset: 32003:ae4c54d915ad
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Tue May 02 09:27:56 2017 +0200
summary:   fixed bug 35855: requests borrow more than one connection from DB

   Before starting module rebuild through MMC, finalize current transaction to
   release any lock it might have acquired.

   This is now needed because HSAS for this servlet have occurred in the same
   transaction and are still held, before they were already realeased becuase
   they were executed in auto-commit short transactions.

diffstat:

 src/org/openbravo/authentication/basic/DefaultAuthenticationManager.java |    
8 +-
 src/org/openbravo/base/secureApp/HttpSecureAppServlet.java               |   
34 +-
 src/org/openbravo/base/secureApp/LoginHandler.java                       |   
80 +++--
 src/org/openbravo/erpCommon/ad_process/ApplyModules.java                 |    
6 +-
 src/org/openbravo/erpCommon/security/Login.java                          |   
44 +-
 src/org/openbravo/erpCommon/security/SessionLogin_data.xsql              |    
2 +-
 src/org/openbravo/erpCommon/security/UsageAudit.java                     |  
136 +--------
 src/org/openbravo/erpCommon/utility/DynamicJS.java                       |    
5 +-
 src/org/openbravo/service/db/DalConnectionProvider.java                  |    
3 +
 9 files changed, 117 insertions(+), 201 deletions(-)

diffs (truncated from 754 to 300 lines):

diff -r 257643f9f61d -r ae4c54d915ad 
src/org/openbravo/authentication/basic/DefaultAuthenticationManager.java
--- a/src/org/openbravo/authentication/basic/DefaultAuthenticationManager.java  
Tue Apr 18 00:18:59 2017 +0530
+++ b/src/org/openbravo/authentication/basic/DefaultAuthenticationManager.java  
Tue May 02 09:27:56 2017 +0200
@@ -35,9 +35,11 @@
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
+import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.model.ad.access.User;
+import org.openbravo.service.db.DalConnectionProvider;
 import org.openbravo.service.web.BaseWebServiceServlet;
 
 /**
@@ -135,7 +137,7 @@
       throw e;
     }
     final String sessionId = createDBSession(request, user, userId);
-
+    ConnectionProvider cp = new DalConnectionProvider(false);
     if (userId == null) {
       OBError errorMsg = new OBError();
       errorMsg.setType("Error");
@@ -143,7 +145,7 @@
       // LoginUtils.getValidUserId() called by default implementation of 
checkUserPassword() returns
       // null when the user is locked and when the user password is wrong.
       // LoginUtils.checkUserPassword() is called to check the real cause of 
null user id.
-      if (LoginUtils.checkUserPassword(conn, user, pass) == null) {
+      if (LoginUtils.checkUserPassword(cp, user, pass) == null) {
         log4j.debug("Failed user/password. Username: " + user + " - Session 
ID:" + sessionId);
         errorMsg.setTitle("IDENTIFICATION_FAILURE_TITLE");
         errorMsg.setMessage("IDENTIFICATION_FAILURE_MSG");
@@ -169,7 +171,7 @@
 
     if (!StringUtils.isEmpty(strAjax) && StringUtils.isEmpty(userId)) {
       bdErrorAjax(response, "Error", "",
-          Utility.messageBD(this.conn, "NotLogged", variables.getLanguage()));
+          Utility.messageBD(cp, "NotLogged", variables.getLanguage()));
       return null;
     } else {
       // redirects to the menu or the menu with the target
diff -r 257643f9f61d -r ae4c54d915ad 
src/org/openbravo/base/secureApp/HttpSecureAppServlet.java
--- a/src/org/openbravo/base/secureApp/HttpSecureAppServlet.java        Tue Apr 
18 00:18:59 2017 +0530
+++ b/src/org/openbravo/base/secureApp/HttpSecureAppServlet.java        Tue May 
02 09:27:56 2017 +0200
@@ -131,7 +131,8 @@
       log4j.debug("Servlet request for class info: " + this.getClass());
 
       if (classInfo == null) {
-        ClassInfoData[] classInfoAux = ClassInfoData.select(this, 
this.getClass().getName());
+        ClassInfoData[] classInfoAux = ClassInfoData.select(new 
DalConnectionProvider(false), this
+            .getClass().getName());
         if (classInfoAux != null && classInfoAux.length > 0)
           classInfo = classInfoAux[0];
         else {
@@ -202,6 +203,7 @@
 
     String strUserAuth;
 
+    ConnectionProvider cp = new DalConnectionProvider(false);
     try {
 
       OBContext.setAdminMode();
@@ -223,7 +225,8 @@
         if (areThereLicenseRestrictions(null)) {
           throw new AuthenticationException("No valid license");
         }
-        // make sure that there is an OBContext for the logged in user also in 
case of stateless requests
+        // make sure that there is an OBContext for the logged in user also in 
case of stateless
+        // requests
         if (OBContext.getOBContext() == null
             || 
!strUserAuth.equals(OBContext.getOBContext().getUser().getId())) {
           
OBContext.setOBContext(UserContextCache.getInstance().getCreateOBContext(strUserAuth));
@@ -240,7 +243,7 @@
       // is done by the fillSessionArguments below
       if (!variables.isLoggingIn()) {
         // log in process is completed, check whether the session in db is 
still active
-        loggedOK = SeguridadData.loggedOK(this, variables.getDBSession());
+        loggedOK = SeguridadData.loggedOK(cp, variables.getDBSession());
         if (!loggedOK) {
           if (request.getSession(false) != null
               && "Y".equals(request.getSession().getAttribute("forceLogin"))) {
@@ -276,11 +279,11 @@
           if (areThereLicenseRestrictions(variables.getDBSession()) || 
!correctSystemStatus
               || onlySystemAdminAvailable) {
             // it is only allowed to log as system administrator
-            strRole = DefaultOptionsData.getDefaultSystemRole(this, 
strUserAuth);
+            strRole = DefaultOptionsData.getDefaultSystemRole(cp, strUserAuth);
             if (strRole == null || strRole.equals("")) {
               final OBError roleError = new OBError();
               roleError.setType("Error");
-              roleError.setMessage(Utility.messageBD(this, 
"SystemLoginRequired",
+              roleError.setMessage(Utility.messageBD(cp, "SystemLoginRequired",
                   variables.getLanguage()));
               invalidLogin(request, response, roleError);
 
@@ -291,20 +294,20 @@
             strWarehouse = "";
           } else {
             RoleDefaults defaults = LoginUtils.getLoginDefaults(strUserAuth, 
variables.getRole(),
-                this);
+                cp);
             strRole = defaults.role;
             strClient = defaults.client;
             strOrg = defaults.org;
             strWarehouse = defaults.warehouse;
           }
 
-          DefaultOptionsData dataLanguage[] = 
DefaultOptionsData.defaultLanguage(this, strUserAuth);
+          DefaultOptionsData dataLanguage[] = 
DefaultOptionsData.defaultLanguage(cp, strUserAuth);
           if (dataLanguage != null && dataLanguage.length > 0) {
             strLanguage = dataLanguage[0].getField("DEFAULT_AD_LANGUAGE");
             strIsRTL = dataLanguage[0].getField("ISRTL");
           }
           if (strLanguage == null || strLanguage.equals("")) {
-            dataLanguage = DefaultOptionsData.getDefaultLanguage(this);
+            dataLanguage = DefaultOptionsData.getDefaultLanguage(cp);
             if (dataLanguage != null && dataLanguage.length > 0) {
               strLanguage = dataLanguage[0].getField("AD_LANGUAGE");
               strIsRTL = dataLanguage[0].getField("ISRTL");
@@ -313,7 +316,7 @@
 
           // note fill session arguments will set the LOGGINGIN session var
           // to N
-          if (LoginUtils.fillSessionArguments(this, vars, strUserAuth, 
strLanguage, strIsRTL,
+          if (LoginUtils.fillSessionArguments(cp, vars, strUserAuth, 
strLanguage, strIsRTL,
               strRole, strClient, strOrg, strWarehouse)) {
             readProperties(vars);
             readNumberFormat(vars, globalParameters.getFormatPath());
@@ -450,7 +453,7 @@
         }
         long t = System.currentTimeMillis();
         super.serviceInitialized(request, response);
-        UsageAudit.auditActionNoDal(this, vars1, this.getClass().getName(),
+        UsageAudit.auditActionNoDal(cp, vars1, this.getClass().getName(),
             System.currentTimeMillis() - t);
       } else {
         if ((strPopUp != null && !strPopUp.equals("")) || 
classInfo.type.equals("S")) {
@@ -527,19 +530,20 @@
    */
   protected boolean hasGeneralAccess(VariablesSecureApp vars, String type, 
String id) {
     try {
-      final String accessLevel = SeguridadData.selectAccessLevel(this, type, 
id);
+      ConnectionProvider cp = new DalConnectionProvider(false);
+      final String accessLevel = SeguridadData.selectAccessLevel(cp, type, id);
       vars.setSessionValue("#CurrentAccessLevel", accessLevel);
       if (type.equals("W")) {
         return hasLevelAccess(vars, accessLevel)
-            && SeguridadData.selectAccess(this, vars.getRole(), "TABLE", 
id).equals("0")
-            && !SeguridadData.selectAccess(this, vars.getRole(), type, 
id).equals("0");
+            && SeguridadData.selectAccess(cp, vars.getRole(), "TABLE", 
id).equals("0")
+            && !SeguridadData.selectAccess(cp, vars.getRole(), type, 
id).equals("0");
       } else if (type.equals("S")) {
-        return !SeguridadData.selectAccessSearch(this, vars.getRole(), 
id).equals("0");
+        return !SeguridadData.selectAccessSearch(cp, vars.getRole(), 
id).equals("0");
       } else if (type.equals("C"))
         return true;
       else
         return hasLevelAccess(vars, accessLevel)
-            && !SeguridadData.selectAccess(this, vars.getRole(), type, 
id).equals("0");
+            && !SeguridadData.selectAccess(cp, vars.getRole(), type, 
id).equals("0");
     } catch (final Exception e) {
       log4j.error("Error checking access: ", e);
       return false;
diff -r 257643f9f61d -r ae4c54d915ad 
src/org/openbravo/base/secureApp/LoginHandler.java
--- a/src/org/openbravo/base/secureApp/LoginHandler.java        Tue Apr 18 
00:18:59 2017 +0530
+++ b/src/org/openbravo/base/secureApp/LoginHandler.java        Tue May 02 
09:27:56 2017 +0200
@@ -35,6 +35,7 @@
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
+import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.businessUtility.Preferences;
 import org.openbravo.erpCommon.businessUtility.Preferences.QueryFilter;
 import org.openbravo.erpCommon.obps.ActivationKey;
@@ -51,6 +52,7 @@
 import org.openbravo.model.ad.system.Client;
 import org.openbravo.model.ad.system.SystemInformation;
 import org.openbravo.server.ServerControllerHandler;
+import org.openbravo.service.db.DalConnectionProvider;
 import org.openbravo.utils.FormatUtilities;
 
 /**
@@ -185,12 +187,13 @@
   protected final void checkLicenseAndGo(HttpServletResponse res, 
VariablesSecureApp vars,
       String strUserAuth, String username, String sessionId) throws 
IOException, ServletException {
     OBContext.setAdminMode();
+    ConnectionProvider cp = new DalConnectionProvider(false);
     try {
       ActivationKey ak = ActivationKey.getInstance(true);
       boolean hasSystem = false;
 
       try {
-        hasSystem = SeguridadData.hasSystemRole(this, strUserAuth);
+        hasSystem = SeguridadData.hasSystemRole(cp, strUserAuth);
       } catch (Exception ignore) {
         log4j.error(ignore);
       }
@@ -215,17 +218,17 @@
       // allowed to login only as system administrator
       switch (limitation) {
       case NUMBER_OF_CONCURRENT_USERS_REACHED:
-        String msg = Utility.messageBD(myPool, 
"NUMBER_OF_CONCURRENT_USERS_REACHED",
-            vars.getLanguage());
-        String title = Utility.messageBD(myPool, 
"NUMBER_OF_CONCURRENT_USERS_REACHED_TITLE",
+        String msg = Utility
+            .messageBD(cp, "NUMBER_OF_CONCURRENT_USERS_REACHED", 
vars.getLanguage());
+        String title = Utility.messageBD(cp, 
"NUMBER_OF_CONCURRENT_USERS_REACHED_TITLE",
             vars.getLanguage());
         log4j.warn("Concurrent Users Reached - Session: " + sessionId);
         updateDBSession(sessionId, msgType.equals("Warning"), "CUR");
         goToRetry(res, vars, msg, title, msgType, action);
         return;
       case NUMBER_OF_SOFT_USERS_REACHED:
-        msg = Utility.messageBD(myPool, "NUMBER_OF_SOFT_USERS_REACHED", 
vars.getLanguage());
-        title = Utility.messageBD(myPool, 
"NUMBER_OF_SOFT_USERS_REACHED_TITLE", vars.getLanguage());
+        msg = Utility.messageBD(cp, "NUMBER_OF_SOFT_USERS_REACHED", 
vars.getLanguage());
+        title = Utility.messageBD(cp, "NUMBER_OF_SOFT_USERS_REACHED_TITLE", 
vars.getLanguage());
         action = "../security/Menu.html";
         msgType = "Warning";
         log4j.warn("Soft Users Reached - Session: " + sessionId);
@@ -233,15 +236,15 @@
         goToRetry(res, vars, msg, title, msgType, action);
         return;
       case OPS_INSTANCE_NOT_ACTIVE:
-        msg = Utility.messageBD(myPool, "OPS_INSTANCE_NOT_ACTIVE", 
vars.getLanguage());
-        title = Utility.messageBD(myPool, "OPS_INSTANCE_NOT_ACTIVE_TITLE", 
vars.getLanguage());
+        msg = Utility.messageBD(cp, "OPS_INSTANCE_NOT_ACTIVE", 
vars.getLanguage());
+        title = Utility.messageBD(cp, "OPS_INSTANCE_NOT_ACTIVE_TITLE", 
vars.getLanguage());
         log4j.warn("Innactive OBPS instance - Session: " + sessionId);
         updateDBSession(sessionId, msgType.equals("Warning"), "IOBPS");
         goToRetry(res, vars, msg, title, msgType, action);
         return;
       case MODULE_EXPIRED:
-        msg = Utility.messageBD(myPool, "OPS_MODULE_EXPIRED", 
vars.getLanguage());
-        title = Utility.messageBD(myPool, "OPS_MODULE_EXPIRED_TITLE", 
vars.getLanguage());
+        msg = Utility.messageBD(cp, "OPS_MODULE_EXPIRED", vars.getLanguage());
+        title = Utility.messageBD(cp, "OPS_MODULE_EXPIRED_TITLE", 
vars.getLanguage());
         StringBuffer expiredMoudules = new StringBuffer();
         log4j.warn("Expired modules - Session: " + sessionId);
         for (Module module : ak.getExpiredInstalledModules()) {
@@ -253,22 +256,22 @@
         goToRetry(res, vars, msg, title, msgType, action);
         return;
       case NOT_MATCHED_INSTANCE:
-        msg = Utility.messageBD(myPool, "OPS_NOT_MATCHED_INSTANCE", 
vars.getLanguage());
-        title = Utility.messageBD(myPool, "OPS_NOT_MATCHED_INSTANCE_TITLE", 
vars.getLanguage());
+        msg = Utility.messageBD(cp, "OPS_NOT_MATCHED_INSTANCE", 
vars.getLanguage());
+        title = Utility.messageBD(cp, "OPS_NOT_MATCHED_INSTANCE_TITLE", 
vars.getLanguage());
         log4j.warn("No matched instance - Session: " + sessionId);
         updateDBSession(sessionId, msgType.equals("Warning"), "IOBPS");
         goToRetry(res, vars, msg, title, msgType, action);
         return;
       case HB_NOT_ACTIVE:
-        msg = Utility.messageBD(myPool, "OPS_NOT_HB_ACTIVE", 
vars.getLanguage());
-        title = Utility.messageBD(myPool, "OPS_NOT_HB_ACTIVE_TITLE", 
vars.getLanguage());
+        msg = Utility.messageBD(cp, "OPS_NOT_HB_ACTIVE", vars.getLanguage());
+        title = Utility.messageBD(cp, "OPS_NOT_HB_ACTIVE_TITLE", 
vars.getLanguage());
         log4j.warn("HB not active - Session: " + sessionId);
         updateDBSession(sessionId, msgType.equals("Warning"), "IOBPS");
         goToRetry(res, vars, msg, title, msgType, action);
         return;
       case EXPIRED_GOLDEN:
-        msg = Utility.messageBD(myPool, "OPS_EXPIRED_GOLDEN", 
vars.getLanguage());
-        title = Utility.messageBD(myPool, "OPS_EXPIRED_GOLDEN_TITLE", 
vars.getLanguage());
+        msg = Utility.messageBD(cp, "OPS_EXPIRED_GOLDEN", vars.getLanguage());
+        title = Utility.messageBD(cp, "OPS_EXPIRED_GOLDEN_TITLE", 
vars.getLanguage());
         updateDBSession(sessionId, false, "IOBPS");
         goToRetry(res, vars, msg, title, "Error", "../security/Login_FS.html");
         return;
@@ -277,8 +280,8 @@
           // Preventing concurrency of already logged in named user in case 
System Status is OK.
           // While rebuilding or if problems in the rebuild, allow same user 
with Sys Admin role not
           // to kill the session that started the rebuild.
-          msg = Utility.messageBD(myPool, "CONCURRENT_NAMED_USER", 
vars.getLanguage());
-          title = Utility.messageBD(myPool, "CONCURRENT_NAMED_USER_TITLE", 
vars.getLanguage());
+          msg = Utility.messageBD(cp, "CONCURRENT_NAMED_USER", 
vars.getLanguage());
+          title = Utility.messageBD(cp, "CONCURRENT_NAMED_USER_TITLE", 
vars.getLanguage());
           log4j.warn("Named Concurrent Users Reached - Session: " + sessionId);
           vars.clearSession(true);
           goToRetry(res, vars, msg, title, "Confirmation", 
"../secureApp/LoginHandler.html");
@@ -288,14 +291,14 @@
           break;
         }
       case ON_DEMAND_OFF_PLATFORM:
-        msg = Utility.messageBD(myPool, "ON_DEMAND_OFF_PLATFORM", 
vars.getLanguage());
-        title = Utility.messageBD(myPool, "ON_DEMAND_OFF_PLATFORM_TITLE", 
vars.getLanguage());
+        msg = Utility.messageBD(cp, "ON_DEMAND_OFF_PLATFORM", 
vars.getLanguage());
+        title = Utility.messageBD(cp, "ON_DEMAND_OFF_PLATFORM_TITLE", 
vars.getLanguage());
         log4j.warn("On demand off platform");
         goToRetry(res, vars, msg, title, msgType, action);
         return;
       case POS_TERMINALS_EXCEEDED:
-        msg = Utility.messageBD(myPool, "OPS_POS_TERMINALS_EXCEEDED", 
vars.getLanguage());
-        title = Utility.messageBD(myPool, "OPS_POS_TERMINALS_EXCEEDED_TITLE", 
vars.getLanguage());
+        msg = Utility.messageBD(cp, "OPS_POS_TERMINALS_EXCEEDED", 
vars.getLanguage());
+        title = Utility.messageBD(cp, "OPS_POS_TERMINALS_EXCEEDED_TITLE", 
vars.getLanguage());
         log4j.warn("Exceeded maximum number of pos terminals");
         goToRetry(res, vars, msg, title, msgType, action);
         return;

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to