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:nz.co.senanque.vaadinsupport.viewmanager.ViewManagerImpl.java

public void logout() {
    HttpSession httpSession = ((WebApplicationContext) getApplication().getContext()).getHttpSession();
    httpSession.invalidate();
    if (getMaduraSessionManager() != null) {
        getMaduraSessionManager().close();
    }//from   w w w .jav  a2s  .  co m
}

From source file:org.mifos.security.authentication.MifosLegacyUsernamePasswordAuthenticationFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {

    //LocaleContextHolder.setLocale(Localization.getInstance().getConfiguredLocale());

    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;
    AuthenticationException denied = null;

    boolean allowAuthenticationToContinue = true;
    if (MifosBatchJob.isBatchJobRunningThatRequiresExclusiveAccess()) {
        allowAuthenticationToContinue = false;

        HttpSession session = request.getSession(false);
        if (session != null) {
            session.invalidate();
        }/*from ww  w  .  ja v a2  s .com*/

        denied = new AuthenticationServiceException(messages.getMessage(LoginConstants.BATCH_JOB_RUNNING,
                "You have been logged out of the system because batch jobs are running."));
    }

    ShutdownManager shutdownManager = (ShutdownManager) ServletUtils.getGlobal(request,
            ShutdownManager.class.getName());
    if (shutdownManager.isShutdownDone()) {
        allowAuthenticationToContinue = false;
        request.getSession(false).invalidate();
        denied = new AuthenticationServiceException(messages.getMessage(LoginConstants.SHUTDOWN,
                "You have been logged out of the system because Mifos is shutting down."));
    }

    if (shutdownManager.isInShutdownCountdownNotificationThreshold()) {
        request.setAttribute("shutdownIsImminent", true);
    }

    if (allowAuthenticationToContinue) {
        super.doFilter(request, response, chain);
    } else {
        unsuccessfulAuthentication(request, response, denied);
    }
}

From source file:com.sfs.ucm.security.Authenticator.java

/**
 * logout action/*from  w w w.j  av  a 2s .  c  o  m*/
 */
public void logout() {
    HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext()
            .getSession(false);
    if (session != null) {
        session.setAttribute("USERID", null);
        session.invalidate();
    }
}

From source file:com.xtc.controller.AuthController.java

@RequestMapping({ "/auth/logout" })
public @ResponseBody Map<String, Object> layout(ModelMap map) {
    Map<String, Object> mapRtn = new HashMap<String, Object>();
    try {/*from   ww w . jav a  2 s  .  c  om*/
        HttpSession session = request.getSession();
        session.invalidate();
        mapRtn.put(RestDto.RESULT, session);
    } catch (Exception e) {
        System.out.println("");
    }
    return mapRtn;
}

From source file:ua.aits.crc.controller.SystemController.java

@RequestMapping(value = { "/system/do/logout", "/system/do/logout/" })
public ModelAndView logout(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request.setCharacterEncoding("UTF-8");
    HttpSession session = request.getSession(false);
    if (session != null) {
        session.invalidate();
    }//from w  ww . j  a v  a 2s. c  o m
    return new ModelAndView("redirect:" + "/system/login");
}

From source file:mx.com.quadrum.contratos.controller.service.user.ClientesController.java

@RequestMapping(value = "inicioCambioPasswordCliente", method = RequestMethod.POST)
public ModelAndView cambiarPassword(String password, HttpSession session) {
    Contacto contacto = (Contacto) session.getAttribute(CLIENTE);
    if (contacto == null) {
        session.invalidate();
        return new ModelAndView("templates/error", "error", "No se pudo cambiar el password");
    }/*from   www.j av a  2 s.c o m*/
    List<Contrato> contratos = contratoService.buscarPorContacto(contacto.getId());
    if (contactoService.cambiarPassword(contacto, password)) {
        return new ModelAndView("cliente/contratos", "contratos", contratos);
    }
    session.invalidate();
    return new ModelAndView("templates/error", "error", "No se pudo cambiar el password");
}

From source file:de.theit.jenkins.crowd.CrowdServletFilter.java

/**
 * {@inheritDoc}/*from   w  ww  .  ja va  2 s .co m*/
 * 
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
 *      javax.servlet.ServletResponse, javax.servlet.FilterChain)
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse res = (HttpServletResponse) response;

        // check if we have a token
        // if it is not present, we are not / no longer authenticated
        boolean isValidated = false;
        try {
            isValidated = this.configuration.crowdHttpAuthenticator.isAuthenticated(req, res);
        } catch (OperationFailedException ex) {
            LOG.log(Level.SEVERE, operationFailed(), ex);
        }

        if (!isValidated) {
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("User is not logged in (anymore) via Crowd => logout user");
            }
            SecurityContext sc = SecurityContextHolder.getContext();
            sc.setAuthentication(null);
            // close the SSO session
            if (null != this.rememberMe) {
                this.rememberMe.logout(req, res);
            }

            // invalidate the current session
            // (see SecurityRealm#doLogout())
            HttpSession session = req.getSession(false);
            if (session != null) {
                session.invalidate();
            }
            SecurityContextHolder.clearContext();

            // reset remember-me cookie
            Cookie cookie = new Cookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY, "");
            cookie.setPath(req.getContextPath().length() > 0 ? req.getContextPath() : "/");
            res.addCookie(cookie);
        } else {
            SecurityContext sc = SecurityContextHolder.getContext();

            if (!(sc.getAuthentication() instanceof CrowdAuthenticationToken)) {
                // user logged in via Crowd, but no Crowd-specific
                // authentication token available
                // => try to auto-login the user
                if (null != this.rememberMe) {
                    if (LOG.isLoggable(Level.FINE)) {
                        LOG.fine(
                                "User is logged in via Crowd, but no authentication token available; trying auto-login...");
                    }
                    Authentication auth = this.rememberMe.autoLogin(req, res);
                    if (null != auth) {
                        if (LOG.isLoggable(Level.FINE)) {
                            LOG.fine("User sucessfully logged in");
                        }
                        sc.setAuthentication(auth);
                    }
                }
            }
        }
    }

    this.defaultFilter.doFilter(request, response, chain);
}

From source file:org.wso2.carbon.core.services.util.CarbonAuthenticationUtil.java

public static void onFailedAdminLogin(HttpSession httpSess, String username, int tenantId, String tenantDomain,
        String remoteAddress, String reason) throws Exception {

    if (httpSess != null) {
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        carbonContext.setUsername(username);
        carbonContext.setTenantId(tenantId);
        if (tenantDomain == null) {
            tenantDomain = carbonContext.getTenantDomain(true);
        }// w  w w .j  av a  2  s  .c  o m
        carbonContext.setTenantDomain(tenantDomain);
    }

    Date currentTime = Calendar.getInstance().getTime();
    SimpleDateFormat date = new SimpleDateFormat("'['yyyy-MM-dd HH:mm:ss,SSSZ']'");

    String msg = "Failed Administrator login attempt \'" + username + "[" + tenantId + "]\' at "
            + date.format(currentTime);
    if (!CarbonUtils.isRunningOnLocalTransportMode()) {
        msg += " from IP address " + remoteAddress;
    }
    log.warn(msg);
    audit.warn(msg);

    if (httpSess != null) {
        httpSess.invalidate();
    }
    LoginAttempt loginAttempt = new LoginAttempt(username, tenantId, remoteAddress, new Date(), false, reason);
    LoginStatDatabase.recordLoginAttempt(loginAttempt);
}

From source file:org.wso2.carbon.apimgt.authenticator.oidc.ui.common.OIDCAuthenticationClient.java

public void logout(HttpSession session) throws AuthenticationException {
    try {/* w  w w. ja v  a 2  s . c  o m*/
        if (!CarbonUtils.isRunningOnLocalTransportMode()) {
            stub.logout();
        }
        session.removeAttribute(ServerConstants.ADMIN_SERVICE_AUTH_TOKEN);
        session.invalidate();
    } catch (java.lang.Exception e) {
        String msg = "Error occurred while logging out";
        log.error(msg, e);
        throw new AuthenticationException(msg, e);
    }
}

From source file:com.netpace.cms.sso.filter.AlfrescoOpenSSOFilter.java

private void doLogout(HttpSession httpSession, SSOToken token) {
    getOpenSSOClient().destroyToken(token);
    httpSession.invalidate();
}