1 12 package org.openbravo.base.secureApp; 13 14 import org.openbravo.xmlEngine.XmlDocument; 15 import org.openbravo.erpCommon.reference.PreferencesData; 16 import org.openbravo.erpCommon.utility.Utility; 17 import org.openbravo.utils.FormatUtilities; 18 import org.openbravo.base.*; 19 import org.openbravo.erpCommon.security.*; 20 import org.openbravo.erpCommon.ad_combos.*; 21 22 import java.io.*; 23 import java.util.*; 24 import javax.servlet.*; 25 import javax.servlet.http.*; 26 import java.sql.*; 27 28 29 30 public class LoginHandler extends HttpBaseServlet{ 31 String strServletPorDefecto; 32 33 34 public void init (ServletConfig config) { 35 super.init(config); 36 strServletPorDefecto = config.getServletContext().getInitParameter("DefaultServlet"); 37 } 38 39 public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 40 41 log4j.info("start doPost"); 42 VariablesSecureApp vars = new VariablesSecureApp(req); 43 44 req.getSession(true).setAttribute("#Authenticated_user", null); 46 47 if (vars.getStringParameter("user").equals("")) { 48 res.sendRedirect(res.encodeRedirectURL(strDireccion + "/security/Login_F1.html")); 49 } else { 50 51 if (log4j.isDebugEnabled()) log4j.debug("Base path: " + strBaseDesignPath); 52 53 String strUser = vars.getRequiredStringParameter("user"); 54 String strPass = FormatUtilities.sha1Base64(vars.getRequiredStringParameter("password")); 55 String strUserAuth = SeguridadData.valido(this, strUser, strPass); 56 57 if (!strUserAuth.equals("-1")) { 58 req.getSession(true).setAttribute("#Authenticated_user", strUserAuth); 59 goToTarget(res, vars); 60 61 } else { 62 goToRetry(res); 63 } 64 } 65 } 66 67 private void goToTarget(HttpServletResponse response, VariablesSecureApp vars) throws IOException { 68 69 String target = vars.getSessionValue("target"); 70 if (target.equals("")) { 71 response.sendRedirect(strDireccion + "/security/Menu.html"); 72 } else { 73 response.sendRedirect(target); 74 } 75 } 76 77 private void goToRetry(HttpServletResponse res) throws IOException { 78 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/base/secureApp/HtmlErrorLogin").createXmlDocument(); 79 80 res.setContentType("text/html"); 81 PrintWriter out = res.getWriter(); 82 out.println(xmlDocument.print()); 83 out.close(); 84 } 85 86 public String getServletInfo() { 87 return "User-login control Servlet"; 88 } } 90 | Popular Tags |