if (username.indexOf("@") != -1) org = username.substring(username.indexOf("@") + 1, username.length()); 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; }
    public void doPost(final HttpServletRequest request, final HttpServletResponse response)    throws IOException, ServletException {        // Get current configuration.        final Properties config = getConfig();        // Get login and SSO ticket ID.        final String loginTicketId = request.getParameter(config.getProperty(RequestUtil.PROP_LOGIN_TICKET_PARAM));        final String ssoTicketId = request.getParameter(config.getProperty(RequestUtil.PROP_COOKIE_SSO));        // Get user's credentials and organization (organization from dropdown).        final String username = request.getParameter(RequestUtil.PARAM_USERNAME);        final String password = request.getParameter(RequestUtil.PARAM_PASSWORD);        String org = request.getParameter(RequestUtil.PARAM_ORG);        // Parse organization, if set in username, and validate results.        if (username.indexOf("@") != -1)            org = username.substring(username.indexOf("@") + 1, username.length());        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;        }        // Did the user choose to deny SSO?        String denySSOStr = request.getParameter(RequestUtil.PARAM_DENYSSO);        final boolean denySSO = (denySSOStr != null && denySSOStr.equals("true"));        if (denySSO)            denySSOStr = "true";        else            denySSOStr = "false";        // Set cookie to remember user's SSO choice.        final 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));        // Store user's organization selection in cookie.        final Cookie orgCookie = RequestUtil.createCookie((String) config.get(RequestUtil.PROP_COOKIE_ORG), request.getParameter(RequestUtil.PARAM_ORG), new Integer((String) config.get(RequestUtil.PROP_COOKIE_ORG_TTL)).intValue());        response.addCookie(orgCookie);        /* Attempt login */        final Map tickets;        final 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;        } catch (AuthorizationException e) {            showLoginPage(request, response, RequestUtil.ERROR_AUTHORIZATION_FAILED);             return;        }                // Authentication is now complete.        // If we didn't disallow SSO, then store the SSO ticket in a cookie.        if (!denySSO) {            final 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);        }        // Redirect back to the web service.        response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);        response.setHeader("Location", redirectURL);    }