TreeMap allowedOrganizations = RequestUtil.parseConfig(getConfig(), RequestUtil.PROP_ORG, bundle.getLocale().getLanguage()); final String servicePrincipal = (String) serviceProperties.get(RequestUtil.CONFIG_SERVICE_PRINCIPAL);
String servicePrincipal = null; if (serviceProperties != null) servicePrincipal = (String) serviceProperties.get(RequestUtil.CONFIG_SERVICE_PRINCIPAL);   TreeMap allowedOrganizations = null; if (servicePrincipal != null) {   allowedOrganizations = RequestUtil.parseConfig(getConfig(), RequestUtil.PROP_ORG, bundle.getLocale().getLanguage());
    private void showLoginPage(final HttpServletRequest request,                               final HttpServletResponse response,                               String errorType)    throws IOException, ServletException {        // Get configuration.        final Properties config = getConfig();        HashMap serviceProperties = null;        // Get the login ticket name and set the base authentication page URL.        final String loginTicketId = request.getParameter(config.getProperty(RequestUtil.PROP_LOGIN_TICKET_PARAM));        request.setAttribute(RequestUtil.ATTR_BASE_URL, config.getProperty(RequestUtil.PROP_LOGIN_URL_PREFIX) + "?" + config.getProperty(RequestUtil.PROP_LOGIN_TICKET_PARAM) + "=" + loginTicketId);        // Get service properties and set security level.        try {            serviceProperties = MoriaController.getServiceProperties(loginTicketId);            request.setAttribute(RequestUtil.ATTR_SEC_LEVEL, "" + MoriaController.getSecLevel(loginTicketId));            // TODO: Move error handling into doGet instead, where            // MoriaControllerException is ignored.        } catch (UnknownTicketException e) {            errorType = RequestUtil.ERROR_UNKNOWN_TICKET;        } catch (IllegalInputException e) {            errorType = RequestUtil.ERROR_UNKNOWN_TICKET;        } catch (InoperableStateException e) {            errorType = RequestUtil.ERROR_MORIA_DOWN;        }        // Set error message, if any.        request.setAttribute(RequestUtil.ATTR_ERROR_TYPE, errorType);        // This entire section is skipped if no service could be looked up due        // to a problem with the login ticket.        if (serviceProperties != null) {            // Decide which language to use for login page.            final String serviceLanguage = (String) serviceProperties.get(RequestUtil.CONFIG_LANG);            String cookieLanguage = null;            if (request.getCookies() != null)                cookieLanguage = RequestUtil.getCookieValue((String) config.get(RequestUtil.PROP_COOKIE_LANG), request.getCookies());            final ResourceBundle bundle = RequestUtil.getBundle(RequestUtil.BUNDLE_LOGIN, request.getParameter(RequestUtil.PARAM_LANG), cookieLanguage, serviceLanguage, request.getHeader("Accept-Language"), (String) config.get(RequestUtil.PROP_LOGIN_DEFAULT_LANGUAGE));            request.setAttribute(RequestUtil.ATTR_BUNDLE, bundle);            request.setAttribute(RequestUtil.ATTR_LANGUAGES, RequestUtil.parseConfig(getConfig(), RequestUtil.PROP_LANGUAGE, RequestUtil.PROP_COMMON));            // Set/update the user's language cookie.            request.setAttribute(RequestUtil.ATTR_SELECTED_LANG, bundle.getLocale());            if (request.getParameter(RequestUtil.PARAM_LANG) != null) {                response.addCookie(RequestUtil.createCookie((String) config.get(RequestUtil.PROP_COOKIE_LANG), request.getParameter(RequestUtil.PARAM_LANG), new Integer((String) config.get(RequestUtil.PROP_COOKIE_LANG_TTL)).intValue()));            }            // Resolve list of allowed organizations, removing those that are            // not.            TreeMap allowedOrganizations = RequestUtil.parseConfig(getConfig(), RequestUtil.PROP_ORG, bundle.getLocale().getLanguage());            final String servicePrincipal = (String) serviceProperties.get(RequestUtil.CONFIG_SERVICE_PRINCIPAL);            Iterator i = allowedOrganizations.values().iterator();            while (i.hasNext())                try {                    if (!MoriaController.isOrganizationAllowedForService(servicePrincipal, (String) i.next()))                        i.remove();                } catch (UnknownServicePrincipalException e) {                    // This is ignored; an unknown service principal should                    // never even reach this stage - and the worst consequence                    // will be an empty organization list.                    log.logWarn("Unknown service principal: " + servicePrincipal);                }            request.setAttribute(RequestUtil.ATTR_ORGANIZATIONS, allowedOrganizations);            // Get organization from URL parameter, service configuration and            // user cookie, with the latter prioritized highest.            String selectedOrg = request.getParameter(RequestUtil.PARAM_ORG);            selectedOrg = (String) serviceProperties.get(RequestUtil.CONFIG_HOME);            if (request.getCookies() != null)                selectedOrg = RequestUtil.getCookieValue((String) config.get(RequestUtil.PROP_COOKIE_ORG), request.getCookies());            request.setAttribute(RequestUtil.ATTR_SELECTED_ORG, selectedOrg);            // Set service display name and URL.            request.setAttribute(RequestUtil.ATTR_CLIENT_NAME, serviceProperties.get(RequestUtil.CONFIG_DISPLAY_NAME));            request.setAttribute(RequestUtil.ATTR_CLIENT_URL, serviceProperties.get(RequestUtil.CONFIG_URL));        }        // Set link to the FAQ.        request.setAttribute("faqlink", config.get(RequestUtil.FAQ_LINK));        // Process JSP.        final RequestDispatcher rd = getServletContext().getNamedDispatcher("Login.JSP");        rd.forward(request, response);    }