use of org.compiere.util.Login in project adempiere by adempiere.
the class PostgresConvertTest method main.
/**
* Test
* @param args ignored
*/
public static void main(String[] args) {
Adempiere.startup(true);
CLogMgt.setLoggerLevel(Level.INFO, null);
CLogMgt.setLevel(Level.INFO);
//
Ini.setProperty(Ini.P_UID, "SuperUser");
Ini.setProperty(Ini.P_PWD, "System");
Ini.setProperty(Ini.P_ROLE, "GardenWorld Admin");
Ini.setProperty(Ini.P_CLIENT, "GardenWorld");
Ini.setProperty(Ini.P_ORG, "HQ");
Ini.setProperty(Ini.P_WAREHOUSE, "HQ Warehouse");
Ini.setProperty(Ini.P_LANGUAGE, "English");
Login login = new Login(Env.getCtx());
if (!login.batchLogin(null))
System.exit(1);
log.info("start test");
StringBuffer sql = new StringBuffer("SELECT 'un DATE en una constante'," + " 'ropa de cache para damas' FROM DUAL");
try {
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
ResultSet rs = pstmt.executeQuery();
} catch (SQLException e) {
log.log(Level.SEVERE, sql.toString(), e);
}
// From org.compiere.acct.Doc_Order
// update Product PO info
// should only be once, but here for every AcctSchema
// ignores multiple lines with same product - just uses first
/*sql = new StringBuffer (
"UPDATE M_Product_PO po "
+ "SET PriceLastPO = (SELECT currencyConvert(ol.PriceActual,ol.C_Currency_ID,po.C_Currency_ID,o.DateOrdered,o.C_ConversionType_ID,o.AD_Client_ID,o.AD_Org_ID) "
+ "FROM C_Order o, C_OrderLine ol "
+ "WHERE o.C_Order_ID=ol.C_Order_ID"
+ " AND po.M_Product_ID=ol.M_Product_ID AND po.C_BPartner_ID=o.C_BPartner_ID"
+ " AND ROWNUM=1 AND o.C_Order_ID=").append(getRecord_ID()).append(") ")
.append("WHERE EXISTS (SELECT * "
+ "FROM C_Order o, C_OrderLine ol "
+ "WHERE o.C_Order_ID=ol.C_Order_ID"
+ " AND po.M_Product_ID=ol.M_Product_ID AND po.C_BPartner_ID=o.C_BPartner_ID"
+ " AND o.C_Order_ID=").append(getRecord_ID()).append(")");
int no = DB.executeUpdate(sql.toString(), getTrxName());
log.fine("M_Product_PO - Updated=" + no);
*/
//sql = new StringBuffer ("DELETE T_MRP WHERE AD_Client_ID<>0");
//no = DB.executeUpdate(sql.toString(), getTrxName());
/*
// From org.compiere.acct.Doc_Invoice
// update Product PO info
// should only be once, but here for every AcctSchema
// ignores multiple lines with same product - just uses first
StringBuffer sql = new StringBuffer (
"UPDATE M_Product_PO po "
+ "SET PriceLastInv = "
// select
+ "(SELECT currencyConvert(il.PriceActual,i.C_Currency_ID,po.C_Currency_ID,i.DateInvoiced,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID) "
+ "FROM C_Invoice i, C_InvoiceLine il "
+ "WHERE i.C_Invoice_ID=il.C_Invoice_ID"
+ " AND po.M_Product_ID=il.M_Product_ID AND po.C_BPartner_ID=i.C_BPartner_ID"
+ " AND ROWNUM=1 AND i.C_Invoice_ID=").append(getRecord_ID()).append(") ")
// update
.append("WHERE EXISTS (SELECT * "
+ "FROM C_Invoice i, C_InvoiceLine il "
+ "WHERE i.C_Invoice_ID=il.C_Invoice_ID"
+ " AND po.M_Product_ID=il.M_Product_ID AND po.C_BPartner_ID=i.C_BPartner_ID"
+ " AND i.C_Invoice_ID=").append(getRecord_ID()).append(")");
int no = DB.executeUpdate(sql.toString(), getTrxName());
log.fine("M_Product_PO - Updated=" + no);
*/
sql = new StringBuffer("UPDATE I_Order SET M_Warehouse_ID=(SELECT M_Warehouse_ID FROM M_Warehouse w WHERE ROWNUM=1 AND I_Order.AD_Client_ID=w.AD_Client_ID AND I_Order.AD_Org_ID=w.AD_Org_ID) WHERE M_Warehouse_ID IS NULL AND I_IsImported<>'Y' AND AD_Client_ID=11");
int no = DB.executeUpdate(sql.toString(), getTrxName());
/*sql = new StringBuffer ("UPDATE I_Order o SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Org, ' WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0 OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N'))) AND I_IsImported<>'Y'");
no = DB.executeUpdate(sql.toString(), getTrxName());
sql = new StringBuffer ("UPDATE I_Order o SET C_DocType_ID=(SELECT C_DocType_ID FROM C_DocType d WHERE d.Name=o.DocTypeName AND d.DocBaseType='POO' AND o.AD_Client_ID=d.AD_Client_ID) WHERE C_DocType_ID IS NULL AND IsSOTrx='N' AND DocTypeName IS NOT NULL AND I_IsImported<>'Y'");
no = DB.executeUpdate(sql.toString(), getTrxName());*/
sql = new StringBuffer("UPDATE I_Order o SET (C_BPartner_ID,AD_User_ID)=(SELECT C_BPartner_ID,AD_User_ID FROM AD_User u WHERE o.ContactName=u.Name AND o.AD_Client_ID=u.AD_Client_ID AND u.C_BPartner_ID IS NOT NULL) WHERE C_BPartner_ID IS NULL AND ContactName IS NOT NULL AND EXISTS (SELECT Name FROM AD_User u WHERE o.ContactName=u.Name AND o.AD_Client_ID=u.AD_Client_ID AND u.C_BPartner_ID IS NOT NULL GROUP BY Name HAVING COUNT(*)=1) AND I_IsImported<>'Y' AND AD_Client_ID=11");
no = DB.executeUpdate(sql.toString(), getTrxName());
//sql = new StringBuffer ("SELECT M_PriceList_ID, pl.Name, pl.Description, pl.IsTaxIncluded, c.ISO_Code, c.CurSymbol, cc.AD_Language FROM M_PriceList pl INNER JOIN C_Currency c ON (pl.C_Currency_ID=c.C_Currency_ID) LEFT OUTER JOIN C_Country cc ON (c.C_Currency_ID=cc.C_Currency_ID AND ROWNUM=1) WHERE pl.IsActive='Y' AND pl.AD_Client_ID=? AND pl.M_PriceList_ID=100000");
//no = DB.executeUpdate(sql.toString(), getTrxName());
log.info("final test");
}
use of org.compiere.util.Login in project adempiere by adempiere.
the class ModelADServiceImpl method modelLogin.
private String modelLogin(ADLoginRequest r, String webService, String method, String serviceType) throws XFireFault {
// TODO: Share login between different sessions
if (m_cs.isLoggedIn() && m_cs.getM_AD_Client_ID() == r.getClientID() && m_cs.getM_AD_Org_ID() == r.getOrgID() && m_cs.getM_AD_Role_ID() == r.getRoleID() && m_cs.getM_AD_Warehouse_ID() == r.getWarehouseID() && r.getUser().equals(m_cs.getUser()))
// already logged with same data
return authenticate(webService, method, serviceType);
Login login = new Login(m_cs.getM_ctx());
KeyNamePair[] roles = login.getRoles(r.getUser(), r.getPass());
if (roles != null) {
boolean okrole = false;
for (KeyNamePair role : roles) {
if (role.getKey() == r.getRoleID()) {
okrole = true;
break;
}
}
if (!okrole)
return "Error logging in - role not allowed for this user";
KeyNamePair[] clients = login.getClients(new KeyNamePair(r.getRoleID(), ""));
boolean okclient = false;
for (KeyNamePair client : clients) {
if (client.getKey() == r.getClientID()) {
okclient = true;
break;
}
}
if (!okclient)
return "Error logging in - client not allowed for this role";
KeyNamePair[] orgs = login.getOrgs(new KeyNamePair(r.getClientID(), ""));
if (orgs == null)
return "Error logging in - no organizations for this role";
KeyNamePair orglogin = null;
boolean okorg = false;
for (KeyNamePair org : orgs) {
if (org.getKey() == r.getOrgID()) {
okorg = true;
orglogin = org;
break;
}
}
if (!okorg)
return "Error logging in - org not allowed for this role";
KeyNamePair[] warehouses = login.getWarehouses(new KeyNamePair(r.getOrgID(), ""));
boolean okwh = false;
if (warehouses != null) {
for (KeyNamePair warehouse : warehouses) {
if (warehouse.getKey() == r.getWarehouseID()) {
okwh = true;
break;
}
}
if (!okwh)
return "Error logging in - warehouse not allowed for this org";
}
String error = login.validateLogin(orglogin);
if (error != null && error.length() > 0)
return error;
int AD_User_ID = Env.getAD_User_ID(m_cs.getM_ctx());
if (!m_cs.login(AD_User_ID, r.getRoleID(), r.getClientID(), r.getOrgID(), r.getWarehouseID(), r.getLang()))
return "Error logging in";
} else {
return "Error logging in - no roles or user/pwd invalid for user " + r.getUser();
}
return authenticate(webService, method, serviceType);
}
use of org.compiere.util.Login in project adempiere by adempiere.
the class LoginDynUpdate method reply_Login2_Role.
// getReply
/**
* Login 2nd page Response - Field Role.
* <p>
* fill Client, Org, Warehouse
* @param body document body
* @param wsc web session context
* @param formName
* @param fieldValue
*/
private static void reply_Login2_Role(body body, MobileSessionCtx wsc, String roleId) {
// Formname
String form = null;
Login login = new Login(wsc.ctx);
// Get Data
KeyNamePair[] clients = login.getClients(new KeyNamePair(Integer.parseInt(roleId), roleId));
// Set Client ----
StringBuffer script = new StringBuffer("{\"options\":[");
for (int i = 0; i < clients.length; i++) {
if (i > 0)
script.append(",");
KeyNamePair p = clients[i];
script.append("{\"text\":\"");
// text
script.append(p.getName());
script.append("\",\"value\":\"");
// value
script.append(p.getKey());
script.append("\"}); ");
}
script.append("]}");
/*
// Set Organization ----
if (clients.length > 0)
{
// var A=top.WWindow.document.formName.selectName.options;
script.append("var B=").append(form).append(WLogin.P_ORG).append(".options; ");
// A.length=0; // resets options
script.append("B.length=0; ");
// A[0]=new Option('text','value'); // add new oprtion
KeyNamePair[] orgs = login.getOrgs (clients[0]);
for (int i = 0; i < orgs.length; i++)
{
KeyNamePair p = orgs[i];
script.append("B[").append(i).append("]=new Option('");
script.append(p.getName()); // text
script.append("','");
script.append(p.getKey()); // value
script.append("'); ");
}
script.append("\n");
// Set Warehouse ----
if (orgs.length > 0)
{
// var A=top.WWindow.document.formName.selectName.options;
script.append("var C=").append(form).append(WLogin.P_WAREHOUSE).append(".options; ");
// A.length=0; // resets options
script.append("C.length=0; ");
// A[0]=new Option('text','value'); // add new oprtion
KeyNamePair[] whs = login.getWarehouses (orgs[0]);
if (whs != null)
{
for (int i = 0; i < whs.length; i++)
{
KeyNamePair p = whs[i];
script.append("C[").append(i).append("]=new Option('");
script.append(p.getName()); // text
script.append("','");
script.append(p.getKey()); // value
script.append("'); ");
}
}
} // we have a org
} // we have a client
// add script
body.addElement(new p().addElement(WLogin.P_CLIENT + "="));
body.addElement(new script(script.toString()));
// log.trace(log.l6_Database, "reply_Login2_Role - Script=" + script.toString());
*/
}
use of org.compiere.util.Login in project adempiere by adempiere.
the class LoginDynUpdate method doPost.
// doPost
/**
* Process the HTTP Post request
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Get Session Info
MobileSessionCtx wsc = MobileSessionCtx.get(request);
WWindowStatus ws = WWindowStatus.get(request);
if (// ws can be null for Login
wsc == null || ws == null)
;
String role = request.getParameter("AD_Role_ID");
int roleId;
try {
roleId = Integer.parseInt(role);
} catch (Exception e) {
roleId = -1;
}
String client = request.getParameter("AD_Client_ID");
int clientId;
try {
clientId = Integer.parseInt(client);
} catch (Exception e) {
clientId = -1;
}
Login login = new Login(wsc.ctx);
StringBuffer script = new StringBuffer("{");
boolean hasClients = false;
if (roleId >= 0) {
// Get Data
KeyNamePair[] clients = login.getClients(new KeyNamePair(roleId, role));
// Set Client ----
script.append("\"clients\":[");
for (int i = 0; i < clients.length; i++) {
if (i > 0)
script.append(",");
KeyNamePair p = clients[i];
script.append("{\"text\":\"");
// text
script.append(p.getName());
script.append("\",\"value\":\"");
// value
script.append(p.getKey());
script.append("\"}");
}
script.append("]");
if (clientId < 0 && clients.length > 0) {
clientId = clients[0].getKey();
}
}
if (clientId >= 0) {
script.append(",\"orgs\":[");
KeyNamePair[] orgs = login.getOrgs(new KeyNamePair(clientId, client));
for (int i = 0; i < orgs.length; i++) {
if (i > 0)
script.append(",");
KeyNamePair p = orgs[i];
script.append("{\"text\":\"");
// text
script.append(p.getName());
script.append("\",\"value\":\"");
// value
script.append(p.getKey());
script.append("\"}");
}
script.append("]");
}
script.append("}");
// print document
// with character encoding support
PrintWriter out = response.getWriter();
out.print(script);
out.flush();
if (out.checkError())
log.log(Level.SEVERE, "error writing");
// binary output (is faster but does not do character set conversion)
// OutputStream out = response.getOutputStream();
// byte[] data = doc.toString().getBytes();
// response.setContentLength(data.length);
// out.write(doc.toString().getBytes());
//
out.close();
}
use of org.compiere.util.Login in project adempiere by adempiere.
the class AdempiereMonitorFilter method checkAuthorization.
// doFilter
/**
* Check Authorization
* @param authorization authorization
* @return true if authenticated
*/
private boolean checkAuthorization(String authorization) {
if (authorization == null)
return false;
try {
String userInfo = authorization.substring(6).trim();
Base64 decoder = new Base64();
String namePassword = new String(decoder.decode(userInfo.getBytes()));
// log.fine("checkAuthorization - Name:Password=" + namePassword);
int index = namePassword.indexOf(':');
String name = namePassword.substring(0, index);
String password = namePassword.substring(index + 1);
Login login = new Login(Env.getCtx());
KeyNamePair[] rolesKNPairs = login.getRoles(name, password);
if (rolesKNPairs == null || rolesKNPairs.length == 0)
throw new AdempiereException("@UserPwdError@");
for (KeyNamePair keyNamePair : rolesKNPairs) {
if ("System Administrator".equals(keyNamePair.getName())) {
log.info("Name=" + name);
return true;
}
}
log.warning("Not a Sys Admin = " + name);
return false;
} catch (Exception e) {
log.log(Level.SEVERE, "check", e);
}
return false;
}
Aggregations