Example usage for javax.servlet.http HttpSession removeAttribute

List of usage examples for javax.servlet.http HttpSession removeAttribute

Introduction

In this page you can find the example usage for javax.servlet.http HttpSession removeAttribute.

Prototype

public void removeAttribute(String name);

Source Link

Document

Removes the object bound with the specified name from this session.

Usage

From source file:fr.openwide.talendalfresco.rest.server.command.LoginCommand.java

private User authenticate(String username, String password, String ticket) {

    // case of existing session user : getting alfresco ticket
    User existingSessionUser = null;//from  w w w  . j  ava  2  s .  c  o  m
    HttpSession session = httpRequest.getSession(false);
    if (session != null) {
        existingSessionUser = (User) session.getAttribute(AuthenticationHelper.AUTHENTICATION_USER);
        if (existingSessionUser != null) {
            String existingSessionTicket = existingSessionUser.getTicket();
            // alternatives :
            // 1. using alfresco ticket rather than sso ticket to speed up things
            // NB. this means that before logging in a different user an explicit logout must be done
            // 2. using sso ticket rather than alfresco one
            // this requires never to give the ticket but when we want to relog, which is bothersome
            if (existingSessionTicket != null) {
                ticket = existingSessionTicket;
            }
        }
    }

    UserTransaction tx = null;
    try {
        // Authenticate via the authentication service, then save the details of user in an object
        // in the session - this is used by the servlet filter etc. on each page to check for login
        if (username != null && password != null) {
            // authentication using login (alfresco or sso), since user/pwd params (even empty ones) have been supplied
            // validation :
            RestServerHelper.validateUsername(session, username);
            RestServerHelper.validatePassword(session, password);
            // login :
            authenticationService.authenticate(username, password.toCharArray());

        } else if (ticket != null && ticket.length() != 0) {
            // authentication using ticket (alfresco or sso), since non empty ticket has been supplied
            authenticationService.validate(ticket);

        } else {
            xmlResult.setError(RestCommandResult.CODE_ERROR_AUTH_MISSING,
                    RestServerHelper.getMessage(session, RestServerHelper.MSG_ERROR_MISSING) + " : " + username,
                    null);
            return null;
        }

        // Set the user name as stored by the back end 
        username = authenticationService.getCurrentUserName();

        if (existingSessionUser != null && existingSessionUser.getUserName().equals(username)) {
            // user was already logged in, nothing else to do
            return existingSessionUser;
        }

        // now setting up logged in user elements
        // using non propagated tx because already inside a tx (commandServlet)
        tx = transactionService.getNonPropagatingUserTransaction();
        tx.begin();

        // remove the session invalidated flag (used to remove last username cookie by AuthenticationFilter)
        if (session != null) {
            session.removeAttribute(AuthenticationHelper.SESSION_INVALIDATED);
        }

        // setup User object and Home space ID
        User user = new User(username, authenticationService.getCurrentTicket(),
                personService.getPerson(username));

        NodeRef homeSpaceRef = (NodeRef) nodeService.getProperty(personService.getPerson(username),
                ContentModel.PROP_HOMEFOLDER);

        // check that the home space node exists - else user cannot login
        if (nodeService.exists(homeSpaceRef) == false) {
            throw new InvalidNodeRefException(homeSpaceRef);
        }
        user.setHomeSpaceId(homeSpaceRef.getId());

        tx.commit();
        tx = null; // clear this so we know not to rollback 

        // put the User object in the Session - the authentication servlet will then allow
        // the app to continue without redirecting to the login page
        if (session == null) {
            session = httpRequest.getSession(true); // creating session if none yet
        }
        session.setAttribute(AuthenticationHelper.AUTHENTICATION_USER, user);

        // Set the current locale for Alfresco web app. NB. session exists now.
        I18NUtil.setLocale(Application.getLanguage(session, true));

        return user;

    } catch (AuthenticationException ae) {
        xmlResult.setError(RestCommandResult.CODE_ERROR_AUTH_UNKNOWN_USER,
                RestServerHelper.getMessage(session, RestServerHelper.MSG_ERROR_UNKNOWN_USER) + " : "
                        + username,
                ae);

    } catch (InvalidNodeRefException inre) {
        xmlResult.setError(RestCommandResult.CODE_ERROR_AUTH_UNKNOWN_USER,
                RestServerHelper.getMessage(session, Repository.ERROR_NOHOME) + " : "
                        + inre.getNodeRef().getId() + " (" + username + ")",
                inre);

    } catch (Throwable e) {
        // Some other kind of serious failure
        xmlResult.setError("Unknown technical error when authenticating user " + username, null);

    } finally {
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    }

    return null;
}

From source file:cn.jsprun.struts.action.BasicSettingsAction.java

@SuppressWarnings("unchecked")
public ActionForward bankuaiSetting(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {/*w ww .  j  a  v a  2 s. co m*/
    try {
        if (submitCheck(request, "settingsubmit")) {
            String creditId = request.getParameter("extcreditid");
            int creditid = Integer.parseInt(creditId);
            String[] bankuaiIdArray = request.getParameterValues("bankuaiIdArray");
            StringBuffer fidBuffer = new StringBuffer("0");
            for (String bankuaiId : bankuaiIdArray) {
                fidBuffer.append("," + bankuaiId);
            }
            List<Map<String, String>> forumsInfoMapList = dataBaseService.executeQuery(
                    "SELECT fid,postcredits,replycredits,digestcredits,postattachcredits,getattachcredits FROM "
                            + tablePrefix + "forumfields WHERE fid IN(" + fidBuffer.toString() + ")");
            for (String bankuaiId : bankuaiIdArray) {
                boolean bool = true;
                Map<String, String> forumsInfoMap = null;
                for (Map<String, String> tempMap : forumsInfoMapList) {
                    if (tempMap.get("fid").equals(bankuaiId)) {
                        forumsInfoMap = tempMap;
                        break;
                    }
                }
                if (forumsInfoMap != null) {
                    Map tempMap = null;
                    String postcreditsstatus_ = request.getParameter("postcreditsstatus_" + bankuaiId);
                    String postcreditsInDS = forumsInfoMap.get("postcredits");
                    String textName1 = "postcredits_" + bankuaiId;
                    tempMap = getResultString(request, postcreditsstatus_, postcreditsInDS, creditid,
                            textName1);
                    bool = bool && (Boolean) tempMap.get("bool");
                    String postcreditsResult = (String) tempMap.get("result");
                    String replycreditsstatus_ = request.getParameter("replycreditsstatus_" + bankuaiId);
                    String replycreditsInDS = forumsInfoMap.get("replycredits");
                    String textName2 = "replycredits_" + bankuaiId;
                    tempMap = getResultString(request, replycreditsstatus_, replycreditsInDS, creditid,
                            textName2);
                    bool = bool && (Boolean) tempMap.get("bool");
                    String replycreditsResult = (String) tempMap.get("result");
                    String digestcreditsstatus_ = request.getParameter("digestcreditsstatus_" + bankuaiId);
                    String digestcreditsInDS = forumsInfoMap.get("digestcredits");
                    String textName3 = "digestcredits_" + bankuaiId;
                    tempMap = getResultString(request, digestcreditsstatus_, digestcreditsInDS, creditid,
                            textName3);
                    bool = bool && (Boolean) tempMap.get("bool");
                    String digestcreditsResult = (String) tempMap.get("result");
                    String postattachcreditsstatus_ = request
                            .getParameter("postattachcreditsstatus_" + bankuaiId);
                    String postattachcreditsInDS = forumsInfoMap.get("postattachcredits");
                    String textName4 = "postattachcredits_" + bankuaiId;
                    tempMap = getResultString(request, postattachcreditsstatus_, postattachcreditsInDS,
                            creditid, textName4);
                    bool = bool && (Boolean) tempMap.get("bool");
                    String postattachcreditsResult = (String) tempMap.get("result");
                    String getattachcreditsstatus_ = request
                            .getParameter("getattachcreditsstatus_" + bankuaiId);
                    String getattachcreditsInDS = forumsInfoMap.get("getattachcredits");
                    String textName5 = "getattachcredits_" + bankuaiId;
                    tempMap = getResultString(request, getattachcreditsstatus_, getattachcreditsInDS, creditid,
                            textName5);
                    bool = bool && (Boolean) tempMap.get("bool");
                    String getattachcreditsResult = (String) tempMap.get("result");
                    if (!bool) {
                        dataBaseService.execute("UPDATE " + tablePrefix + "forumfields SET postcredits='"
                                + postcreditsResult + "',replycredits='" + replycreditsResult
                                + "',digestcredits='" + digestcreditsResult + "',postattachcredits='"
                                + postattachcreditsResult + "',getattachcredits='" + getattachcreditsResult
                                + "' WHERE fid=" + bankuaiId);
                    }
                }
            }
            request.setAttribute("message", getMessage(request, "a_setting_creditwizard_succeed"));
            request.setAttribute("url_forward", request.getContextPath()
                    + FinalProperty.FROM_BasicSettingsAction_GO_bksetting + "&extcreditid=" + creditId);
            request.getSession().setAttribute("extcreditidFromBankuaiSettingCommit", creditId);
            return mapping.findForward("message");
        }
    } catch (Exception e) {
        request.setAttribute("message", e.getMessage());
        return mapping.findForward("message");
    }
    String creditId = request.getParameter("extcreditid");
    if (creditId == null) {
        HttpSession session = request.getSession();
        creditId = (String) session.getAttribute("extcreditidFromBankuaiSettingCommit");
        session.removeAttribute("extcreditidFromBankuaiSettingCommit");
    }
    int creditid = Integer.parseInt(creditId);
    List<BKSettingVO> forumsList = getBKSettingVOList(creditid);
    beforeGoBKsetting_jsp(request, creditid, forumsList);
    return mapping.findForward("bksetting");
}

From source file:com.esd.ps.AdministratorController.java

/**
 * ?userworker?,sessionuser?//from  w  ww .j ava2s  . c o m
 * 
 * @param worker
 * @param session
 * @return workerImage?
 * @throws IOException
 */
@RequestMapping(value = "/addworker", method = RequestMethod.POST)
public ModelAndView addworkerPOST(
        @RequestParam(value = "workerImage", required = false) MultipartFile workerImage, String workerRealName,
        String workerDisabilityCard, String workerPhone, String workerBankCard, String workerPaypal,
        RedirectAttributes redirectAttributes, HttpSession session, HttpServletRequest request,
        int userRegisted) {
    logger.debug(
            "workerRealName:{},workerIdCard:{},workerDisabilityCard:{},workerBankCard:{},workerPaypal:{},workerPhone:{}",
            workerRealName, workerDisabilityCard, workerBankCard, workerPaypal);
    boolean flag = true;
    if (workerDisabilityCard(workerDisabilityCard) == 1) {
        redirectAttributes.addFlashAttribute(Constants.USER_WORKERDISABILITYCARD,
                MSG_WORKERDISABILITYCARD_EXIST);
        flag = false;
    }
    if (workerPhone(workerPhone) == 1) {
        redirectAttributes.addFlashAttribute(Constants.USER_WORKERDISABILITYCARD, MSG_WORKERPHONE_EXIST);
        flag = false;
    }
    worker worker = new worker();
    if (flag) {
        // int login =
        // Integer.parseInt(request.getAttribute("login").toString());
        String address = null;
        if (userRegisted == 0) {
            worker.setUserId(Integer.parseInt(session.getAttribute(Constants.USER_ID).toString()));
            address = Constants.REDIRECT + Constants.COLON + Constants.WORKER;
        } else if (userRegisted == 1) {
            worker.setUserId(Integer.parseInt(session.getAttribute(Constants.ADD_USER_ID).toString()));
            address = Constants.REDIRECT + Constants.COLON + "administrator";
        }
        if (!workerImage.isEmpty()) {
            try {
                worker.setWorkerImage(workerImage.getBytes());
            } catch (IOException e) {

                e.printStackTrace();
            }
        }
        worker.setWorkerBankCard(workerBankCard);
        worker.setWorkerDisabilityCard(workerDisabilityCard);
        worker.setWorkerIdCard(workerDisabilityCard.substring(0, 17));
        worker.setWorkerPaypal(workerPaypal);
        worker.setWorkerPhone(workerPhone);
        worker.setWorkerRealName(workerRealName);

        worker.setCreateId(Integer.parseInt(session.getAttribute(Constants.USER_ID).toString()));
        worker.setCreateTime(new Date());
        StackTraceElement[] items = Thread.currentThread().getStackTrace();
        worker.setCreateMethod(items[1].toString());
        worker.setVersion(1);
        workerService.insertSelective(worker);
        session.removeAttribute(Constants.ADD_USER_ID);
        return new ModelAndView(address);
    }
    redirectAttributes.addFlashAttribute(Constants.WORKER, worker);
    return new ModelAndView(Constants.REDIRECT + Constants.COLON + Constants.ADD_WORKER);
}

From source file:cn.jsprun.struts.action.BasicSettingsAction.java

@SuppressWarnings("unchecked")
public ActionForward usergroupSetting(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {//from ww  w  .  ja  va  2s .com
    try {
        if (submitCheck(request, "settingsubmit")) {
            String creditId = request.getParameter("extcreditid");
            List<Map<String, String>> ugInfoMapList = dataBaseService
                    .executeQuery("SELECT groupid,grouptitle,raterange FROM " + tablePrefix
                            + "usergroups ORDER By radminid DESC,groupid DESC");
            for (Map<String, String> ugInfoMap : ugInfoMapList) {
                String groupId = ugInfoMap.get("groupid");
                String checkBox = request.getParameter("raterangestatus_" + groupId);
                String minValue = request.getParameter("minValue_" + groupId);
                String maxValue = request.getParameter("maxValue_" + groupId);
                String hourMaxValue = request.getParameter("hourMaxValue_" + groupId);
                if (checkBox != null) {
                    String grouptitle = ugInfoMap.get("grouptitle");
                    minValue = FormDataCheck.getNumberFromFormOfDisplayorder(minValue);
                    minValue = (Long.valueOf(minValue) < -999 ? "-999" : minValue);
                    maxValue = FormDataCheck.getNumberFromFormOfDisplayorder(maxValue);
                    maxValue = (Long.valueOf(maxValue) > 999 ? "999" : maxValue);
                    hourMaxValue = FormDataCheck.getNumberFromFormOfDisplayorder(hourMaxValue);
                    hourMaxValue = (Long.valueOf(hourMaxValue) > 99999 ? "99999" : hourMaxValue);
                    Long longMinValue = Long.valueOf(minValue);
                    Long longMaxValue = Long.valueOf(maxValue);
                    Long longHourMaxValue = Long.valueOf(hourMaxValue);
                    if (longMinValue >= longMaxValue || longHourMaxValue < longMaxValue
                            || longHourMaxValue + longMinValue < 0) {
                        request.setAttribute("message",
                                getMessage(request, "a_setting_creditwizard_rate_invalid", grouptitle));
                        request.setAttribute("return", true);
                        return mapping.findForward("message");
                    }
                }
                if (minValue != null) {
                    String raterange = ugInfoMap.get("raterange");
                    if (raterange != null && !raterange.equals("")) {
                        String[] raterangeArray = raterange.split("\t");
                        int count = raterangeArray.length / 4;
                        boolean haveExtcredit = false;
                        int sign = 0;
                        for (int j = 0; j < count; j++) {
                            String extcreditid = raterangeArray[j * 4];
                            if (extcreditid.equals(creditId)) {
                                haveExtcredit = true;
                                sign = j;
                                break;
                            }
                        }
                        if (haveExtcredit) {
                            if (checkBox == null) {
                                StringBuffer buffer = new StringBuffer();
                                for (int j = 0; j < raterangeArray.length; j++) {
                                    if (j != sign * 4 && j != sign * 4 + 1 && j != sign * 4 + 2
                                            && j != sign * 4 + 3) {
                                        buffer.append(raterangeArray[j] + "\t");
                                    }
                                }
                                String result = buffer.toString();
                                if (result.endsWith("\t")) {
                                    result = result.substring(0, result.length() - 1);
                                }
                                dataBaseService.execute("UPDATE " + tablePrefix + "usergroups SET raterange='"
                                        + result + "' WHERE groupid=" + groupId);
                            } else {
                                String minValueDB = raterangeArray[sign * 4 + 1];
                                String maxValueDB = raterangeArray[sign * 4 + 2];
                                String hourMaxValueDB = raterangeArray[sign * 4 + 3];
                                if (!minValue.equals(minValueDB) || !maxValue.equals(maxValueDB)
                                        || !hourMaxValue.equals(hourMaxValueDB)) {
                                    StringBuffer buffer = new StringBuffer();
                                    for (int j = 0; j < raterangeArray.length; j++) {
                                        if (j == sign * 4 + 1) {
                                            buffer.append(minValue + "\t");
                                        } else if (j == sign * 4 + 2) {
                                            buffer.append(maxValue + "\t");
                                        } else if (j == sign * 4 + 3) {
                                            buffer.append(hourMaxValue + "\t");
                                        } else {
                                            buffer.append(raterangeArray[j] + "\t");
                                        }
                                    }
                                    String result = buffer.toString();
                                    if (result.endsWith("\t")) {
                                        result = result.substring(0, result.length() - 1);
                                    }
                                    dataBaseService
                                            .execute("UPDATE " + tablePrefix + "usergroups SET raterange='"
                                                    + result + "' WHERE groupid=" + groupId);
                                }
                            }
                        } else {
                            if (checkBox != null) {
                                StringBuffer buffer = new StringBuffer(raterange);
                                buffer.append("\t" + creditId + "\t" + minValue + "\t" + maxValue + "\t"
                                        + hourMaxValue);
                                dataBaseService.execute("UPDATE " + tablePrefix + "usergroups SET raterange='"
                                        + buffer.toString() + "' WHERE groupid=" + groupId);
                            }
                        }
                    } else {
                        if (checkBox != null) {
                            StringBuffer buffer = new StringBuffer(raterange);
                            buffer.append(creditId + "\t" + minValue + "\t" + maxValue + "\t" + hourMaxValue);
                            dataBaseService.execute("UPDATE " + tablePrefix + "usergroups SET raterange='"
                                    + buffer.toString() + "' WHERE groupid=" + groupId);
                        }
                    }
                }
            }
            request.setAttribute("message", getMessage(request, "a_setting_creditwizard_succeed"));
            request.setAttribute("url_forward",
                    request.getContextPath() + FinalProperty.FROM_BasicSettingsAction_GO_usergroupsetting);
            request.getSession().setAttribute("extcreditidFromUsergroupSettingCommit", creditId);
            return mapping.findForward("message");
        }
    } catch (Exception e) {
        request.setAttribute("message", e.getMessage());
        return mapping.findForward("message");
    }
    String creditId = request.getParameter("extcreditid");
    if (creditId == null) {
        HttpSession session = request.getSession();
        creditId = (String) session.getAttribute("extcreditidFromUsergroupSettingCommit");
        session.removeAttribute("extcreditidFromUsergroupSettingCommit");
    }
    int creditid = Integer.parseInt(creditId);
    List<UsergroupSettingVO> usergroupSettingVOList = getUsergroupSettingVOList(creditId);
    Map extcredits = dataParse.characterParse(ForumInit.settings.get("extcredits_bak"), true);
    Map extcredit = (Map) extcredits.get(creditid);
    request.setAttribute("extcredits", extcredits);
    request.setAttribute("usergroupVOList", usergroupSettingVOList);
    request.setAttribute("extcreditid", creditid);
    request.setAttribute("extcredit", extcredit);
    return mapping.findForward("usergroupsetting");
}

From source file:mercury.BaseHandler.java

private String processMenu(HttpServletRequest request, String submitButton) {
    HttpSession session = request.getSession();

    if (submitButton.equals("LOGIN")) {
        String username = request.getParameter("USERNAME");
        String password = request.getParameter("PASSWORD");

        if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) {
            Dialog.showWarning(request, "ERROR_ACCESS_DENIED");
            return "/jsp/login.jsp";
        }/*w  w  w. j a  va2 s. co  m*/

        LoginBO bo = new LoginBO();
        LoginDTO user = bo.login(username, password);

        if (user != null) {
            AuthorizationBO authBO = new AuthorizationBO();
            AuthorizationPoints atps = authBO.getUserAuthPoints(user);
            atps.setAdmin(user.getLoginId() == 1);

            session.setAttribute("LOGGED_USER", user);
            session.setAttribute("LOGGED_USER_ATPS", atps);

            if (atps.isAdmin()) {
                boolean warningPassword = password.toLowerCase().equals("abracadabra");
                session.setAttribute("SYSTEM_WARNING_PASSWORD", warningPassword);
            }

            if (atps.isAllowed(AuthorizationPointTypes.ADMIN_BACKUP)) {
                boolean warningBackup = false;
                AdminBO adminBO = new AdminBO();

                Date lastBackup = adminBO.getLastBackupDate();
                if (lastBackup == null) {
                    String path = request.getSession().getServletContext().getRealPath(".");
                    //String path = session.getServletContext().getRealPath("/WEB-INF/sqldump/");
                    Date now = new Date();

                    boolean b = (new BackupBO()).doBackup(path, String.valueOf(now.getTime()));
                    if (b) {
                        adminBO.insertLastBackupDate(now);
                    }
                } else {
                    int diff = DateUtils.dateDiff(lastBackup, new Date());
                    warningBackup = (diff >= 7);
                }

                session.setAttribute("SYSTEM_WARNING_BACKUP", warningBackup);
            }

            if (atps.isAllowed(AuthorizationPointTypes.ADMIN_REINDEX)) {
                session.setAttribute("SYSTEM_WARNING_REINDEX", new AdminBO().isIndexOutdated());
            }

            Dialog.showNormal(request, "DIALOG_WELCOME_MESSAGE");
            return "/jsp/logged.jsp";
        } else {
            Dialog.showWarning(request, "ERROR_ACCESS_DENIED");
            return "/jsp/login.jsp";
        }

    } else if (submitButton.equals("LOGOUT")) {
        String lang = (String) session.getAttribute("I18N");
        session.invalidate();
        session = request.getSession();
        session.setAttribute("I18N", lang);
        session.removeAttribute("LOGGED_USER");

        Dialog.showNormal(request, "DIALOG_GOODBYE_MESSAGE");
        return "/jsp/login.jsp";

    } else if (submitButton.equals("SEARCH_BIBLIO")) {
        Dialog.showNormal(request, "DIALOG_BIBLIO_SEARCH");
        return "/jsp/search/biblio.jsp";

    } else if (submitButton.equals("SEARCH_AUTH")) {
        Dialog.showNormal(request, "DIALOG_AUTH_SEARCH");
        return "/jsp/search/auth.jsp";

    } else if (submitButton.equals("SEARCH_THESAURUS")) {
        Dialog.showNormal(request, "DIALOG_THESAURUS_SEARCH");
        return "/jsp/search/vocabulary.jsp";

    } else if (submitButton.equals("SEARCH_Z3950")) {
        Z3950BO bo = new Z3950BO();
        session.setAttribute("z3950_server_list", bo.listServers());

        Dialog.showNormal(request, "DIALOG_Z3950_SEARCH");
        return "/jsp/search/distributed.jsp";

    } else if (submitButton.equals("CIRCULATION_REGISTER")) {
        CirculationBO circulationBO = new CirculationBO();
        Collection<UserTypeDTO> listAllUserType = circulationBO.findAllUserType();
        session.setAttribute("LIST_USERS_TYPE", listAllUserType);

        Dialog.showNormal(request, "DIALOG_REGISTER");
        return "/jsp/circulation/user.jsp";

    } else if (submitButton.equals("CIRCULATION_LENDING")) {
        new ReservationBO().deleteExpired();

        Dialog.showNormal(request, "DIALOG_LENDING");
        return "/jsp/circulation/lending.jsp";

    } else if (submitButton.equals("CIRCULATION_RESERVATION")) {
        new ReservationBO().deleteExpired();

        Dialog.showNormal(request, "DIALOG_RESERVATION");
        return "/jsp/circulation/reservation.jsp";

    } else if (submitButton.equals("CIRCULATION_ACCESS")) {
        Dialog.showNormal(request, "DIALOG_ACCESS");
        return "/jsp/circulation/access.jsp";

    } else if (submitButton.equals("CIRCULATION_USER_CARDS")) {
        Dialog.showNormal(request, "DIALOG_USER_CARDS");
        return "/jsp/circulation/user_cards.jsp";

    } else if (submitButton.equals("CATALOGING_BIBLIO")) {
        Dialog.showNormal(request, "DIALOG_BIBLIO_CATALOGING");
        return "/jsp/cataloging/biblio.jsp";

    } else if (submitButton.equals("CATALOGING_AUTH")) {
        Dialog.showNormal(request, "DIALOG_AUTH_CATALOGING");
        return "/jsp/cataloging/auth.jsp";

    } else if (submitButton.equals("CATALOGING_VOCABULARY")) {
        Dialog.showNormal(request, "DIALOG_THESAURUS_CATALOGING");
        return "/jsp/cataloging/vocabulary.jsp";

    } else if (submitButton.equals("CATALOGING_IMPORT")) {
        Dialog.showNormal(request, "DIALOG_IMPORT");
        return "/jsp/cataloging/import.jsp";

    } else if (submitButton.equals("CATALOGING_LABEL")) {
        Dialog.showNormal(request, "DIALOG_LABELS");
        return "/jsp/cataloging/label.jsp";

    } else if (submitButton.equals("CATALOGING_BIBLIO_MOVE")) {
        Dialog.showNormal(request, "DIALOG_BIBLIO_MOVE");
        return "/jsp/cataloging/move.jsp";

    } else if (submitButton.equals("ACQUISITION_SUPPLIER")) {
        Dialog.showNormal(request, "DIALOG_SUPPLIER");
        return "/jsp/acquisition/supplier.jsp";

    } else if (submitButton.equals("ACQUISITION_REQUISITION")) {
        Dialog.showNormal(request, "DIALOG_REQUISITION");
        return "/jsp/acquisition/requisition.jsp";

    } else if (submitButton.equals("ACQUISITION_QUOTATION")) {
        SupplierBO bo = new SupplierBO();
        List<SupplierDTO> suppliers = bo.listAllSuppliers();
        session.setAttribute("supplierList", suppliers);
        RequestBO rbo = new RequestBO();
        List<RequestDTO> requests = rbo.listAllPendingRequests();
        session.setAttribute("requestList", requests);

        Dialog.showNormal(request, "DIALOG_QUOTATION");
        return "/jsp/acquisition/quotation.jsp";

    } else if (submitButton.equals("ACQUISITION_ORDER")) {
        SupplierBO bo = new SupplierBO();
        List<SupplierDTO> suppliers = bo.listAllSuppliers();
        session.setAttribute("supplierList", suppliers);
        QuotationBO qbo = new QuotationBO();
        List<QuotationDTO> quotations = qbo.listAllQuotations();
        session.setAttribute("quotationList", quotations);

        Dialog.showNormal(request, "DIALOG_ORDER");
        return "/jsp/acquisition/order.jsp";

    } else if (submitButton.equals("ADMINISTRATION_MAINTENANCE")) {
        session.setAttribute("MOVE_RECORDS", "ESCONDER");
        session.setAttribute("BUTTON_MOVE_RECORDS", "EXIBIR");
        session.setAttribute("TOTAL_WORK_REC", new AdminBO().totalRecords("WORK"));
        session.setAttribute("TOTAL_MAIN_REC", new AdminBO().totalRecords("MAIN"));
        session.removeAttribute("LIST_RECORDS");

        String defaultFormat = I18nUtils.getText(session, "biblivre3", "DEFAULT_DATETIME_FORMAT");
        SimpleDateFormat formatter = new SimpleDateFormat(defaultFormat);
        AdminBO bo = new AdminBO();
        List<Date> dates = bo.getLastFiveBackups();
        List<String[]> formattedDates = new ArrayList<String[]>();
        for (Date date : dates) {
            formattedDates.add(new String[] { formatter.format(date), String.valueOf(date.getTime()) });
        }
        session.setAttribute("SYSTEM_LAST_FIVE_BACKUPS", formattedDates);

        Dialog.showNormal(request, "DIALOG_MAINTENANCE");
        return "/jsp/administration/maintenance.jsp";

    } else if (submitButton.equals("ADMINISTRATION_PASSWORD")) {
        Dialog.showNormal(request, "DIALOG_PASSWORD");
        return "/jsp/administration/password.jsp";

    } else if (submitButton.equals("ADMINISTRATION_REPORTS")) {
        Dialog.showNormal(request, "DIALOG_REPORTS");
        return "/jsp/administration/reports.jsp";

    } else if (submitButton.equals("ADMINISTRATION_PERMISSIONS")) {
        Dialog.showNormal(request, "DIALOG_PERMISSIONS");
        return "/jsp/administration/permissions.jsp";

    } else if (submitButton.equals("ADMINISTRATION_USER_TYPES")) {
        Dialog.showNormal(request, "DIALOG_USER_TYPES_ADMIN");
        return "/jsp/administration/usertypes.jsp";

    } else if (submitButton.equals("ADMINISTRATION_ACCESSCARDS")) {
        Dialog.showNormal(request, "DIALOG_ACCESSCARDS");
        return "/jsp/administration/accesscards.jsp";

    } else if (submitButton.equals("ADMINISTRATION_Z3950SERVERS")) {
        final Z3950BO bo = new Z3950BO();
        session.setAttribute("serverStatus", bo.getServerStatus());

        Dialog.showNormal(request, "DIALOG_Z3950SERVER");
        return "/jsp/administration/z3950.jsp";

    } else if (submitButton.equals("ADMINISTRATION_CONFIGURATION")) {
        Dialog.showNormal(request, "DIALOG_CONFIGURATION");
        return "/jsp/administration/configuration.jsp";

    } else if (submitButton.equals("HELP_ABOUT")) {
        Dialog.showNormal(request, "DIALOG_ABOUT");
        return "/jsp/help/about.jsp";
    }

    Dialog.showNormal(request, "DIALOG_VOID");
    return null;
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.filterConfiguration.FilterConfigurationImportHandler.java

/**
 * Invokes this PageHandler/*from w w  w  . j a  va2s  . c om*/
 * 
 * @param pageDescriptor
 *            the page desciptor
 * @param request
 *            the original request sent from the browser
 * @param response
 *            the original response object
 * @param context
 *            context the Servlet context
 * @throws IOException
 * @throws ServletException
 * @throws EnvoyServletException
 */
public void invokePageHandler(WebPageDescriptor p_pageDescriptor, HttpServletRequest p_request,
        HttpServletResponse p_response, ServletContext p_context)
        throws EnvoyServletException, ServletException, IOException {
    HttpSession session = p_request.getSession(false);
    String sessionId = session.getId();
    SessionManager sessionMgr = (SessionManager) session.getAttribute(WebAppConstants.SESSION_MANAGER);
    m_userId = (String) session.getAttribute(WebAppConstants.USER_NAME);
    String companyId = CompanyThreadLocal.getInstance().getValue();
    sessionMgr.setAttribute("companyId", companyId);
    String action = p_request.getParameter("action");
    if (action != null) {
        if ("startUpload".equals(action)) {
            File uploadedFile = this.uploadFile(p_request);
            session.setAttribute("uploading_filter", uploadedFile);
        } else if ("doImport".equals(action)) {
            int count = 0;
            if (sessionMgr.getAttribute("count") != null) {
                count = (Integer) sessionMgr.getAttribute("count");
                if (count == 1) {
                    count++;
                    sessionMgr.setAttribute("count", count);
                }
            } else {
                count++;
                sessionMgr.setAttribute("count", count);
            }
            if (session.getAttribute("uploading_filter") != null) {
                filter_percentage_map.clear();// .remove(sessionId);
                filter_error_map.clear();// .remove(sessionId);
                File uploadedFile = (File) session.getAttribute("uploading_filter");
                session.removeAttribute("uploading_filter");

                DoImport imp = new DoImport(sessionId, uploadedFile, companyId);
                imp.start();
            } else {
                logger.error("No uploaded user info file.");
            }
        } else if ("refreshProgress".equals(action)) {
            this.refreshProgress(p_request, p_response, sessionId);
            return;
        }
    }

    ResourceBundle bundle = PageHandler.getBundle(session);
    setLable(p_request, bundle);
    super.invokePageHandler(p_pageDescriptor, p_request, p_response, p_context);
}

From source file:Login.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Login</title>");
    out.println("</head>");
    out.println("<body>");

    HttpSession session = request.getSession();
    Connection connection = (Connection) session.getAttribute("connection");
    if (connection == null) {
        String userName = request.getParameter("username");
        String password = request.getParameter("password");
        if (userName == null || password == null) {
            // prompt the user for her username and password
            out.println("<form method=\"get\" action=\"Login\">");
            out.println("Please specify the following to log in:<p>");
            out.println("Username: <input type=\"text\" " + "name=\"username\" size=\"30\"><p>");
            out.println("Password: <input type=\"password\" " + "name=\"password\" size=\"30\"><p>");
            out.println("<input type=\"submit\" value=\"Login\">");
            out.println("</form>");
        } else {/*ww  w . ja  v  a2 s  . c  o  m*/
            // create the connection
            try {
                connection = DriverManager.getConnection("jdbc:oracle:thin:@dssw2k01:1521:orcl", userName,
                        password);
            } catch (SQLException e) {
                out.println("Login doGet() " + e.getMessage());
            }
            if (connection != null) {
                // store the connection
                session.setAttribute("connection", connection);
                response.sendRedirect("Login");
                return;
            }
        }
    } else {
        String logout = request.getParameter("logout");
        if (logout == null) {
            // test the connection
            Statement statement = null;
            ResultSet resultSet = null;
            String userName = null;
            try {
                statement = connection.createStatement();
                resultSet = statement.executeQuery("select initcap(user) from sys.dual");
                if (resultSet.next())
                    userName = resultSet.getString(1);
            } catch (SQLException e) {
                out.println("Login doGet() SQLException: " + e.getMessage() + "<p>");
            } finally {
                if (resultSet != null)
                    try {
                        resultSet.close();
                    } catch (SQLException ignore) {
                    }
                if (statement != null)
                    try {
                        statement.close();
                    } catch (SQLException ignore) {
                    }
            }
            out.println("Hello " + userName + "!<p>");
            out.println("Your session ID is " + session.getId() + "<p>");
            out.println("It was created on " + new java.util.Date(session.getCreationTime()) + "<p>");
            out.println("It was last accessed on " + new java.util.Date(session.getLastAccessedTime()) + "<p>");
            out.println("<form method=\"get\" action=\"Login\">");
            out.println("<input type=\"submit\" name=\"logout\" " + "value=\"Logout\">");
            out.println("</form>");
        } else {
            // close the connection and remove it from the session
            try {
                connection.close();
            } catch (SQLException ignore) {
            }
            session.removeAttribute("connection");
            out.println("You have been logged out.");
        }
    }
    out.println("</body>");
    out.println("</html>");
}

From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractBillingController.java

@RequestMapping(value = { "/history" }, method = RequestMethod.GET)
public String showHistory(@ModelAttribute("currentTenant") Tenant currentTenant,
        @RequestParam(value = "tenant", required = false) String tenantParam,
        @RequestParam(value = "user", required = false) String userParam,
        @RequestParam(value = "page", required = false, defaultValue = "1") String currentPage,
        HttpSession session, ModelMap map, HttpServletRequest request) {
    int page;//from w  w w.  j  a  v  a2 s  .  co  m
    int perPage;
    try {
        page = Integer.parseInt(currentPage);
    } catch (NumberFormatException nFE) {
        page = 1;
    }
    try {
        perPage = getDefaultPageSize();
        if (perPage > 14) {
            perPage = 14;
        }
    } catch (NumberFormatException nFE) {
        perPage = 14;
    }

    setPage(map, Page.USAGE_BILLING_BILLING_HISTORY);

    User currentUser = getCurrentUser();
    boolean showUserProfile = false;
    Tenant effectiveTenant = (Tenant) request.getAttribute(UserContextInterceptor.EFFECTIVE_TENANT_KEY);

    if ((Boolean) request.getAttribute("isSurrogatedTenant")) {
        showUserProfile = true;
        map.addAttribute("userHasCloudServiceAccount",
                userService.isUserHasAnyActiveCloudService(effectiveTenant.getOwner()));
    } else {
        map.addAttribute("userHasCloudServiceAccount", userService.isUserHasAnyActiveCloudService(currentUser));
    }

    map.addAttribute("showUserProfile", showUserProfile);
    map.addAttribute("currentUser", currentUser);

    boolean showUsers = false;
    try {
        List<AccountStatement> accountStatements = billingService.getAccountStatements(effectiveTenant, null,
                page, perPage, null, null, null);
        map.addAttribute("billingActivities", accountStatements);
    } catch (Exception e) {
        logger.error("Error occurred while getting account statements " + e);

    }
    if (hasFullBillingView(currentUser)) {
        List<User> users = effectiveTenant.getUsers();
        map.addAttribute("users", users);
        showUsers = true;

    }
    map.addAttribute("showUsers", showUsers);
    map.addAttribute("tenant", effectiveTenant);

    /*
     * if(totalInvoices-(page*perPage)>0){ map.addAttribute("enable_next", true); } else{
     * map.addAttribute("enable_next", false); }
     */

    map.addAttribute("current_page", page);

    if (session.getAttribute("makepayment_status") != null
            && session.getAttribute("makepayment_status").equals("true")) {
        map.addAttribute("statusMessage", "succeeded");
        session.removeAttribute("makepayment_status");
    } else if (session.getAttribute("makepayment_status") != null
            && session.getAttribute("makepayment_status").equals("false")) {
        map.addAttribute("statusMessage", "failed");
        session.removeAttribute("makepayment_status");
    }
    return "billing.history";

}

From source file:be.fedict.eid.dss.webapp.ProtocolEntryServlet.java

@Override
protected void handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    LOG.debug("handle request");
    LOG.debug("request URI: " + request.getRequestURI());
    LOG.debug("request method: " + request.getMethod());
    LOG.debug("request path info: " + request.getPathInfo());
    LOG.debug("request context path: " + request.getContextPath());
    LOG.debug("request query string: " + request.getQueryString());
    LOG.debug("request path translated: " + request.getPathTranslated());
    String protocolServiceContextPath = request.getPathInfo();
    HttpSession httpSession = request.getSession();
    storeProtocolServiceContextPath(protocolServiceContextPath, httpSession);

    DSSProtocolService dssProtocolService = super.findProtocolService(protocolServiceContextPath);
    if (null == dssProtocolService) {
        LOG.warn("unsupported protocol: " + protocolServiceContextPath);
        response.sendRedirect(request.getContextPath() + this.unknownProtocolPageInitParam);
        return;//  w  ww .  j av a  2 s  . c  o m
    }

    DSSRequest dssRequest;
    try {
        dssRequest = dssProtocolService.handleIncomingRequest(request, response);
    } catch (Exception e) {
        error(request, response, e.getMessage(), e);
        return;
    }

    // try to identify a RP from the domain
    LOG.debug("DSS Request domain: " + dssRequest.getDomain());
    RPEntity rp = this.rpService.find(dssRequest.getDomain());
    if (null != rp) {

        if (!isValid(rp, dssRequest, request, response)) {
            return;
        }

    }

    // get document data, either from artifact map or direct
    byte[] documentData;
    String contentType;
    if (null != dssRequest.getDocumentId()) {

        DocumentEntity document = this.documentService.find(dssRequest.getDocumentId());
        if (null == document) {
            error(request, response, "Document not found!", null);
            return;
        }
        documentData = document.getData();
        contentType = document.getContentType();

    } else {
        documentData = dssRequest.getDocumentData();
        contentType = dssRequest.getContentType();
    }

    if (null == documentData || null == contentType) {
        error(request, response, "No document data or content type found.", null);
        return;
    }

    DocumentRepository documentRepository = new DocumentRepository(httpSession);

    // store artifact if specified for later
    if (null != dssRequest.getDocumentId()) {
        documentRepository.setDocumentId(dssRequest.getDocumentId());
    }

    /*
     * Check the document format.
     */
    LOG.debug("document content type: " + contentType);
    documentRepository.setDocumentContentType(contentType);
    DSSDocumentService documentService = super.findDocumentService(contentType);
    if (null == documentService) {
        LOG.debug("no document service found for content type: " + contentType);
        documentRepository.setSignatureStatus(SignatureStatus.FILE_FORMAT);
        response.sendRedirect(request.getContextPath() + this.exitPageInitParam);
        return;
    }
    try {
        documentService.checkIncomingDocument(documentData);
    } catch (Exception e) {
        LOG.debug("document verification error: " + e.getMessage(), e);
        documentRepository.setSignatureStatus(SignatureStatus.FILE_FORMAT);
        response.sendRedirect(request.getContextPath() + this.exitPageInitParam);
        return;
    }

    /*
     * Store the relevant data into the HTTP session document repository.
     */
    documentRepository.setDocument(documentData);

    /*
     * i18n
     */
    String language = dssRequest.getLanguage();
    if (null != language) {
        httpSession.setAttribute(View.LANGUAGE_SESSION_ATTRIBUTE, language);
    } else {
        httpSession.removeAttribute(View.LANGUAGE_SESSION_ATTRIBUTE);
    }

    // accounting
    accountingService.addRequest(dssRequest.getDomain());

    /*
     * Goto the next eID DSS page.
     */
    response.sendRedirect(request.getContextPath() + this.nextPageInitParam);
}

From source file:SessionLogin.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Login</title>");
    out.println("</head>");
    out.println("<body>");

    HttpSession session = request.getSession();
    SessionConnection sessionConnection = (SessionConnection) session.getAttribute("sessionconnection");
    Connection connection = null;
    if (sessionConnection != null) {
        connection = sessionConnection.getConnection();
    }//from  w  w w  .  java2 s. com
    if (connection == null) {
        String userName = request.getParameter("username");
        String password = request.getParameter("password");
        if (userName == null || password == null) {
            // prompt the user for her username and password
            out.println("<form method=\"get\" action=\"SessionLogin\">");
            out.println("Please specify the following to log in:<p>");
            out.println("Username: <input type=\"text\" " + "name=\"username\" size=\"30\"><p>");
            out.println("Password: <input type=\"password\" " + "name=\"password\" size=\"30\"><p>");
            out.println("<input type=\"submit\" value=\"Login\">");
            out.println("</form>");
        } else {
            // create the connection
            try {
                connection = DriverManager.getConnection("jdbc:oracle:thin:@dssw2k01:1521:orcl", userName,
                        password);
            } catch (SQLException e) {
                out.println("Login doGet() " + e.getMessage());
            }
            if (connection != null) {
                // store the connection
                sessionConnection = new SessionConnection();
                sessionConnection.setConnection(connection);
                session.setAttribute("sessionconnection", sessionConnection);
                response.sendRedirect("SessionLogin");
                return;
            }
        }
    } else {
        String logout = request.getParameter("logout");
        if (logout == null) {
            // test the connection
            Statement statement = null;
            ResultSet resultSet = null;
            String userName = null;
            try {
                statement = connection.createStatement();
                resultSet = statement.executeQuery("select initcap(user) from sys.dual");
                if (resultSet.next())
                    userName = resultSet.getString(1);
            } catch (SQLException e) {
                out.println("Login doGet() SQLException: " + e.getMessage() + "<p>");
            } finally {
                if (resultSet != null)
                    try {
                        resultSet.close();
                    } catch (SQLException ignore) {
                    }
                if (statement != null)
                    try {
                        statement.close();
                    } catch (SQLException ignore) {
                    }
            }
            out.println("Hello " + userName + "!<p>");
            out.println("Your session ID is " + session.getId() + "<p>");
            out.println("It was created on " + new java.util.Date(session.getCreationTime()) + "<p>");
            out.println("It was last accessed on " + new java.util.Date(session.getLastAccessedTime()) + "<p>");
            out.println("<form method=\"get\" action=\"SessionLogin\">");
            out.println("<input type=\"submit\" name=\"logout\" " + "value=\"Logout\">");
            out.println("</form>");
        } else {
            // close the connection and remove it from the session
            try {
                connection.close();
            } catch (SQLException ignore) {
            }
            session.removeAttribute("sessionconnection");
            out.println("You have been logged out.");
        }
    }
    out.println("</body>");
    out.println("</html>");
}