log.info("Fetched session object: "+session);
    private Template loginPage(HttpServletRequest request, HttpServletResponse response, Context context) throws ParseErrorException, ResourceNotFoundException, Exception {        log.info("loginPage(HttpServletRequest, HttpServletResponse, Context");        /* Get session ID */        String id = request.getParameter("id");        log.info("SessionID: "+id);        if (request.getParameter("showAttrs") != null)            showAllAttributes = request.getParameter("showAttrs").equals("yes");        else             showAllAttributes = false;        Session existingSession = null;         /* Try to use SSO. */        HttpSession httpSession =             ((HttpServletRequest)request).getSession(true);                    /* Find existing session */        String existingSessionID = (String) httpSession.getAttribute("moriaID");        try {            existingSession = sessionStore.getSession(existingSessionID);        }        catch (NoSuchSessionException e) {            /* If no old session exist, then SSO is impossible.             * Continue with normal authentication. */            log.info("Did not find SSO session: "+existingSessionID);            existingSession = null;        }        try {            Session session = sessionStore.getSession(id);            sessionStore.renameSession(session);             httpSession.setAttribute("moriaID", session.getID());                        if (existingSession != null) {                log.info("Existing SSO session found.");                /* Session has to be authenticated and locked to be                   used in SSO. If not locked another web service is                   using the session. */                if (existingSession.isAuthenticated() && existingSession.isLocked()) {                    HashMap cachedAttributes = existingSession.getCachedAttributes();                    if (cachedAttributes != null && cachedAttributes.size() > 0) {                        session.setCachedAttributes(cachedAttributes);                        sessionStore.deleteSession(existingSession);                        if (session.allowSso()) {                            log.fine("SSO Redirect.");                            session.unlock(existingSession.getUser());                            redirectToWebService(response, session);                            return null;                        }                    }                }            }            session.initiateAuthentication();            return genLoginTemplate(request, response, context, session, null);        }                catch (NoSuchSessionException e) {            return genLoginTemplate(request, response, context, null, NOSESSION);        }        catch (SessionException e) {            return genLoginTemplate(request, response, context, null, GENERIC);        }    }