Example usage for javax.servlet.http HttpSession invalidate

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

Introduction

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

Prototype

public void invalidate();

Source Link

Document

Invalidates this session then unbinds any objects bound to it.

Usage

From source file:org.opendaylight.controller.web.DaylightWeb.java

@RequestMapping(value = "logout")
public String logout(Map<String, Object> model, final HttpServletRequest request) {

    IUserManager userManager = (IUserManager) ServiceHelper.getGlobalInstance(IUserManager.class, this);
    if (userManager == null) {
        return "User Manager is not available";
    }/*from www.  j a v a 2  s.  c  o m*/
    String username = request.getUserPrincipal().getName();
    HttpSession session = request.getSession(false);
    if (session != null) {
        if (username != null) {
            userManager.userLogout(username);
        }
        session.invalidate();

    }
    return "redirect:" + "/";
}

From source file:pt.iflow.authentication.AuthWinUserServlet.java

static AuthenticationResult authenticate(final HttpServletRequest request, final HttpServletResponse response,
        final String username, final String password, final String nextUrl)
        throws ServletException, IOException {
    AuthenticationResult result = new AuthenticationResult();
    result.nextUrl = nextUrl;//from   ww  w .  jav a 2s .  c om

    HttpSession session = request.getSession();

    Boolean bIsSystem = (Boolean) session.getAttribute(ADMIN_SESSION_NAME);
    boolean isSystem = false;

    if (bIsSystem != null)
        isSystem = bIsSystem.booleanValue();

    String login = Utils.decrypt(username);
    String pass = Utils.decrypt(password);

    if (login != null) {
        login = login.trim();
    }

    boolean licenseOk = LicenseServiceFactory.getLicenseService().isLicenseOK();

    AuthProfile ap = BeanFactory.getAuthProfileBean();

    UserInfoInterface ui = null;

    if (isSystem)
        ui = BeanFactory.getUserInfoFactory().newSystemUserInfo();
    else
        ui = BeanFactory.getUserInfoFactory().newUserInfo();

    Hashtable<String, String> cookies = ServletUtils.getCookies(request);
    if (cookies != null) {
        ui.setCookieLang(cookies.get(Const.LANG_COOKIE));
    }

    ui.login(login, pass);

    // check license status
    if (!licenseOk && !isSystem) {
        result.nextUrl = "Admin/login.jsp";
        session.invalidate();
        return result;
    }

    boolean isAuth = result.isAuth = ui.isLogged();

    if (isAuth) {

        /////////////////////////////
        //
        // Now set some session vars
        //
        /////////////////////////////

        //Application Data
        session.setAttribute("login", login);

        session.setAttribute(Const.USER_INFO, ui);
        UserSettings settings = ui.getUserSettings();
        OrganizationData orgData = ap.getOrganizationInfo(ui.getOrganization());
        session.setAttribute(Const.ORG_INFO, orgData);

        OrganizationTheme orgTheme = BeanFactory.getOrganizationThemeBean();
        if (orgTheme != null) {
            OrganizationThemeData themeData = orgTheme.getOrganizationTheme(ui);
            session.setAttribute("themedata", themeData);
        }

        if (ui.isPasswordExpired()) {
            result.nextUrl = "changePassword";
        }

        if (!isSystem && settings.isDefault() && Const.USE_INDIVIDUAL_LOCALE && Const.ASK_LOCALE_AT_LOGIN) {
            result.nextUrl = "setupUser";
        }

        // check license status
        if (!licenseOk && isSystem) {
            result.nextUrl = "Admin/licenseValidation.jsp";
        }

        session.setAttribute("SessionHelperToken", new SimpleSessionHelper());

    } else {
        result.nextUrl = "main.jsp";
        result.errorMsg = ui.getError();
        session.setAttribute("login_error", result.errorMsg);
    }
    PersistSession ps = new PersistSession();
    ps.getSession(ui, session);

    response.sendRedirect(response.encodeRedirectURL("main.jsp"));

    return result;
}

From source file:ke.co.tawi.babblesms.server.servlet.accountmngmt.Login.java

/**
 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *///from w w w. ja v a2  s. c  o  m
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    HttpSession session = request.getSession(false);

    if (session != null) {
        session.invalidate(); // This is in case the user had previously signed
        // in and his/her session is still active.
    }

    session = request.getSession(true);

    Account account = new Account();
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    String gRecaptchaResponse = request.getParameter("g-recaptcha-response");

    // hiddenCaptchaStr = request.getParameter("captchaHidden");
    // String captchaAnswer = request.getParameter("captchaAnswer").trim();

    Element element;
    if ((element = accountsCache.get(username)) != null) {
        account = (Account) element.getObjectValue();
    }

    if (account != null) {
        // Check that the system generated captcha and the user input for the captcha match            
        if (validateCaptcha(gRecaptchaResponse) == false) {
            session.setAttribute(SessionConstants.ACCOUNT_SIGN_IN_ERROR_KEY, ACCOUNT_SIGN_IN_BAD_CAPTCHA);
            response.sendRedirect("index.jsp");

        } else {
            // Correct login
            if (StringUtils.equals(SecurityUtil.getMD5Hash(password), account.getLogpassword())) {
                updateCache(account.getUuid());
                session.setAttribute(SessionConstants.ACCOUNT_SIGN_IN_ACCOUNTUUID, account.getUuid());
                session.setAttribute(SessionConstants.ACCOUNT_SIGN_IN_KEY, username);

                session.setAttribute(SessionConstants.ACCOUNT_SIGN_IN_TIME,
                        String.valueOf(new Date().getTime()));

                response.sendRedirect("account/inbox.jsp");

                // Incorrect login, password not matching   
            } else {
                session.setAttribute(SessionConstants.ACCOUNT_SIGN_IN_ERROR_KEY,
                        SessionConstants.ACCOUNT_SIGN_IN_WRONG_PASSWORD);
                response.sendRedirect("index.jsp");
            }
        }

        // This is also an incorrect login whereby the username does not exist.   
    } else { // end 'if(account != null)'
        session.setAttribute(SessionConstants.ACCOUNT_SIGN_IN_ERROR_KEY,
                SessionConstants.ACCOUNT_SIGN_IN_NO_EMAIL);
        response.sendRedirect("index.jsp");
    }
}

From source file:pivotal.au.se.gemfirexdweb.controller.LogoutController.java

@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String logout(Model model, HttpSession session, HttpServletResponse response, HttpServletRequest request)
        throws Exception {
    logger.debug("Received request to logout of GemFireXD*Web");

    // remove connection from list
    ConnectionManager cm = ConnectionManager.getInstance();
    cm.removeConnection(session.getId());

    session.invalidate();

    Login login = new Login();
    login.setUrl("jdbc:gemfirexd://localhost:1527/");

    model.addAttribute("loginAttribute", login);
    // This will resolve to /WEB-INF/jsp/loginpage.jsp
    return "loginpage";

    //response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
    //return null;
}

From source file:com.andco.salasucc.bean.nuevaBean.java

public String cerrarSesion() {
    HttpSession session = Util.getSession();
    session.invalidate();
    return "index";
}

From source file:com.wtr.ui.action.Login.java

public String displayLogin() {
    logger.debug("Login: displayLogin()");
    logger.debug(getText("loginpageup"));
    //invalidate the current session if any
    HttpSession session = request.getSession(false);
    logger.debug("session is " + session);
    if (session != null) {
        session.invalidate();
        session = null;//from w ww  .  j  av a 2  s .c  om
        logger.debug("session invalidate complete");
    }
    return "success";
}

From source file:managedbeans.UsuarioController.java

public UsuarioController() {
    HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext()
            .getSession(false);/*from w  w w  .ja v a2  s.  com*/
    if (session != null) {
        session.invalidate();
    }
}

From source file:org.eurekaclinical.user.webapp.servlet.filter.UserFilter.java

@Override
public void doFilter(ServletRequest inRequest, ServletResponse inResponse, FilterChain inFilterChain)
        throws IOException, ServletException {

    HttpServletRequest servletRequest = (HttpServletRequest) inRequest;
    HttpServletResponse servletResponse = (HttpServletResponse) inResponse;

    String remoteUser = servletRequest.getRemoteUser();

    inRequest.setAttribute(RequestAttributes.Eureka_Webapp_URL, this.properties.getEurekaWebappUrl());
    inRequest.setAttribute(RequestAttributes.Eureka_Services_URL, this.properties.getEurekaServicesUrl());

    if (!StringUtils.isEmpty(remoteUser)) {
        try {/*from   ww w . ja  va2 s . c  om*/
            HttpSession session = servletRequest.getSession(false);
            if (session != null) {
                User user = this.servicesClient.getMe();
                if (!user.isActive()) {
                    session.invalidate();
                    sendForbiddenError(servletResponse, servletRequest, true);
                } else {
                    inRequest.setAttribute(RequestAttributes.USER, user);
                    inRequest.setAttribute(RequestAttributes.USER_IS_ACTIVATED, user.isActive());
                    inFilterChain.doFilter(inRequest, inResponse);
                }
            } else {
                goHome(servletRequest, servletResponse);
            }
        } catch (ClientException ex) {
            if (null != ex.getResponseStatus()) {
                switch (ex.getResponseStatus()) {
                case FORBIDDEN: {
                    HttpSession session = servletRequest.getSession(false);
                    if (session != null) {
                        session.invalidate();
                    }
                    sendForbiddenError(servletResponse, servletRequest, false);
                    break;
                }
                case UNAUTHORIZED: {
                    HttpSession session = servletRequest.getSession(false);
                    if (session != null) {
                        session.invalidate();
                    }
                    goHome(servletRequest, servletResponse);
                    break;
                }
                default:
                    throw new ServletException("Error getting user " + servletRequest.getRemoteUser(), ex);
                }
            }
        }
    } else {
        inFilterChain.doFilter(inRequest, inResponse);
    }
}

From source file:com.sct.descubriendoturuta.controller.HomeController.java

/**
 * Metodo para eliminar la sesin de facebook.
 * /*from  ww  w.j  a  v a 2s  .  c  o  m*/
 * @param session
 * @return
 */
@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String logout(HttpSession session) {
    session.invalidate();
    return "redirect:/";
}

From source file:fina.usuario.servlet.usuarioServlet.java

private void cerrarSesion(HttpServletRequest request, HttpServletResponse response) {
    HttpSession session = request.getSession(true);
    session.invalidate();
    try {/*  ww w.jav  a 2 s. c  o m*/
        response.sendRedirect("index.jsp");
    } catch (Exception e) {
    }
}