List of usage examples for javax.servlet.http HttpSession getAttribute
public Object getAttribute(String name);
null
if no object is bound under the name. From source file:mx.com.quadrum.contratos.controller.crud.UsuarioController.java
@ResponseBody @RequestMapping(value = "eliminarUsuario", method = RequestMethod.POST) public String eliminarUsuario(Usuario usuario, BindingResult bindingResult, HttpSession session) { if (session.getAttribute("usuario") == null) { return SESION_CADUCA; }//from w ww . jav a 2 s.c om return usuarioService.eliminar(usuario); }
From source file:net.anthonychaves.bookmarks.web.PersistentLoginFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; Cookie tokenCookie = getCookieByName(httpRequest.getCookies(), "loginToken"); HttpSession session = httpRequest.getSession(); User user = (User) session.getAttribute("user"); if (user == null && tokenCookie != null) { user = tokenService.loginWithToken(tokenCookie.getValue()); String tokenValue = tokenService.setupNewLoginToken(user); httpRequest.getSession().setAttribute("user", user); tokenCookie.setMaxAge(0);// ww w . jav a 2 s . c om httpResponse.addCookie(tokenCookie); tokenCookie = new Cookie("loginToken", tokenValue); tokenCookie.setPath("/bookmarks"); tokenCookie.setMaxAge(168 * 60 * 60); httpResponse.addCookie(tokenCookie); } chain.doFilter(httpRequest, httpResponse); }
From source file:org.lightadmin.core.web.security.LightAdminRequestCache.java
@Override public SavedRequest getRequest(HttpServletRequest currentRequest, HttpServletResponse response) { HttpSession session = currentRequest.getSession(false); if (session != null) { return (DefaultSavedRequest) session.getAttribute(savedRequestKey); }/*from w w w .j a va2 s . co m*/ return null; }
From source file:com.viseur.control.MoreSuggestedProjects.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request//from www . ja v a2s . co m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JSONObject json = new JSONObject(); int last = Integer.valueOf(request.getParameter("last")); ArrayList<Project> country = new ArrayList<>(); String htmlContent = ""; HttpSession session = request.getSession(); User reg = (User) session.getAttribute("user"); country.addAll(new Investor(reg).getFromInvestorCountry(last)); for (Project proj : country) { htmlContent += "<div class='col-sm-4 col-md-4'><div class='thumbnail'>" + "<h6><span class='label label-default pull-right'>" + proj.categoryName + "</span></h6>" + "<div class='col-item'><div class='photo'><img src='" + VHost.IMGPATH + "/content/logo/" + proj.itemId + ".png' class='img-responsive' alt='' /></div>" + "<div class='info'><div class='row'><div class='price col-sm-12'><div class='separator clear-left'>" + "</div><h4 class=\"text_warap\"><a href='" + VHost.ROOT + "viewproject.jsp?project=" + proj.itemId + "' class='text_warap'>" + proj.title + "</a></h4><p>" + proj.itemShortDesc + "</p></div></div>" + "<div class='separator clear-left'><div class='col-md-6'><h6 class=''><span class='glyphicon glyphicon-eye-open'></span>" + proj.visted + "</h6></div><div class='col-md-6'> <h6 class=''><span class='glyphicon glyphicon-fire'></span> " + proj.buzzedTimes + "</h6></div></div><div class='clearfix'></div></div></div></a></div>"; } json.put("last", last + country.size()); json.put("htmlContent", htmlContent); try (PrintWriter out = response.getWriter()) { out.println(json); out.flush(); } }
From source file:chiron.maxscore.controller.MenuController.java
@RequestMapping("menu") @ResponseBody/*from ww w. j av a 2 s . c o m*/ public Object menu(HttpSession session) { Role role = (Role) session.getAttribute("role"); return menuService.getMenuItemRoot(role).getChildren(); }
From source file:handlers.CustomLoginSuccessHandler.java
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { this.setDefaultTargetUrl(defaultSuccessUrl); String username = ((User) authentication.getPrincipal()).getUsername(); userService.updateLastLoginAccess(username, new Date()); HttpSession session = request.getSession(); if (session != null) { String redirectUrl = (String) session.getAttribute("url_prior_login"); if (redirectUrl != null) { logger.info("Redirigiendo usuario a : " + redirectUrl); // we do not forget to clean this attribute from session session.removeAttribute("url_prior_login"); // then we redirect getRedirectStrategy().sendRedirect(request, response, redirectUrl); } else {/* w ww . ja v a 2 s . com*/ super.onAuthenticationSuccess(request, response, authentication); } } else { super.onAuthenticationSuccess(request, response, authentication); } }
From source file:mx.com.quadrum.contratos.controller.crud.ContactoController.java
@RequestMapping(value = "contacto", method = RequestMethod.GET) public String contactos(Model model, HttpSession session) { Usuario usuario = (Usuario) session.getAttribute("usuario"); List<Permiso> permisos = (List<Permiso>) session.getAttribute(PERMISOS); if (usuario == null || permisos == null) { return "templates/index"; }/* w ww .j a va2 s. co m*/ if (usuario.getEsAdmin()) { model.addAttribute("esAdmin", "esAdmin"); } if (usuarioService.tienePermiso(usuario, "contacto")) { return "templates/noAutorizado"; } model.addAttribute("permisos", permisos); model.addAttribute("contactos", contactoService.buscarTodos()); model.addAttribute("grado", gradoService.buscarTodos()); model.addAttribute("empresa", empresaService.buscarTodos()); return "crud/contacto"; }
From source file:org.jasig.portlet.cms.controller.DownloadPostAttachmentController.java
@RequestMapping protected void handleRequest(final HttpServletRequest request, final HttpServletResponse response) throws Exception { final HttpSession session = request.getSession(); final Attachment attachment = (Attachment) session.getAttribute("attachment"); logDebug("Attempting to download attachment: " + attachment); response.setContentType("application/x-download"); logDebug("Set content type to: " + response.getContentType()); final String encoding = response.getCharacterEncoding(); logDebug("Encoded file name based on: " + encoding); final String fileName = URLEncoder.encode(attachment.getFileName(), encoding); response.setHeader("Content-Disposition", "attachment; filename=" + fileName); logDebug("Downloading file: " + fileName); final OutputStream out = response.getOutputStream(); out.write(attachment.getContents()); out.flush();//from w w w. ja v a2s .c om logDebug("Clearing session attribute"); session.setAttribute("attachment", null); }
From source file:org.shareok.data.webserv.HomeController.java
@RequestMapping("/home") public ModelAndView home(HttpServletRequest req, HttpServletResponse res) { ModelAndView model = new ModelAndView(); model.setViewName("home"); HttpSession session = (HttpSession) req.getSession(false); if (null != session) { RedisUser user = (RedisUser) session .getAttribute(ShareokdataManager.getSessionRedisUserAttributeName()); if (null != user) { Cookie userCookie = new Cookie("userId", String.valueOf(user.getUserId())); userCookie.setMaxAge(30 * 60); res.addCookie(userCookie);/*from www .j a v a2s . co m*/ model.addObject("user", user); model.addObject("loginTime", session.getCreationTime()); } } return model; }
From source file:getSession.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from ww w . j a v a 2 s. c o m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); String result = ""; JSONObject jo = new JSONObject(); if (session.getAttribute("name") != null && session.getAttribute("affiliation") != null && session.getAttribute("cid") != null) { jo.put("name", session.getAttribute("name")); jo.put("affiliation", session.getAttribute("affiliation")); jo.put("cid", session.getAttribute("cid")); result = jo.toString(); } else result = "null"; response.getWriter().write(result); }