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.leapfrog.springFramework.Controller.LoginController.java

@RequestMapping(value = "/loggedIn", method = RequestMethod.POST)
public String LoginUser(@RequestParam Map<String, String> parVal, HttpServletRequest request) {
    ModelAndView mv = new ModelAndView();
    String username = parVal.get("username");
    String password = parVal.get("password");

    User user = dao.checkUsername(username, password);
    if (user != null) {

        HttpSession session = request.getSession(true);
        session.setAttribute("USER", user);
        session.setAttribute("user", user.getUsername());
        session.setAttribute("ROLE", user.getRole());

        //To remove login msg from discuss forum
        session.removeAttribute("loginMsg");
        return "redirect:" + "/user";
    }/* w ww . j a v  a2 s .co m*/
    return "redirect:" + "/userlogin";
}

From source file:com.pureinfo.tgirls.sns.servlet.SNSEntryServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    logger.debug("tgirls sns entry.");

    String taobaoUserId = null;/*from   w w w.jav  a  2  s  . c om*/
    String taobaoUserName = null;

    String topSession = request.getParameter(APPConstants.REQ_PARAMETER_SESSION);
    String topParameters = request.getParameter(APPConstants.REQ_PARAMETER_PARAMETERS);
    String topSign = request.getParameter(APPConstants.REQ_PARAMETER_SIGN);

    TipBean tb = null;
    try {
        tb = TipUtil.beforeFetch(topSession, topParameters, topSign, APPConstants.SECRET);
        if (!tb.isOk()) {
            logger.error("top api failed." + tb.getErrMsg());

            throw new Exception("TOP API failed:" + tb.getErrMsg());
        }
        taobaoUserId = tb.getUserId() + "";
        taobaoUserName = tb.getUserNick();

        logger.debug("id:" + taobaoUserId);
        logger.debug("name:" + taobaoUserName);
        logger.debug("session:" + topSession);

        if ("0".equals(taobaoUserId) || StringUtils.isEmpty(taobaoUserId)
                || StringUtils.isEmpty(taobaoUserName)) {
            throw new Exception("parameter empty.");
        }
    } catch (Exception e) {
        logger.error("error when call top API.", e);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "top system error." + e.getMessage());
        return;
    }

    HttpSession session = request.getSession(true);
    session.removeAttribute(ArkHelper.ATTR_LOGIN_USER);
    User loginUser = null;//(User) session.getAttribute(ArkHelper.ATTR_LOGIN_USER);
    //loginUser = CookieUtils.getLoginUser(request, response);

    if (loginUser != null && loginUser.getTaobaoID().equals(taobaoUserId)) {

        logger.debug("user " + taobaoUserId + " already logined.");

    } else {
        try {
            userMgr = (IUserMgr) ArkContentHelper.getContentMgrOf(User.class);
            if (!userMgr.isUserExists(taobaoUserId)) {
                loginUser = createUser(taobaoUserId, topSession);
                //ScriptWriteUtils.reBuildUserInfoScript(loginUser);
                try {
                    //ScriptWriteUtils.reBuildUserBuyPhotosScript(loginUser);
                    //ScriptWriteUtils.reBuildUserUploadPhotosScript(loginUser);
                } catch (Exception e) {
                    logger.error("error when rebuild buy and upload scripts.", e);
                }
            } else {
                loginUser = userMgr.getUserByTaobaoId(taobaoUserId);
            }
        } catch (PureException e) {
            logger.error("tgirls system error.", e);
            response.sendError(HttpServletResponse.SC_BAD_GATEWAY, "tgirls system error." + e.getMessage());
            return;
        } catch (NumberFormatException e) {
            logger.error("number format error.", e);
            response.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
            return;
        } catch (TaobaoApiException e) {
            logger.error("top system error.", e);
            response.sendError(HttpServletResponse.SC_BAD_GATEWAY, "top system error." + e.getMessage());
            return;
        }
    }

    if (loginUser == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "can not find current user.");
        return;
    }

    if (loginUser.getFunds() <= UserConstants.DISUSE_FUNDS
            || loginUser.getAssets() <= UserConstants.DISUSE_ASSETS) {
        response.sendRedirect(request.getContextPath() + "/disable.html");
        return;
    }

    updateUserHeadImg(loginUser, topSession);

    session.setAttribute(ArkHelper.ATTR_LOGIN_USER, loginUser);
    session.setAttribute(SessionConstants.TAOBAO_SESSION_ID, topSession);
    LocalContextHelper.setAttribute(SessionConstants.TAOBAO_SESSION_ID, topSession);

    addCookie(loginUser, request, response);

    //        System.out.println("========================");
    //        
    //        
    //       Cookie[] cs = request.getCookies();
    //        for (int i = 0; i < cs.length; i++) {
    //            Cookie c = cs[i];
    //            System.out.println("cookie[" + c.getName() + "]:" + c.getValue());
    //        }
    //        
    RequestDispatcher rd = request.getRequestDispatcher("/index.html");
    rd.forward(request, response);
    //response.sendRedirect(request.getContextPath());

    return;
}

From source file:com.gian.controller.SecurityController.java

@RequestMapping(value = "login", method = RequestMethod.POST)
public ModelAndView login(HttpServletRequest request, @RequestParam String login,
        @RequestParam String password) {

    ModelAndView mv = null;/*from ww  w .j a  va2  s .c  om*/
    boolean b = userService.loginUser(login, password);

    if (b == true) {

        //Create a session variable for login

        HttpSession stateSession = request.getSession(true);
        stateSession.setAttribute("id", "logged");

        _log.info("Start Login Session!");
        mv = new ModelAndView("home");
        mv.addObject("user", login);

    } else {

        HttpSession stateSession = request.getSession();
        stateSession.removeAttribute("id");

        _log.info("Login Failed!");
        mv = new ModelAndView("index");
        mv.addObject("messageFromController", "Login Failed!");
    }

    return mv;

}

From source file:com.lewischooman.services.CustomerSrv.java

@Override
public boolean login(HttpSession httpSession, String uid, String password) {
    CustomerDB customer = this.customerDAO.getUserbyEmailId(uid);
    if (customer != null && this.digester.digestToHex(password).equals(customer.getPassword())) {
        httpSession.setAttribute(Utility.LOGGED_IN_USER_ATTRIBUTE, customer);
        return true;
    } else {/*from  ww w  .  ja  v a 2 s  .c  o m*/
        httpSession.removeAttribute(Utility.LOGGED_IN_USER_ATTRIBUTE);
        return false;
    }
}

From source file:org.duracloud.account.app.controller.AccountGroupsController.java

@RequestMapping(value = GROUP_EDIT_PATH, method = RequestMethod.GET)
public String editGroup(@PathVariable Long accountId, @PathVariable String groupName,
        HttpServletRequest request, Model model) throws Exception {

    AccountService as = getAccountService(accountId);

    List<DuracloudGroup> groups = getGroups(accountId);
    addGroupsObjectsToModel(as, groups, model);

    DuracloudGroup group = getGroup(groupName, groups);
    addGroupToModel(group, model);//  www  .  ja v  a2 s  . c o m

    model.addAttribute(GROUP_FORM_KEY, new GroupForm());
    Set<DuracloudUser> groupUsers = group.getUsers();

    addAvailableUsersToModel(as, groupUsers, model);
    HttpSession session = request.getSession();
    session.removeAttribute(GROUP_USERS_KEY);
    addGroupUsersIfNotAlreadyInSession(group, model, session);
    return GROUP_EDIT_VIEW_ID;
}

From source file:com.toft.widgets.login.LoginAction.java

/**
 * session?//  www.j a  v  a  2  s.  co m
 */
public String logout() {
    //LicenseListener.logout(this.getRequest().getSession());
    HttpSession session = this.getRequest().getSession();
    if (session != null) {
        session.removeAttribute("userNumber");
        session.invalidate();
    }

    return SUCCESS;
}

From source file:fr.paris.lutece.portal.service.admin.AdminAuthenticationService.java

/**
 * Unregister the user in the Http session
 * @param request The Http request//from  w  w  w  .  j a  va  2 s  .  c o m
 */
public void unregisterUser(HttpServletRequest request) {
    HttpSession session = request.getSession(true);
    session.removeAttribute(ATTRIBUTE_ADMIN_USER);
}

From source file:com.opencnc.controllers.UsuarioController.java

/**
 * *****************************************************************************
 * Hace el Logout.//from   w  w  w .j  av a2 s  .c o  m
 * *****************************************************************************
 * Metodo aun le fata desarrollo para algunas vistas, solo implementado para el
 * index.jsp
 * *****************************************************************************
 * @param request
 * @param response
 * @return
 * @throws IOException 
 */
@RequestMapping("/usuario/logout")
public ModelAndView logout(HttpServletRequest request, HttpServletResponse response) throws IOException {
    HttpSession sess = request.getSession();
    if (sess != null) {
        sess.removeAttribute("usuario");
        return new ModelAndView("redirect:/usuario/login.htm");
    } else {
        return new ModelAndView("redirect:/usuario/login.htm");
    }
}

From source file:nl.strohalm.cyclos.controls.access.LoginAction.java

/**
 * Logins the user and returns a forward to the next action
 *///w  w  w  .  j av a 2s. co m
protected ActionForward doLogin(final ActionMapping mapping, final HttpServletRequest request,
        final HttpServletResponse response, final LoginForm form) {
    final String member = StringUtils.trimToNull(form.getMember());
    final String principal = StringUtils.trimToNull(form.getPrincipal());
    final String password = form.getPassword();
    final String errorReturnTo = resolveErrorReturnTo(mapping, request, response, form);
    final HttpSession session = request.getSession();
    if (errorReturnTo == null) {
        session.removeAttribute("errorReturnTo");
        session.setAttribute("forceBack", true);
    } else {
        session.setAttribute("errorReturnTo", errorReturnTo);
    }
    try {
        final Class<? extends User> requiredUserType = requiredUserType(mapping, request, response, form);
        final User user = loginHelper.login(requiredUserType, form.getPrincipalType(), member, principal,
                password, Channel.WEB, request, response);
        return loginForward(mapping, request, response, form, user);
    } catch (final BlockedCredentialsException e) {
        return ActionHelper.sendError(mapping, request, response, "login.error.blocked");
    } catch (final InactiveMemberException e) {
        return ActionHelper.sendError(mapping, request, response, "login.error.inactive");
    } catch (final AlreadyConnectedException e) {
        return ActionHelper.sendError(mapping, request, response, "login.error.alreadyConnected");
    } catch (final AccessDeniedException e) {
        return ActionHelper.sendError(mapping, request, response, "error.accessDenied");
    } catch (final PermissionDeniedException e) {
        return ActionHelper.sendError(mapping, request, response, "error.accessDenied");
    } catch (final SystemOfflineException e) {
        return ActionHelper.sendError(mapping, request, response, "error.systemOffline");
    } catch (final LoginException e) {
        return ActionHelper.sendError(mapping, request, response, "login.error");
    }
}

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

/**
 * //from  w  ww .jav  a  2s . c o m
 * @param session
 * @return
 */
@RequestMapping(value = "logout")
public String logout(HttpSession session) {
    if (hasAttributeInSession(session, LOVEAPPLE_MEMBER)) {
        session.removeAttribute(LOVEAPPLE_MEMBER);
    }
    return "redirect:/";
}