Authenticate.getSiteAuth().initEPerson(context, request, eperson);
AuthenticationManager.initEPerson(context, request, eperson);
    protected void doDSPost(Context context,        HttpServletRequest request,        HttpServletResponse response)        throws ServletException, IOException, SQLException, AuthorizeException    {        // Process the POSTed email and password        String netid = request.getParameter("login_netid");        String password = request.getParameter("login_password");                // Locate the eperson        EPerson eperson = EPerson.findByNetid(context, netid.toLowerCase());        EPerson eperson2 = EPerson.findByEmail(context, netid.toLowerCase());        boolean loggedIn = false;        // make sure ldap values are null with every request        ldapGivenName = null;        ldapSurname = null;        ldapEmail = null;        ldapPhone = null;        // if they entered a netid that matches an eperson        if (eperson != null && eperson.canLogIn())        {            // e-mail address corresponds to active account            if (eperson.getRequireCertificate())            {                // they must use a certificate                JSPManager.showJSP(request,                    response,                    "/error/require-certificate.jsp");                return;            }            else             {                if (ldapAuthenticate(netid, password, context))                {                    // Logged in OK.                    Authenticate.loggedIn(context, request, eperson);                    log.info(LogManager                        .getHeader(context, "login", "type=ldap"));                    // resume previous request                    Authenticate.resumeInterruptedRequest(request, response);                    return;                }                else                 {                   JSPManager.showJSP(request, response, "/login/ldap-incorrect.jsp");                   return;                }            }        }        // if they entered an email address that matches an eperson        else if (eperson2 != null && eperson2.canLogIn())        {            // e-mail address corresponds to active account            if (eperson2.getRequireCertificate())            {                // they must use a certificate                JSPManager.showJSP(request,                    response,                    "/error/require-certificate.jsp");                return;            }            else            {                if (eperson2.checkPassword(password))                {                    // Logged in OK.                    Authenticate.loggedIn(context, request, eperson2);                    log.info(LogManager                        .getHeader(context, "login", "type=password"));                    // resume previous request                    Authenticate.resumeInterruptedRequest(request, response);                    return;                }                else                {                   JSPManager.showJSP(request, response, "/login/ldap-incorrect.jsp");                   return;                }            }        }        // the user does not already exist so try and authenticate them with ldap and create an eperson for them        else {            if (ldapAuthenticate(netid, password, context))            {                if (ConfigurationManager.getBooleanProperty("webui.ldap.autoregister"))                {                    // Register the new user automatically                    log.info(LogManager.getHeader(context,                                    "autoregister", "netid=" + netid));                    if ((ldapEmail!=null)&&(!ldapEmail.equals("")))                     {                        eperson = EPerson.findByEmail(context, ldapEmail);                        if (eperson!=null)                        {                            log.info(LogManager.getHeader(context,                                    "failed_autoregister", "type=ldap_but_already_email"));                            JSPManager.showJSP(request, response,                                    "/register/already-registered.jsp");                            return;                        }                    }                    // TEMPORARILY turn off authorisation                    context.setIgnoreAuthorization(true);                    eperson = EPerson.create(context);                    if ((ldapEmail!=null)&&(!ldapEmail.equals(""))) eperson.setEmail(ldapEmail);                    else eperson.setEmail(netid);                    if ((ldapGivenName!=null)&&(!ldapGivenName.equals(""))) eperson.setFirstName(ldapGivenName);                    if ((ldapSurname!=null)&&(!ldapSurname.equals(""))) eperson.setLastName(ldapSurname);                    if ((ldapPhone!=null)&&(!ldapPhone.equals(""))) eperson.setMetadata("phone", ldapPhone);                    eperson.setNetid(netid);                    eperson.setCanLogIn(true);                    Authenticate.getSiteAuth().initEPerson(context, request, eperson);                    eperson.update();                    context.commit();                    context.setIgnoreAuthorization(false);                     Authenticate.loggedIn(context, request, eperson);                    log.info(LogManager.getHeader(context, "login",                                "type=ldap-login"));                    Authenticate.resumeInterruptedRequest(request, response);                    return;                }                else                {                    // No auto-registration for valid certs                    log.info(LogManager.getHeader(context,                                    "failed_login", "type=ldap_but_no_record"));                    JSPManager.showJSP(request, response,                                    "/login/not-in-records.jsp");                    return;                }            }        }        // If we reach here, supplied email/password was duff.        log.info(LogManager.getHeader(context,            "failed_login",            "netid=" + netid));        JSPManager.showJSP(request, response, "/login/ldap-incorrect.jsp");    }