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();

Source Link

Document

Returns the current session associated with this request, or if the request does not have a session, creates one.

Usage

From source file:com.wx.spring.controller.UserController.java

/** 
 * ?@OAuthRequired //from  w  ww.  j a  v a2  s  .  c  o  m
 * @param model 
 * @return 
 */
@RequestMapping(value = { "/userInfo.do" })
@OAuthRequired
public String load(HttpServletRequest request, Model model) {
    System.out.println("Load a User!");
    HttpSession session = request.getSession();
    model.addAttribute("Userid", session.getAttribute("Userid"));
    return "user";
}

From source file:se.inera.certificate.web.controller.PageController.java

protected void invalidateSessionAndClearContext(HttpServletRequest request) {
    request.getSession().invalidate();
    SecurityContextHolder.getContext().setAuthentication(null);
    SecurityContextHolder.clearContext();
}

From source file:com.bitranger.parknshop.buyer.controller.DeleteCartItemController.java

@RequestMapping(value = "/deleteCartItem")
public String addCart(HttpServletRequest req, Integer itemId) {
    PsCustomer currentCustomer = (PsCustomer) req.getSession().getAttribute("currentCustomer");
    if (currentCustomer == null)
        return Utility.error("Not Login");
    CartCustomerItem item = psCartCustomerItemDao
            .findById(new CartCustomerItemId(currentCustomer.getId(), itemId));
    if (item != null) {
        psCartCustomerItemDao.delete(item);
        return "redirect:/cart";
    }//w  w w  .  j a  v  a2  s .  co m
    return "redirect:/cart";
}

From source file:com.sharmila.hibernatespringsecurity.authentication.MyAuthenticationSuccessHandler.java

protected void clearAuthenticationAttribute(HttpServletRequest request) {
    HttpSession session = request.getSession();
    if (session == null) {
        return;//  ww  w .  j  av a2s  . co m
    }
    session.removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
}

From source file:org.sventon.web.UserRepositoryContextTest.java

@Test
public void testGetUserContext() throws Exception {
    final RepositoryName name = new RepositoryName("repository1");
    final HttpServletRequest request = new MockHttpServletRequest();
    assertNull(request.getSession().getAttribute("userContext"));
    final UserRepositoryContext userRepositoryContext = UserRepositoryContext.getContext(request, name);
    assertNotNull(request.getSession());
    final Object o = request.getSession().getAttribute("userContext");
    assertNotNull(o);/*w w w .j a  v a  2  s .  c  o  m*/
    assertTrue(o instanceof UserContext);
    final UserRepositoryContext contextFromSession = ((UserContext) o).getUserRepositoryContext(name);
    assertSame(contextFromSession, userRepositoryContext);
}

From source file:hu.sztaki.lpds.storage.service.carmen.server.upload.ProgressMonitorFileItemFactory.java

/**
 * Constructor//from w ww.  j a  v  a  2 s  .  c o m
 * @param request http request
 */
public ProgressMonitorFileItemFactory(HttpServletRequest request) {
    super();
    temporaryDirectory = (File) request.getSession().getServletContext()
            .getAttribute("javax.servlet.context.tempdir");
    requestRef = new WeakReference(request);
    String contentLength = request.getHeader("content-length");
    if (contentLength != null) {
        requestLength = Long.parseLong(contentLength.trim());
    }
}

From source file:com.controller.TelefonosController.java

@RequestMapping("telefonos.htm")
public ModelAndView getUsuarios(HttpServletRequest request) {
    sesion = request.getSession();
    ModelAndView mav = new ModelAndView();
    TelefonosDao userHelper = new TelefonosDao();
    String mensaje = null;/*from   ww  w .j  a  v  a  2 s  . co  m*/
    try {
        if (sesion.getAttribute("usuario") == null) {
            mensaje = "Debe Loguearse para acceder";
            mav.addObject("mensaje", mensaje);
            mav.setViewName("login/login");
        } else {
            TelefonosDao telDao = new TelefonosDao();
            List<Telefonos> listTelefonos = telDao.getAllTelefonos();
            if (sesion.getAttribute("tipoUsuario").toString().compareTo("Administrador") == 0) {
                System.out.println("Vista Administrador");

                mav.addObject("listaTelefonos", listTelefonos);
                mav.setViewName("telefonos/telefonos");
            } else {
                mav.setViewName("panel/panel");
            }

        }
    } catch (Exception e) {
        e.printStackTrace();
        mensaje = "Debe logearse para acceder a los datos";
        mav.addObject("mensaje", mensaje);
        mav.setViewName("login/login");
    }

    return mav;
}

From source file:net.bafeimao.umbrella.web.interceptor.SecurityCheckingHandlerInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    if (request.getSession().getAttribute("user") == null) {
        response.sendRedirect(request.getContextPath() + "/login?returl=" + request.getPathInfo());
        return false;
    }//from www.ja v  a2s .  co  m

    return super.preHandle(request, response, handler);
}

From source file:com.yahoo.dba.perf.myperf.springmvc.LogoutController.java

@Override
protected ModelAndView handleRequestImpl(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    HttpSession sess = req.getSession();

    //do we have session
    if (sess != null) {
        UserDBConnections conns = UserDBConnections.class.cast(sess.getAttribute("UserDBConnections"));
        sess.removeAttribute("UserDBConnections");
        sess.invalidate();/*ww w  .j a  v  a 2 s .  com*/

        new Thread(new LogoutCleaner(conns)).start();//make it async. 
        //TODO Add the thread handle for central process
    }

    ModelAndView mv = new ModelAndView(new RedirectView(this.getNosessView()));
    return mv;
}

From source file:net.groupbuy.service.impl.RSAServiceImpl.java

@Transactional(readOnly = true)
public void removePrivateKey(HttpServletRequest request) {
    Assert.notNull(request);/*from  w ww.  j  a  va 2 s  . co  m*/
    HttpSession session = request.getSession();
    session.removeAttribute(PRIVATE_KEY_ATTRIBUTE_NAME);
}