session = sessionStore.getSession(id);
    private Template attemptLogin(HttpServletRequest request, HttpServletResponse response, Context context) throws ParseErrorException, ResourceNotFoundException, Exception {        log.finer("attemptLogin(HttpServletRequest, HttpServletResponse, Context)");        Session session = null;        String id       = request.getParameter("id");        String username = request.getParameter("username");        String password = request.getParameter("password");        // Get session        try {            session = sessionStore.getSession(id);            if (session == null) {                return genLoginTemplate(request, response, context, null, NOSESSION);            }        }                catch (SessionException e) {            return genLoginTemplate(request, response, context, null, UNKNOWN);        }        // Authenticate        try {            Credentials c = new Credentials(username, password);            if (!session.authenticateUser(c)) {                log.info("Authentication failed");                if (session == null) {                    // Max login tries has been reached. Session is                    // terminated.                    return genLoginTemplate(request, response, context, null, MAXLOGIN);                }                else                    return genLoginTemplate(request, response, context, session.getID(), AUTHFAILED);            }        }                 catch (BackendException e) {            // A user-friendly message would be preferable...            log.severe("BackendException caught and re-thrown as ServletException");                return genLoginTemplate(request, response, context, null, UNKNOWN);        }         catch (SessionException e) {            // A user-friendly message would be preferable...            log.severe("SessionException caught and re-thrown as ServletException");                return genLoginTemplate(request, response, context, null, UNKNOWN);        }        /* Success; redirect to the original session URL and         * include the updated session ID. */        response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);          response.setHeader("Location", session.getRedirectURL());        log.info("Redirect to Mellon: "+session.getRedirectURL());            return null; // Do not use template for redirect.    }