Search in sources :

Example 26 with Login

use of org.compiere.util.Login in project adempiere by adempiere.

the class OrderTest method main.

//	run
/**
	 * 	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);
    //
    CLogMgt.setLoggerLevel(Level.WARNING, null);
    CLogMgt.setLevel(Level.WARNING);
    int NO_TESTS = 2;
    int NO_ORDERS = 200;
    int NO_LINES = 20;
    long time = System.currentTimeMillis();
    Thread[] tests = new Thread[NO_TESTS];
    for (int i = 0; i < tests.length; i++) {
        tests[i] = new Thread(new OrderTest(i, NO_ORDERS, NO_LINES));
        tests[i].start();
    }
    //	Wait
    for (int i = 0; i < tests.length; i++) {
        try {
            tests[i].join();
        } catch (InterruptedException e) {
        }
    }
    time = System.currentTimeMillis() - time;
    System.out.println("Time (ms)=" + time);
}
Also used : Login(org.compiere.util.Login)

Example 27 with Login

use of org.compiere.util.Login in project adempiere by adempiere.

the class ADServiceImpl method login.

public ADLoginResponseDocument login(ADLoginRequestDocument req) throws XFireFault {
    authenticate(webServiceName, "login");
    // TODO: Implement security layer
    log.log(Level.SEVERE, "Warning: Security layer not implemented yet - opening web service " + webServiceName + " implies a security risk for server");
    ADLoginResponseDocument res = ADLoginResponseDocument.Factory.newInstance();
    ADLoginResponse lr = res.addNewADLoginResponse();
    ADLoginRequest r = req.getADLoginRequest();
    if (// initial phase - return possible translations
    r.getStage() == 0) {
        LookupValues langs = lr.addNewLangs();
        for (int i = 0; i < Language.getLanguageCount(); i++) {
            Language language = Language.getLanguage(i);
            LookupValue lv = langs.addNewLv();
            lv.setKey(language.getAD_Language());
            lv.setVal(language.getName());
        }
    } else if (// Verify user and pass
    r.getStage() == 1) {
        KeyNamePair[] roles = null;
        KeyNamePair[] clients = null;
        KeyNamePair[] orgs = null;
        KeyNamePair[] warehouses = null;
        Login login = new Login(m_cs.getM_ctx());
        roles = login.getRoles(r.getUser(), r.getPass());
        if (roles == null) {
            lr.setStatus(-1);
            return res;
        } else {
            if (r.getRoleID() == -1 && roles != null && roles.length > 0)
                r.setRoleID(Integer.parseInt(roles[0].getID()));
            if (r.getRoleID() > -1)
                clients = login.getClients(new KeyNamePair(r.getRoleID(), ""));
            if (r.getClientID() == -1 && clients != null && clients.length > 0)
                r.setClientID(Integer.parseInt(clients[0].getID()));
            if (r.getClientID() > -1)
                orgs = login.getOrgs(new KeyNamePair(r.getClientID(), ""));
            if (r.getOrgID() == -1 && orgs != null && orgs.length > 0)
                r.setOrgID(Integer.parseInt(orgs[0].getID()));
            if (r.getOrgID() > -1)
                warehouses = login.getWarehouses(new KeyNamePair(r.getOrgID(), ""));
            ADLookup.fillLookupValues(lr.addNewRoles(), roles);
            ADLookup.fillLookupValues(lr.addNewClients(), clients);
            ADLookup.fillLookupValues(lr.addNewOrgs(), orgs);
            ADLookup.fillLookupValues(lr.addNewWarehouses(), warehouses);
        }
    } else if (// Verify user and pass
    r.getStage() == 2) {
        Login login = new Login(m_cs.getM_ctx());
        KeyNamePair[] roles = login.getRoles(r.getUser(), r.getPass());
        if (roles != null) {
            KeyNamePair org = new KeyNamePair(r.getRoleID(), Integer.toString(r.getRoleID()));
            String error = login.validateLogin(org);
            if (error != null && error.length() > 0) {
                lr.setStatus(-1);
                return res;
            }
            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())) {
                lr.setStatus(-1);
                return res;
            }
        } else {
            lr.setStatus(-1);
            return res;
        }
    }
    return res;
}
Also used : ADLoginRequest(pl.x3E.adInterface.ADLoginRequest) ADLoginResponseDocument(pl.x3E.adInterface.ADLoginResponseDocument) Language(org.compiere.util.Language) LookupValues(pl.x3E.adInterface.LookupValues) Login(org.compiere.util.Login) KeyNamePair(org.compiere.util.KeyNamePair) ADLoginResponse(pl.x3E.adInterface.ADLoginResponse) LookupValue(pl.x3E.adInterface.LookupValue)

Example 28 with Login

use of org.compiere.util.Login in project adempiere by adempiere.

the class CompiereService method checkLogin.

/*
	public static Properties testLogin (boolean isClient)
	{
		//logger.entering("Env", "initTest");
		Compiere.startupEnvironment(true);
		//  Test Context
		Properties ctx = Env.getCtx();
		org.compiere.util.Login login = new org.compiere.util.Login(ctx);
		KeyNamePair[] roles = login.getRoles("SuperUser", "System1969");
		//  load role
		if (roles != null && roles.length > 0)
		{
			int x = -1;
			for (int i=0; i<roles.length; i++)
			{
				if (roles[i].getName().equalsIgnoreCase("Opony Admin"))
					x= i;
				log.info( roles[i].getName()); 
			}
			KeyNamePair[] clients = login.getClients (roles[x]);
			//  load client
			if (clients != null && clients.length > 0)
			{
				KeyNamePair[] orgs = login.getOrgs(clients[0]);
				//  load org
				if (orgs != null && orgs.length > 0)
				{
					KeyNamePair[] whs = login.getWarehouses(orgs[0]);
					//
					login.loadPreferences(orgs[0], null, null, null);
				}
			}
		}
		//
		Env.setContext(ctx, "#Date", "2006-01-26");
	//	logger.exiting("Env", "initTest");
		return ctx;
	}   //  testInit
	 */
/**
	 *  Check Login information and set context.
	 *  @returns    true if login info are OK
	 *  @param ctx context
	 *  @param AD_User_ID user
	 *  @param AD_Role_ID role
	 *  @param AD_Client_ID client
	 *  @param AD_Org_ID org
	 *  @param M_Warehouse_ID warehouse
	 */
private String checkLogin(Properties ctx, int AD_User_ID, int AD_Role_ID, int AD_Client_ID, int AD_Org_ID, int M_Warehouse_ID) {
    //  Get Login Info
    String loginInfo = null;
    //  Verify existance of User/Client/Org/Role and User's acces to Client & Org
    String sql = "SELECT u.Name || '@' || c.Name || '.' || o.Name || ' [' || INITCAP(USER) || ']' AS Text " + "FROM AD_User u, AD_Client c, AD_Org o, AD_User_Roles ur " + //  #1
    "WHERE u.AD_User_ID=?" + //  #2
    " AND c.AD_Client_ID=?" + //  #3
    " AND o.AD_Org_ID=?" + //  #4
    " AND ur.AD_Role_ID=?" + " AND ur.AD_User_ID=u.AD_User_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)";
    try {
        PreparedStatement pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, AD_User_ID);
        pstmt.setInt(2, AD_Client_ID);
        pstmt.setInt(3, AD_Org_ID);
        pstmt.setInt(4, AD_Role_ID);
        ResultSet rs = pstmt.executeQuery();
        if (rs.next())
            loginInfo = rs.getString(1);
        rs.close();
        pstmt.close();
    } catch (SQLException e) {
    //	log.log(Level.SEVERE, "checkLogin", e);
    }
    //  not verified
    if (loginInfo == null)
        return null;
    //  Set Preferences
    KeyNamePair org = new KeyNamePair(AD_Org_ID, String.valueOf(AD_Org_ID));
    KeyNamePair wh = null;
    if (M_Warehouse_ID > 0)
        wh = new KeyNamePair(M_Warehouse_ID, String.valueOf(M_Warehouse_ID));
    //
    Timestamp date = null;
    String printer = null;
    Login login = new Login(ctx);
    login.loadPreferences(org, wh, date, printer);
    //	Don't Show Acct/Trl Tabs on HTML UI
    Env.setContext(ctx, "#ShowAcct", "N");
    Env.setContext(ctx, "#ShowTrl", "N");
    //
    return loginInfo;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) KeyNamePair(org.compiere.util.KeyNamePair) Login(org.compiere.util.Login) Timestamp(java.sql.Timestamp)

Example 29 with Login

use of org.compiere.util.Login in project adempiere by adempiere.

the class WMRuleEngine method main.

public static void main(String[] args) {
    Adempiere.startup(true);
    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");
    // Ini.setProperty(Ini.P_PRINTER,"MyPrinter");
    Login login = new Login(Env.getCtx());
    login.batchLogin();
    MWMInOutBoundLine line = new MWMInOutBoundLine(Env.getCtx(), 1000006, null);
    WMRuleEngine engine = WMRuleEngine.get();
    MWMInOutBound order = line.getParent();
    engine.getLocator(line, 0, 0);
}
Also used : MWMInOutBoundLine(org.eevolution.model.MWMInOutBoundLine) MWMInOutBound(org.eevolution.model.MWMInOutBound) Login(org.compiere.util.Login)

Aggregations

Login (org.compiere.util.Login)29 KeyNamePair (org.compiere.util.KeyNamePair)22 org.apache.ecs.xhtml.p (org.apache.ecs.xhtml.p)8 org.apache.ecs.xhtml.script (org.apache.ecs.xhtml.script)8 Properties (java.util.Properties)6 SQLException (java.sql.SQLException)5 IOException (java.io.IOException)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 Timestamp (java.sql.Timestamp)4 ServletException (javax.servlet.ServletException)3 Principal (java.security.Principal)2 ArrayList (java.util.ArrayList)2 HttpSession (javax.servlet.http.HttpSession)2 Language (org.compiere.util.Language)2 PrintWriter (java.io.PrintWriter)1 AccessException (java.rmi.AccessException)1 Callback (javax.security.auth.callback.Callback)1 NameCallback (javax.security.auth.callback.NameCallback)1 PasswordCallback (javax.security.auth.callback.PasswordCallback)1