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:com.base.service.AdminService.java

public String login(String account, String password, String pageCode, String code, HttpSession session)
        throws Exception {
    JSONObject json = new JSONObject();
    try {//w w  w  . j  av  a2 s. c o  m
        if (!code.equals(pageCode.toUpperCase())) {
            CreateResJosnUtil.createjson(json, "err", "??");
            return json.toString();
        }
        List<Admin> list = this.adminDao.list("o.account=? ", account);
        if (list.size() == 0) {
            CreateResJosnUtil.createjson(json, "err", "???");
            return json.toString();
        }

        Admin admin = list.get(0);
        if (StringUtils.isEmpty(password) || !MD5.getMD5(password).equals(admin.getPassword())) {
            CreateResJosnUtil.createjson(json, "err", "???");
            return json.toString();
        }
        session.setAttribute("adminUser", admin);
        session.removeAttribute("code");
        CreateResJosnUtil.createjson(json, "success", "");
        return json.toString();
    } catch (Exception e) {
        throw e;
    }
}

From source file:mitm.djigzo.web.pages.portal.secure.Signup.java

private String getSavedTarget() {
    HttpSession session = requestGlobals.getHTTPServletRequest().getSession(false);

    if (session == null) {
        return null;
    }/* w  w  w  .  j  a v a2 s  .  co m*/

    /*
     * Get the saved request from the HTTP session
     */
    SavedRequest savedRequest = (SavedRequest) session
            .getAttribute(AbstractProcessingFilter.SPRING_SECURITY_SAVED_REQUEST_KEY);

    String target = null;

    if (savedRequest != null) {
        target = savedRequest.getFullRequestUrl();

        /*
         * Clear the saved request since we have handled it
         */
        session.removeAttribute(AbstractProcessingFilter.SPRING_SECURITY_SAVED_REQUEST_KEY);
    }

    return target;
}

From source file:com.skilrock.lms.web.loginMgmt.RolesInterceptor.java

public boolean isSessionValid(HttpSession session) {
    HttpSession sessionNew = null;//  w ww .  j  a v  a2s .c  o m
    ServletContext sc = ServletActionContext.getServletContext();
    Map currentUserSessionMap = (Map) sc.getAttribute("LOGGED_IN_USERS");
    UserInfoBean userBean = (UserInfoBean) session.getAttribute("USER_INFO");
    if (userBean == null) {

        return false;
    }
    if (currentUserSessionMap != null && userBean != null) {
        sessionNew = (HttpSession) currentUserSessionMap.get(userBean.getUserName());
    }
    // logger.debug("In Else If New is --"+sessionNew+" Session Current
    // --"+session);
    // logger.debug("The User in Map are"+currentUserSessionMap );
    if (sessionNew != null) {
        if (!sessionNew.equals(session)) {
            session.removeAttribute("USER_INFO");
            session.invalidate();
            session = null;
            return false;
        }
    }
    return true;

}

From source file:gov.nih.nci.caarray.web.action.vocabulary.VocabularyAction.java

/**
 * Action to list the terms in a given category.
 *
 * @return the string indicating which result to follow.
 *///from w ww.  j  a va  2 s .c o m
@SkipValidation
public String list() {
    if (Boolean
            .valueOf((String) ServletActionContext.getRequest().getSession().getAttribute("startWithEdit"))) {
        HttpSession session = ServletActionContext.getRequest().getSession();
        String returnProjectIdString = (String) session.getAttribute("returnProjectId");
        if (StringUtils.isNotBlank(returnProjectIdString)) {
            setReturnProjectId(Long.parseLong(returnProjectIdString));
        } else {
            setReturnProjectId(null);
        }
        setReturnInitialTab1((String) session.getAttribute("returnInitialTab1"));
        setReturnInitialTab2((String) session.getAttribute("returnInitialTab2"));
        setReturnInitialTab2Url((String) session.getAttribute("returnInitialTab2Url"));
        setReturnToProjectOnCompletion(true);
        session.removeAttribute("startWithEdit");
        session.removeAttribute("returnProjectId");
        session.removeAttribute("returnInitialTab1");
        session.removeAttribute("returnInitialTab2");
        session.removeAttribute("returnInitialTab2Url");
        return edit();
    }
    this.setTerms(VocabularyUtils.getTermsFromCategory(this.getCategory()));
    return SUCCESS;
}

From source file:gov.nih.nci.security.upt.actions.CommonDBAction.java

/**
* Added this method to handle pre-popup search results.
*//*from ww w .java2 s. co  m*/

public String loadOriginalSearchResult(BaseDBForm baseDBForm) throws Exception {
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpSession session = request.getSession();

    if (session.isNew() || (session.getAttribute(DisplayConstants.LOGIN_OBJECT) == null)) {
        if (logDB.isDebugEnabled())
            logDB.debug("||" + baseDBForm.getFormName()
                    + "|loadSearchResult|Failure|No Session or User Object Forwarding to the Login Page||");
        return ForwardConstants.LOGIN_PAGE;
    }

    if (session.getAttribute(DisplayConstants.CREATE_WORKFLOW) != null) {
        session.removeAttribute(DisplayConstants.CREATE_WORKFLOW);
        //session.removeAttribute(DisplayConstants.SEARCH_RESULT);
        return ForwardConstants.LOAD_HOME_SUCCESS;
    } else {
        if (session.getAttribute(DisplayConstants.ORIGINAL_SEARCH_RESULT) != null) {
            session.setAttribute(DisplayConstants.SEARCH_RESULT,
                    session.getAttribute(DisplayConstants.ORIGINAL_SEARCH_RESULT));
            session.removeAttribute(DisplayConstants.ORIGINAL_SEARCH_RESULT);
        }
    }

    if (logDB.isDebugEnabled())
        logDB.debug(session.getId() + "|"
                + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|"
                + baseDBForm.getFormName() + "|loadSearchResult|Success|Loading the Search Result Page||");
    return ForwardConstants.LOAD_SEARCH_RESULT_SUCCESS;
}

From source file:com.osafe.events.CheckOutEvents.java

public static String redeemMemberLoyaltyPoints(HttpServletRequest request, HttpServletResponse response) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
    ShoppingCart sc = org.ofbiz.order.shoppingcart.ShoppingCartEvents.getCartObject(request);
    String orderId = sc.getOrderId();
    HttpSession session = request.getSession();
    List orderAdjustmentAttributeList = (List) session.getAttribute("orderAdjustmentAttributeList");
    String result = "success";

    if (UtilValidate.isNotEmpty(orderId) && UtilValidate.isNotEmpty(orderAdjustmentAttributeList)) {
        //Call service to reduce user Loyatly points in Users Account
        Map serviceContext = FastMap.newInstance();
        serviceContext.put("orderId", orderId);
        serviceContext.put("orderAdjustmentAttributeList", orderAdjustmentAttributeList);
        try {//from www  . jav a 2  s.  co m
            dispatcher.runSync("redeemLoyaltyPoints", serviceContext);
        } catch (Exception e) {
            String errMsg = "Error attempting to redeem loyalty points :" + e.toString();
            Debug.logError(e, errMsg, module);
            return "error";
        }
        session.removeAttribute("orderAdjustmentAttributeList");
    }

    return "success";
}

From source file:com.jfinal.core.Controller.java

/**
 * Remove Object in session./* w w  w  .j  a  v  a2 s .  c om*/
 * @param key a String specifying the key of the Object stored in session
 */
public Controller removeSessionAttr(String key) {
    HttpSession session = request.getSession(false);
    if (session != null)
        session.removeAttribute(key);
    return this;
}

From source file:net.lightbody.bmp.proxy.jetty.servlet.SessionDump.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession session = request.getSession(false);
    String action = request.getParameter("Action");
    String name = request.getParameter("Name");
    String value = request.getParameter("Value");
    String age = request.getParameter("MaxAge");

    String nextUrl = getURI(request) + "?R=" + redirectCount++;
    if (action.equals("New Session")) {
        session = request.getSession(true);
    } else if (session != null) {
        if (action.equals("Invalidate"))
            session.invalidate();// w  w w.j av a  2  s.  com
        else if (action.equals("Set")) {
            session.setAttribute(name, value);
            try {
                int m = Integer.parseInt(age);
                session.setMaxInactiveInterval(m);
            } catch (Exception e) {
                LogSupport.ignore(log, e);
            }
        } else if (action.equals("Remove"))
            session.removeAttribute(name);
    }

    String encodedUrl = response.encodeRedirectURL(nextUrl);
    response.sendRedirect(encodedUrl);

}

From source file:cn.loveapple.service.controller.member.action.MemberController.java

/**
 * /*w w  w .j  a v  a  2  s.com*/
 * 
 * @param session
 * @param model
 * @return
 */
@RequestMapping(value = "registComplete", method = RequestMethod.POST)
public String registComplete(HttpSession session, HttpServletRequest request, Model model, Locale locale) {

    LoveappleMemberModel member = (LoveappleMemberModel) session.getAttribute(LOVEAPPLE_MEMBER_TMP);

    if (member == null) {
        try {
            throw new NoSuchRequestHandlingMethodException(request);
        } catch (NoSuchRequestHandlingMethodException e) {
            throw new HttpMessageNotWritableException(e.getMessage(), e);
        }
    }
    member = memberCoreService.insertLoveappleMember(member);
    if (member == null) {
        throw new HttpMessageNotWritableException("can not regist member. "
                + ToStringBuilder.reflectionToString(session.getAttribute(LOVEAPPLE_MEMBER_TMP)));
    }
    session.removeAttribute(FORM);
    session.removeAttribute(LOVEAPPLE_MEMBER_TMP);

    // ??
    try {
        MimeMessage message = memberCoreService.sendRegistCertificationMail(member);
        log.info("Send mail: " + ToStringBuilder.reflectionToString(message));
    } catch (MailException e) {
        log.warn("?", e);
    }

    return "redirect:/member/certification";
}

From source file:de.highbyte_le.weberknecht.security.filters.AuthenticationFilter.java

/**
 * do authentication, if parameters are present and check session for valid login
 * @return true, if the user is authenticated
 *///from  w  w w .ja v a  2  s .co m
protected boolean handleAuthentication(HttpServletRequest request) {
    HttpSession session = request.getSession();

    String reqUser = null;
    String reqPwd = null;
    String reqDoParam = null;

    //Erst prfen, ob Authentifizierungsversuch vorliegt, da es nach getParameter() nicht mehr mglich ist auf gepostete formulare zuzugreifen.
    String queryString = request.getQueryString();
    if (queryString != null && (queryString.contains(doParameter + "=auth")
            || queryString.contains(doParameter + "=signout"))) {
        // Get user id and password from request parameters
        reqUser = request.getParameter("user");
        reqPwd = request.getParameter("pwd");
        reqDoParam = request.getParameter(doParameter);
    }

    boolean success = false;

    // If user id and password are present, authenticate
    if (reqUser != null && reqPwd != null && reqDoParam != null && reqDoParam.equalsIgnoreCase("auth")) {
        session.removeAttribute("user_auth"); //first remove the previous login from session

        if (authentication != null) {
            Integer userId = authentication.authenticate(reqUser, reqPwd);
            if (userId != null) { //successful login
                session.setAttribute("user_auth", new UserAuthentication(userId, true));
                success = true;
            }
        } else {
            logger.fatal("handleAuthentication() - no Authenticator object set!");
        }
    } else if (reqDoParam != null && reqDoParam.equalsIgnoreCase("signout")) {
        session.removeAttribute("user_auth"); //remove the previous login from session
    } else { //use login information from session
        UserAuthentication userAuth = (UserAuthentication) session.getAttribute("user_auth");
        if (userAuth != null) {
            success = userAuth.isAuthenticated();
        }
    }

    return success;
}