response.addCookie(ssoTicketCookie);
if (!denySSO) { Cookie ssoTicketCookie = RequestUtil.createCookie((String) config.get(RequestUtil.PROP_COOKIE_SSO), (String) tickets.get(MoriaController.SSO_TICKET), new Integer((String) config.get(RequestUtil.PROP_COOKIE_SSO_TTL)).intValue()); response.addCookie(ssoTicketCookie); }
    public final void doPost(final HttpServletRequest request, final HttpServletResponse response)            throws IOException, ServletException {        Properties config = getConfig();        /* Login ticket */        String loginTicketId = request.getParameter(config.getProperty(RequestUtil.PROP_LOGIN_TICKET_PARAM));        /* SSO ticket */        String ssoTicketId = request.getParameter(config.getProperty(RequestUtil.PROP_COOKIE_SSO));        String username = request.getParameter(RequestUtil.PARAM_USERNAME);        String password = request.getParameter(RequestUtil.PARAM_PASSWORD);        String org = request.getParameter(RequestUtil.PARAM_ORG);        /* Wash SSO selection input */        String denySSOStr = request.getParameter(RequestUtil.PARAM_DENYSSO);        boolean denySSO = (denySSOStr != null && denySSOStr.equals("true"));        if (denySSO) {            denySSOStr = "true";        } else {            denySSOStr = "false";        }        /* Set cookie and mark request for SSO denial */        Cookie denySSOCookie =                RequestUtil.createCookie((String) config.get(RequestUtil.PROP_COOKIE_DENYSSO), denySSOStr,                                         new Integer((String) config.get(RequestUtil.PROP_COOKIE_DENYSSO_TTL)).intValue());        response.addCookie(denySSOCookie);        request.setAttribute(RequestUtil.ATTR_SELECTED_DENYSSO, new Boolean(denySSO));        /* Parse username */        if (username.indexOf("@") != -1) {            org = username.substring(username.indexOf("@") + 1, username.length());        }        /* Validate organization */        if (org == null || org.equals("") || org.equals("null")) {            showLoginPage(request, response, RequestUtil.ERROR_NO_ORG);            return;        } else if (!RequestUtil.parseConfig(getConfig(), RequestUtil.PROP_ORG,                                            (String) config.get(RequestUtil.PROP_LOGIN_DEFAULT_LANGUAGE))                .containsValue(org)) {            showLoginPage(request, response, RequestUtil.ERROR_INVALID_ORG);            return;        }        /* Attempt login */        Map tickets;        String redirectURL;        try {            tickets = MoriaController.attemptLogin(loginTicketId, ssoTicketId, username + "@" + org, password);            redirectURL = MoriaController.getRedirectURL((String) tickets.get(MoriaController.SERVICE_TICKET));        } catch (AuthenticationException e) {            showLoginPage(request, response, RequestUtil.ERROR_AUTHENTICATION_FAILED);            return;        } catch (UnknownTicketException e) {            showLoginPage(request, response, RequestUtil.ERROR_UNKNOWN_TICKET);            return;        } catch (DirectoryUnavailableException e) {            showLoginPage(request, response, RequestUtil.ERROR_DIRECTORY_DOWN);            return;        } catch (InoperableStateException e) {            showLoginPage(request, response, RequestUtil.ERROR_MORIA_DOWN);            return;        } catch (IllegalInputException e) {            showLoginPage(request, response, RequestUtil.ERROR_NO_CREDENTIALS);            return;            /* This should not happen. Programming error. */        }        /* Authentication has been successful. Remember SSO ticket and organization. */        Cookie orgCookie =                RequestUtil.createCookie(RequestUtil.PROP_COOKIE_ORG,                                         request.getParameter(RequestUtil.PARAM_ORG),                                         new Integer((String) config.get(RequestUtil.PROP_COOKIE_LANG_TTL)).intValue());        Cookie ssoTicketCookie =                RequestUtil.createCookie((String) config.get(RequestUtil.PROP_COOKIE_SSO),                                         (String) tickets.get(MoriaController.SSO_TICKET),                                         new Integer((String) config.get(RequestUtil.PROP_COOKIE_SSO_TTL)).intValue());        response.addCookie(orgCookie);        response.addCookie(ssoTicketCookie);        /* Redirect back to web service */        response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);        response.setHeader("Location", redirectURL);    }