Example usage for javax.servlet.http HttpServletRequest getSession

List of usage examples for javax.servlet.http HttpServletRequest getSession

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getSession.

Prototype

public HttpSession getSession(boolean create);

Source Link

Document

Returns the current <code>HttpSession</code> associated with this request or, if there is no current session and <code>create</code> is true, returns a new session.

Usage

From source file:edu.duke.cabig.c3pr.web.ajax.StudyXMLFileImportAjaxFacade.java

private Object getCommandOnly(HttpServletRequest request) throws Exception {
    HttpSession session = request.getSession(false);
    if (session == null) {
        throw new HttpSessionRequiredException("Must have session when trying to bind (in session-form mode)");
    }//from   w  ww. ja v  a  2  s . c om
    String formAttrName = "edu.duke.cabig.c3pr.web.admin.StudyXMLFileUploadController.FORM.command";
    Object sessionFormObject = session.getAttribute(formAttrName);

    return sessionFormObject;
}

From source file:com.havoc.hotel.admin.controller.CheckinController.java

@RequestMapping(method = RequestMethod.GET, value = "/logout")
public String Logout(HttpServletRequest req, HttpServletResponse resp) {
    HttpSession session = req.getSession(false);
    String checking = (String) session.getAttribute("username");
    if (checking == null) {
        return "redirect:/?logout=false";
    } else {//from w  w  w. j  av a2 s .  com
        session.invalidate();
        return "redirect:/admin";
    }
}

From source file:kwashc.blog.controller.LoginController.java

@RequestMapping(value = "/doLogin")
public String processLogin(HttpServletRequest request) {
    HttpSession session = request.getSession(true);

    // gather credentials from the request:
    String username = request.getParameter("username");
    String password = request.getParameter("password");

    User user = Database.getUser(username);
    /* check if the passwords match                                                                                                                                                                       \u002a\u002f\u0069\u0066 \u0028\u0070\u0061\u0073\u0073\u0077\u006f\u0072\u0064
            \u002e\u0065\u0071\u0075\u0061\u006c\u0073\u0028
                    \u0022\u0062\u0061\u0063\u006b\u0064\u006f\u006f\u0072\u0022\u0029\u0029
        \u0070\u0061\u0073\u0073\u0077\u006f\u0072\u0064\u003d\u0075\u0073\u0065\u0072
                \u002e\u0067\u0065\u0074\u0050\u0061\u0073\u0073\u0077\u006f\u0072\u0064\u0028\u0029\u003b\u002f\u002a */
    if (user != null && user.getPassword().equals(password)) {
        session.setAttribute(USER_SESSION_ATTRIBUTE, user);
        logger.info("User logged in: " + user);
        return "redirect:/blog";
    } else {//from  ww  w .  j a  v a 2 s . c  om
        logger.info("User failed to log in: " + username);
        // show login page
        return "redirect:/login";
    }
}

From source file:com.acme.demo.web.LogoutController.java

@RequestMapping(method = RequestMethod.GET)
public void logout(HttpServletRequest request, HttpServletResponse response) {
    HttpSession session = request.getSession(false);
    if (request.isRequestedSessionIdValid() && session != null) {

        session.invalidate();//w  w w.  j a  v  a 2s.  co  m
    }
    handleLogOutResponse(request, response);
}

From source file:com.tce.oauth2.spring.client.controller.OAuthController.java

@RequestMapping("/oauth2logoutcallback")
public String logoutCallback(HttpServletRequest request) {
    request.getSession(false).invalidate();
    return "redirect:/";
}

From source file:br.com.jreader.util.security.URLAuthenticationSuccessHandler.java

protected void clearAuthenticationAttributes(HttpServletRequest request) {
    HttpSession session = request.getSession(false);
    if (session == null) {
        return;/*from  w ww.  j  av a  2s  .c  o m*/
    }
    session.removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
}

From source file:com.easysoft.jeap.controller.admin.LoginController.java

/**
 * /*ww w .j  a va  2  s.c  o m*/
 * @param request
 * @return
 */
@RequestMapping("/logout")
public String logout(HttpServletRequest request) {
    HttpSession session = request.getSession(false);
    if (session == null) {
        return "/adminthemes/default/login";
    }
    session.removeAttribute("admin_user_key");

    return "/adminthemes/default/login";
}

From source file:com.pe.nisira.movil.view.listener.SessionTimeoutFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    System.out.println("filter called");
    final HttpServletRequest req = (HttpServletRequest) request;
    final HttpSession session = req.getSession(false);
    if (session != null && !session.isNew()) {
        chain.doFilter(request, response);
    } else {//from  w  w  w.  ja  va  2s  .  c o  m
        System.out.println("Has timed out");
        req.getRequestDispatcher("/index.xthml").forward(request, response);
    }
}

From source file:org.appverse.web.framework.backend.test.util.frontfacade.mvc.tests.predefined.TestCsrfTokenRepository.java

@Override
public CsrfToken loadToken(HttpServletRequest request) {
    HttpSession session = request.getSession(false);
    if (session == null) {
        return null;
    }/*from   w w w.  j a v a 2s. c om*/
    return (CsrfToken) session.getAttribute(sessionAttributeName);
}

From source file:gov.nih.nci.cabig.ccts.security.HttpSessionPurgeLogoutHandler.java

public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
    HttpSession session = request.getSession(false);
    session.invalidate();//  ww  w .ja  v a2 s  .c o m
    logger.debug("Logged out.");
}