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:com.iLabs.spice.handler.LoginHandler.java

/**
 * This function is called when user logs out from the system.
 * It invalidates the session info./*from w w w  .jav a  2 s.  co m*/
 * 
 * @return String "success" is returned which determines the navigation. User is redirected to login page.
 * @throws IOException 
 * @throws SQLException 
 * @throws ClassNotFoundException 
 */
public String logout() throws IOException, ClassNotFoundException, SQLException {
    ProfileBean profileBean = (ProfileBean) getSessionScope().get("currentProfile");
    UserAuth userAuth = profileBean.getUserAuth();
    //String s = userAuth.getProfile().getProfileURL();
    int Q = userAuth.getProfile().getUserId();
    DatabaseConnector r = new DatabaseConnector();
    String s = r.Read(Q);
    System.out.println("Closing Session: " + s);
    ClientResource clientResource = new ClientResource("http://192.168.1.41:8180/sessions/" + s);
    clientResource.delete();
    r.DELETE(Q);

    HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext()
            .getSession(false);
    session.invalidate();

    return "success";

}

From source file:it.govpay.web.rs.BaseRsService.java

public void invalidateSession(Logger log) {
    if (log != null)
        log.info("Invalidate Session in corso...");

    HttpSession session = this.request.getSession(false);
    if (session != null) {
        session.invalidate();
    }//from w  ww  .  j  av  a2s  .c  om

    if (log != null)
        log.info("Invalidate Session completata.");
}

From source file:leon.ssi.util.session.AppSessionListener.java

public void sessionDestroyed(HttpSessionEvent se) {
    try {// w w w .  j av  a2  s . c  o m
        HttpSession session = se.getSession();
        String userId = "";
        UserSessionInfo userSession = null;
        try {
            userSession = (UserSessionInfo) session.getAttribute("UserSessionInfo");
            session.removeAttribute("UserSessionInfo");
        } catch (Exception sex) {
        }
        session.invalidate();
        logger.info("session destroy");
    } catch (Exception e) {

    }
}

From source file:org.qualipso.factory.ui.core.login.server.LoginServletImpl.java

/**
 * Log out from the session.//  ww w .  j  a  va2  s . co  m
 * 
 * @see org.qualipso.factory.ui.core.login.client.LoginServlet#logout()
 */
public void logout() {
    HttpSession session = getThreadLocalRequest().getSession(false);
    if (session != null) {
        session.removeAttribute(USERNAME_SESSION_ATTRIBUTE);
        session.removeAttribute(PASSWORD_SESSION_ATTRIBUTE);
        session.invalidate();
    }
}

From source file:org.opencms.jsp.CmsJspLoginBean.java

/**
 * Logs a user out, i.e. destroys the current users session,
 * after that the current page will be redirected to itself one time to ensure that
 * the users session is truly destroyed.<p>
 * //from w  w  w.j av  a2  s  . c  o m
 * @throws IOException if redirect after logout fails
 */
public void logout() throws IOException {

    HttpSession session = getRequest().getSession(false);
    if (session != null) {
        session.invalidate();
    }
    // logout was successful
    if (LOG.isInfoEnabled()) {
        LOG.info(Messages.get().getBundle().key(Messages.LOG_LOGOUT_SUCCESFUL_3,
                getRequestContext().getCurrentUser().getName(),
                getRequestContext().addSiteRoot(getRequestContext().getUri()),
                getRequestContext().getRemoteAddress()));
    }
    getResponse().sendRedirect(getFormLink());
}

From source file:com.launchkey.example.springmvc.DemoController.java

@RequestMapping(value = "/authorized", method = RequestMethod.POST, produces = "application/json")
@ResponseBody/* w  w  w  .j  a  va 2s . c  o m*/
public HttpEntity<Authorized> authorized(HttpSession session) throws AuthManager.AuthException {
    Authorized authorized = new Authorized();
    try {
        authorized.authorized = (authManager.isAuthorized() == true);
    } catch (AuthManager.AuthException e) {
        authorized.authorized = false;
    }
    if (!authorized.authorized) {
        session.invalidate();
    }
    return new ResponseEntity<Authorized>(authorized, HttpStatus.OK);
}

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

@RequestMapping(value = { "/Sdolyna/system/logout.do", "/system/logout.do", "/Sdolyna/system/logout.do/",
        "/system/logout.do/" })
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 ava2  s.  c  o  m
    return new ModelAndView("redirect:" + "/system/login");
}

From source file:org.esgf.globusonline.GOauthView1Controller.java

@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.POST)
public ModelAndView doPost(final HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    //grab the dataset name, file names and urls from the query string
    String dataset_name = request.getParameter("id");
    String[] file_names = request.getParameterValues("child_id");
    String[] file_urls = request.getParameterValues("child_url");
    String esg_user = "";
    String esg_password = "";
    //String e;// ww  w  . ja  v  a 2  s .  co m
    //grab the credential string
    String credential = request.getParameter("credential");
    System.out.println("Starting GlobusOnline workflow");
    //System.out.println("\n\n\n\t\tGO Credential " + credential + "\n\n\n");

    StringBuffer currentURL = request.getRequestURL();
    String currentURI = request.getRequestURI();
    //System.out.println("current URL is: " + currentURL);
    //System.out.println("current URI is: " + currentURI);
    //System.out.println("index is: " + currentURL.lastIndexOf(currentURI));
    String BaseURL = currentURL.substring(0, currentURL.lastIndexOf(currentURI));
    //System.out.println("BaseURL string is: " + BaseURL );

    //Instantiate model object:
    Map<String, Object> model = new HashMap<String, Object>();

    //Bail out if no gsiftp URLs are in file_names
    if (file_names != null) {
        for (int i = 0; i < file_names.length; i++) {
            if (!(file_urls[i] == null) && (file_urls[i].contains("gsiftp"))) {
                break;
            } else {
                model.put(GOFORMVIEW_ERROR, "error");
                String error_msg = "Selected dataset " + dataset_name
                        + " contains no GridFTP URLS, and cannot be transferred with this transfer method.";
                model.put(GOFORMVIEW_ERROR_MSG, error_msg);
                return new ModelAndView("goauthview3", model);
            }
        }
    } else {
        System.out.println("file_urls itself was null\n");
        model.put(GOFORMVIEW_ERROR, "error");
        String error_msg = "Selected dataset(s) " + dataset_name
                + " contain no GridFTP URLS, and cannot be transferred with this transfer method.";
        model.put(GOFORMVIEW_ERROR_MSG, error_msg);
        return new ModelAndView("goauthview3", model);
    }
    //Create a session if it doesn't already exist, so we can save state.
    HttpSession session = request.getSession(true);
    if (session.isNew() == false) {
        session.invalidate();
        session = request.getSession(true);
    }

    //System.out.println("Auth1, session id is:" + session.getId());

    session.setAttribute("fileUrls", file_urls);
    session.setAttribute("fileNames", file_names);
    session.setAttribute("datasetName", dataset_name);
    session.setAttribute("baseurl", BaseURL);
    if (!(credential == null)) {
        session.setAttribute("usercertificatefile", credential);
    }

    Cookie[] cookies = request.getCookies();
    String openId = "";

    for (int i = 0; i < cookies.length; i++) {
        if (cookies[i].getName().equals("esgf.idp.cookie")) {
            openId = cookies[i].getValue();
        }
    }

    LOG.debug("Got User OpenID: " + openId);
    // Create the client
    Properties GOProperties = getGOProperties();
    String PortalID = (String) GOProperties.getProperty("GOesgfPortalID", "bogususer");
    String PortalPass = (String) GOProperties.getProperty("GOesgfPortalPassword", "boguspassword");

    String loginUri = "";
    try {
        GoauthClient cli = new GoauthClient("nexus.api.globusonline.org", "globusonline.org", PortalID,
                PortalPass);
        cli.setIgnoreCertErrors(true);

        // Redirect the user agent to the globusonline log in page
        loginUri = cli.getLoginUrl(response.encodeURL(BaseURL + "/esgf-web-fe/goauthview2"));

    } catch (NexusClientException e) {
        System.out.println("ERROR:  GOesgfPortalID and/or GOesgfPortalPassword wrong or not set.");
        //            e.printStackTrace();
        model.put(GOFORMVIEW_ERROR, "error");
        String error_msg = "GlobusOnline Configuration file not found. Please create /esg/config/globusonline.properties and populate it with GOesgfPortalID and GOesgfPortalPassword";
        model.put(GOFORMVIEW_ERROR_MSG, error_msg);
        return new ModelAndView("goauthview3", model);
    }
    String myproxyServerStr = null;

    return new ModelAndView("redirect:" + loginUri, model);
}

From source file:com.betel.flowers.web.bean.CredencialBean.java

public void logout(ActionEvent event) {
    String url = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath()
            + "/faces/index.xhtml";
    RequestContext context = RequestContext.getCurrentInstance();
    FacesContext facesContext = FacesContext.getCurrentInstance();
    HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false);
    session.removeAttribute(this.userSession.getUsername());
    session.invalidate();
    this.init();/*from   ww w  .j av  a  2  s .co m*/
    context.addCallbackParam("loggerOut", true);
    context.addCallbackParam("ruta", url);
}

From source file:com.jaspersoft.jasperserver.war.control.JSCommonController.java

public ModelAndView logout(HttpServletRequest req, HttpServletResponse res) throws ServletException {
    // invalidate session
    HttpSession session = req.getSession(false);
    if (session != null) {
        session.invalidate();
    }/*  w w w .  ja v a 2s.c  o m*/

    //Determine if the user logging out is internal.  If it is, logout to the internal JRS logout url.
    //If the user is external, logout to the url defined in ExternalAuthProperties bean (app context)
    boolean loggedinUserIsExternal = false;
    final Authentication authObj = SecurityContextHolder.getContext().getAuthentication();
    Object principal = authObj.getPrincipal();
    if (principal instanceof MetadataUserDetails) {
        loggedinUserIsExternal = ((MetadataUserDetails) principal).isExternallyDefined();
    }

    // we aren't using RememberMe but this is how we'd log out if we did
    // Cookie terminate = new Cookie(TokenBasedRememberMeServices.ACEGI_SECURITY_HASHED_REMEMBER_ME_COOKIE_KEY, null);
    // terminate.setMaxAge(0);
    // res.addCookie(terminate);
    SecurityContextHolder.clearContext(); //invalidate authentication

    ExternalAuthProperties externalAuthProperties = getExternalAuthPropertiesBean();
    String externalLogoutUrl = (externalAuthProperties != null ? externalAuthProperties.getLogoutUrl() : null);
    if (loggedinUserIsExternal && externalLogoutUrl != null && externalLogoutUrl.length() > 0) {
        return new ModelAndView("redirect:" + externalLogoutUrl);
    } else {
        return new ModelAndView(
                "redirect:/login.html" + "?" + "showPasswordChange=" + req.getParameter("showPasswordChange"));
    }
}