Committing patch sent by druiz - although not used in iDempiere - as a reference in case somebody wants to implement a process with BatchLogin - adapting the batchlogin to the new iDempiere structure (client->role instead of previous role->client)

This commit is contained in:
Carlos Ruiz 2017-06-14 12:37:07 +02:00
parent e878a33778
commit b1632b4159
1 changed files with 65 additions and 64 deletions

View File

@ -1078,11 +1078,38 @@ public class Login
{ {
// User Login // User Login
String uid = Ini.getProperty(Ini.P_UID); String uid = Ini.getProperty(Ini.P_UID);
String pwd = Ini.getProperty(Ini.P_PWD); String pwd = Ini.getProperty(Ini.P_PWD);
KeyNamePair[] roles = getRoles (uid, pwd);
String client = Ini.getProperty(Ini.P_CLIENT);
KeyNamePair[] clients = getClients(uid, pwd);
if (clients == null || clients.length == 0)
{
log.severe("User/Password invalid: " + uid);
return false;
}
KeyNamePair clientPP = null;
for (KeyNamePair pair : clients)
{
if (pair.getName().equalsIgnoreCase(client))
{
clientPP = pair;
break;
}
}
if (clientPP == null)
{
log.severe("Client invalid: " + client);
if (log.isLoggable(Level.INFO)) {
for (KeyNamePair pair : clients)
log.info("Option: " + pair);
}
return false;
}
KeyNamePair[] roles = getRoles(uid, clientPP);
if (roles == null || roles.length == 0) if (roles == null || roles.length == 0)
{ {
log.severe("User/Password invalid: " + uid); log.severe("No Roles for client: " + client);
return false; return false;
} }
if (log.isLoggable(Level.INFO)) log.info("User: " + uid); if (log.isLoggable(Level.INFO)) log.info("User: " + uid);
@ -1090,9 +1117,8 @@ public class Login
// Role // Role
String role = Ini.getProperty(Ini.P_ROLE); String role = Ini.getProperty(Ini.P_ROLE);
KeyNamePair rolePP = null; KeyNamePair rolePP = null;
for (int i = 0; i < roles.length; i++) for (KeyNamePair pair : roles)
{ {
KeyNamePair pair = roles[i];
if (pair.getName().equalsIgnoreCase(role)) if (pair.getName().equalsIgnoreCase(role))
{ {
rolePP = pair; rolePP = pair;
@ -1110,46 +1136,17 @@ public class Login
} }
if (log.isLoggable(Level.INFO)) log.info("Role: " + role); if (log.isLoggable(Level.INFO)) log.info("Role: " + role);
// Clients
String client = Ini.getProperty(Ini.P_CLIENT);
KeyNamePair[] clients = getClients(rolePP);
if (clients == null || clients.length == 0)
{
log.severe("No Clients for Role: " + role);
return false;
}
KeyNamePair clientPP = null;
for (int i = 0; i < clients.length; i++)
{
KeyNamePair pair = clients[i];
if (pair.getName().equalsIgnoreCase(client))
{
clientPP = pair;
break;
}
}
if (clientPP == null)
{
log.severe("Client invalid: " + client);
if (log.isLoggable(Level.INFO)) {
for (int i = 0; i < clients.length; i++)
log.info("Option: " + clients[i]);
}
return false;
}
// Organization // Organization
String org = Ini.getProperty(Ini.P_ORG); String org = Ini.getProperty(Ini.P_ORG);
KeyNamePair[] orgs = getOrgs(clientPP); KeyNamePair[] orgs = getOrgs(rolePP);
if (orgs == null || orgs.length == 0) if (orgs == null || orgs.length == 0)
{ {
log.severe("No Orgs for Client: " + client); log.severe("No Orgs for Role: " + role);
return false; return false;
} }
KeyNamePair orgPP = null; KeyNamePair orgPP = null;
for (int i = 0; i < orgs.length; i++) for (KeyNamePair pair : orgs)
{ {
KeyNamePair pair = orgs[i];
if (pair.getName().equalsIgnoreCase(org)) if (pair.getName().equalsIgnoreCase(org))
{ {
orgPP = pair; orgPP = pair;
@ -1164,37 +1161,37 @@ public class Login
log.info("Option: " + orgs[i]); log.info("Option: " + orgs[i]);
} }
return false; return false;
} }
String error = validateLogin(orgPP);
if (error != null && error.length() > 0)
return false;
// Warehouse // Warehouse
String wh = Ini.getProperty(Ini.P_WAREHOUSE); String wh = Ini.getProperty(Ini.P_WAREHOUSE);
KeyNamePair[] whs = getWarehouses(orgPP); KeyNamePair whPP = null;
if (whs == null || whs.length == 0)
{ if (orgPP.getKey() != 0) {
log.severe("No Warehouses for Org: " + org); KeyNamePair[] whs = getWarehouses(orgPP);
return false; if (whs == null || whs.length == 0)
}
KeyNamePair whPP = null;
for (int i = 0; i < whs.length; i++)
{
KeyNamePair pair = whs[i];
if (pair.getName().equalsIgnoreCase(wh))
{ {
whPP = pair; log.severe("No Warehouses for Org: " + org);
break; return false;
} }
} for (int i = 0; i < whs.length; i++)
if (whPP == null) {
{ KeyNamePair pair = whs[i];
log.severe("Warehouse invalid: " + wh); if (pair.getName().equalsIgnoreCase(wh))
if (log.isLoggable(Level.INFO)) { {
for (int i = 0; i < whs.length; i++) whPP = pair;
log.info("Option: " + whs[i]); break;
}
} }
return false; if (whPP == null)
{
log.severe("Warehouse invalid: " + wh);
if (log.isLoggable(Level.INFO)) {
for (int i = 0; i < whs.length; i++)
log.info("Option: " + whs[i]);
}
return false;
}
} }
// Language // Language
@ -1211,7 +1208,11 @@ public class Login
String printerName = Ini.getProperty(Ini.P_PRINTER); String printerName = Ini.getProperty(Ini.P_PRINTER);
if (loginDate == null) if (loginDate == null)
loginDate = new java.sql.Timestamp(System.currentTimeMillis()); loginDate = new java.sql.Timestamp(System.currentTimeMillis());
loadPreferences(orgPP, whPP, loginDate, printerName); loadPreferences(orgPP, whPP, loginDate, printerName);
String error = validateLogin(orgPP);
if (error != null && error.length() > 0)
return false;
// //
if (log.isLoggable(Level.INFO)) log.info("complete"); if (log.isLoggable(Level.INFO)) log.info("complete");
return true; return true;