Search in sources :

Example 11 with Login

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

the class WMenu method checkLogin.

//  doPost
/**
	 *  Check Login information and set context.
	 *  @return    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 existence of User/Client/Org/Role and User's access 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, sql, 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);
    //
    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 12 with Login

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

the class ForecastEngine 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();
    ForecastEngine engine = ForecastEngine.get();
}
Also used : Login(org.compiere.util.Login)

Example 13 with Login

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

the class VBrowser method main.

// Worker
public static void main(String[] args) {
    Splash.getSplash();
    // Adempiere.startup(true); // needs to be here for UI
    // Adempiere.startupEnvironment(false);
    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();
    Properties m_ctx = Env.getCtx();
    MBrowse browse = new MBrowse(m_ctx, 50025, null);
    FormFrame frame = new FormFrame(0);
    boolean modal = true;
    int WindowNo = 0;
    String value = "";
    String keyColumn = "";
    boolean multiSelection = true;
    String whereClause = "";
    VBrowser browser = new VBrowser(frame, modal, WindowNo, value, browse, keyColumn, multiSelection, whereClause, true);
    // browser.setPreferredSize(getPreferredSize ());
    browser.getFrame().setVisible(true);
    browser.getFrame().pack();
}
Also used : FormFrame(org.compiere.apps.form.FormFrame) Login(org.compiere.util.Login) Properties(java.util.Properties) MBrowse(org.adempiere.model.MBrowse)

Example 14 with Login

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

the class POSLogin method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource().equals(bProcess)) {
        Login login = new Login(posPanel.getCtx());
        login.getRoles(username.getText(), pin.getText());
    }
    dispose();
}
Also used : Login(org.compiere.util.Login)

Example 15 with Login

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

the class WLogin method doPost.

//	doGet
/**
	 *	Process the HTTP Post request.
	 *  <pre>
	 *  - Optionally create Session
	 *  - Check database connection
	 *  - LoginInfo from request?
	 *      - Yes: DoLogin success ?
	 *          - Yes: return (second) preferences page
	 *          - No: return (first) user/password page
	 *      - No: User Principal ?
	 *          - Yes: DoLogin success ?
	 *              - Yes: return (second) preferences page
	 *              - No: return (first) user/password page
	 *          - No: return (first) user/password page
	 *  </pre>
	 *  @param request request
	 *  @param response response
	 *  @throws ServletException
	 *  @throws IOException
	 */
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    log.info("");
    //  Create New Session
    HttpSession sess = request.getSession(true);
    sess.setMaxInactiveInterval(WebEnv.TIMEOUT);
    //  Get Cookie Properties
    Properties cProp = WebUtil.getCookieProprties(request);
    //  Create Context
    WebSessionCtx wsc = WebSessionCtx.get(request);
    //  Page
    WebDoc doc = null;
    //  Check DB connection
    if (!DB.isConnected()) {
        String msg = Msg.getMsg(wsc.ctx, "WLoginNoDB");
        if (msg.equals("WLoginNoDB"))
            msg = "No Database Connection";
        doc = WebDoc.createWindow(msg);
    } else //  Login Info from request?
    {
        //  Get Parameters:     UserName/Password
        String usr = WebUtil.getParameter(request, P_USERNAME);
        String pwd = WebUtil.getParameter(request, P_PASSWORD);
        //  Get Principle
        Principal userPrincipal = request.getUserPrincipal();
        log.info("Principal=" + userPrincipal + "; User=" + usr);
        //  Login info not from request and not pre-authorized
        if (userPrincipal == null && (usr == null || pwd == null))
            doc = createFirstPage(cProp, request, "");
        else //  Login info from request or authorized
        {
            KeyNamePair[] roles = null;
            Login login = new Login(wsc.ctx);
            //  Pre-authorized
            if (userPrincipal != null) {
                roles = login.getRoles(userPrincipal);
                usr = userPrincipal.getName();
            } else
                roles = login.getRoles(usr, pwd);
            //
            if (roles == null)
                doc = createFirstPage(cProp, request, Msg.getMsg(wsc.ctx, "UserPwdError"));
            else {
                doc = createSecondPage(request, WebUtil.convertToOption(roles, null), "");
                //	Create adempiere Session - user id in ctx
                MSession.get(wsc.ctx, request.getRemoteAddr(), request.getRemoteHost(), sess.getId());
            }
            //  Can we save Cookie ?
            if (WebUtil.getParameter(request, P_STORE) == null) {
                //  erase all
                cProp.clear();
            } else //  Save Cookie Parameter
            {
                cProp.setProperty(P_USERNAME, usr);
                cProp.setProperty(P_STORE, "Y");
                //  For test only
                cProp.setProperty(P_PASSWORD, pwd);
            }
        }
    }
    WebUtil.createResponse(request, response, this, cProp, doc, false);
}
Also used : HttpSession(javax.servlet.http.HttpSession) WebDoc(org.compiere.util.WebDoc) KeyNamePair(org.compiere.util.KeyNamePair) Login(org.compiere.util.Login) Properties(java.util.Properties) WebSessionCtx(org.compiere.util.WebSessionCtx) Principal(java.security.Principal)

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