IDEMPIERE-2944 Preserve iDempiere session between sucessive webservice calls / fix Context Lost issue
This commit is contained in:
parent
31e1dead2c
commit
3f1026519f
|
@ -1324,6 +1324,7 @@ public class Login
|
|||
user.setIsLocked(false);
|
||||
user.setDateAccountLocked(null);
|
||||
user.setFailedLoginCount(0);
|
||||
Env.setContext(Env.getCtx(), "#AD_Client_ID", user.getAD_Client_ID());
|
||||
if (!user.save())
|
||||
log.severe("Failed to unlock user account");
|
||||
}
|
||||
|
@ -1337,6 +1338,7 @@ public class Login
|
|||
{
|
||||
user.setIsLocked(true);
|
||||
user.setDateAccountLocked(new Timestamp(now));
|
||||
Env.setContext(Env.getCtx(), "#AD_Client_ID", user.getAD_Client_ID());
|
||||
if (!user.save())
|
||||
log.severe("Failed to lock user account");
|
||||
}
|
||||
|
@ -1441,6 +1443,7 @@ public class Login
|
|||
{
|
||||
user.setFailedLoginCount(0);
|
||||
user.setDateLastLogin(new Timestamp(now));
|
||||
Env.setContext(Env.getCtx(), "#AD_Client_ID", user.getAD_Client_ID());
|
||||
if (!user.save())
|
||||
log.severe("Failed to update user record with date last login (" + user.getName() + " / clientID = " + user.getAD_Client_ID() + ")");
|
||||
}
|
||||
|
@ -1490,6 +1493,7 @@ public class Login
|
|||
user.setFailedLoginCount(count);
|
||||
user.setIsLocked(reachMaxAttempt);
|
||||
user.setDateAccountLocked(user.isLocked() ? new Timestamp(now) : null);
|
||||
Env.setContext(Env.getCtx(), "#AD_Client_ID", user.getAD_Client_ID());
|
||||
if (!user.save())
|
||||
log.severe("Failed to update user record with increase failed login count");
|
||||
}
|
||||
|
|
|
@ -159,6 +159,7 @@ public class CompiereService {
|
|||
Properties savedCache = new Properties();
|
||||
savedCache.putAll(Env.getCtx());
|
||||
ctxMap.put(key.toString(), savedCache);
|
||||
if (log.isLoggable(Level.INFO)) log.info("Saving " + this + " in cache");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -201,15 +202,16 @@ public class CompiereService {
|
|||
String loginInfo = null;
|
||||
// Verify existence of User/Client/Org/Role and User's acces to Client & Org
|
||||
String sql = "SELECT u.Name || '@' || c.Name || '.' || o.Name AS Text "
|
||||
+ "FROM AD_User u, AD_Client c, AD_Org o, AD_User_Roles ur "
|
||||
+ "FROM AD_User u, AD_Client c, AD_Org o, AD_User_Roles ur, AD_Role r "
|
||||
+ "WHERE u.AD_User_ID=?" // #1
|
||||
+ " AND c.AD_Client_ID=?" // #2
|
||||
+ " AND o.AD_Org_ID=?" // #3
|
||||
+ " AND ur.AD_Role_ID=?" // #4
|
||||
+ " AND ur.AD_User_ID=u.AD_User_ID"
|
||||
+ " AND ur.AD_Role_ID=r.AD_Role_ID"
|
||||
+ " AND (o.AD_Client_ID = 0 OR o.AD_Client_ID=c.AD_Client_ID)"
|
||||
+ " AND c.AD_Client_ID IN (SELECT AD_Client_ID FROM AD_Role_OrgAccess ca WHERE ca.AD_Role_ID=ur.AD_Role_ID)"
|
||||
+ " AND o.AD_Org_ID IN (SELECT AD_Org_ID FROM AD_Role_OrgAccess ca WHERE ca.AD_Role_ID=ur.AD_Role_ID)";
|
||||
+ " AND (r.IsAccessAllOrgs='Y' OR (c.AD_Client_ID IN (SELECT AD_Client_ID FROM AD_Role_OrgAccess ca WHERE ca.AD_Role_ID=ur.AD_Role_ID)"
|
||||
+ " AND o.AD_Org_ID IN (SELECT AD_Org_ID FROM AD_Role_OrgAccess ca WHERE ca.AD_Role_ID=ur.AD_Role_ID)))";
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
|
@ -406,10 +408,13 @@ public class CompiereService {
|
|||
l_cs = csMap.get(key);
|
||||
if (l_cs != null) {
|
||||
if (l_cs.isExpired()) {
|
||||
csMap.remove(key);
|
||||
ctxMap.remove(key);
|
||||
l_cs = null;
|
||||
} else {
|
||||
Properties cachedCtx = ctxMap.get(key);
|
||||
Env.getCtx().putAll(cachedCtx);
|
||||
if (log.isLoggable(Level.INFO)) log.info("Reusing " + l_cs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -445,6 +450,7 @@ public class CompiereService {
|
|||
);
|
||||
if (m_connected && expired)
|
||||
{
|
||||
if (log.isLoggable(Level.INFO)) log.info("Closing expired/invalid " + this);
|
||||
Env.logout();
|
||||
ServerContext.dispose();
|
||||
m_loggedin = false;
|
||||
|
|
|
@ -35,6 +35,7 @@ public class CompiereUtil {
|
|||
|
||||
try
|
||||
{
|
||||
if (log.isLoggable(Level.INFO)) log.info("Starting webservices iDempiere session");
|
||||
s_initOK = Adempiere.startup(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
Loading…
Reference in New Issue