/** * Retrieves saved FlashMap instances from the HTTP session, if any. */ @Override @SuppressWarnings("unchecked") @Nullable protected List<FlashMap> retrieveFlashMaps(HttpServletRequest request) { HttpSession session = request.getSession(false); return (session != null ? (List<FlashMap>) session.getAttribute(FLASH_MAPS_SESSION_ATTRIBUTE) : null); }
@SuppressWarnings("unchecked") Flash(HttpSession session) { this.session = session; this.value = (T) session.getAttribute(ATTRIBUTE); if (this.value != null) { session.removeAttribute(ATTRIBUTE); } }
HttpSession session = request.getSession(); Integer n = (Integer) session.getAttribute("foo"); // not thread safe // another thread might be have got stale value between get and set session.setAttribute("foo", (n == null) ? 1 : n + 1);
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain fc) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; if (!request.getRequestURI().contains("/login") && !request.getRequestURI().contains("/acd/appconfig")) { RequestDispatcher dispatcher; HttpSession session = request.getSession(); if (session != null) { if (session.getAttribute("authName") == null || session.getAttribute("authRole") == null) { response.sendRedirect("/login"); return; } } else { request.setAttribute("fail_msg", "Session timed out!"); dispatcher = request.getRequestDispatcher("/Login"); dispatcher.forward(request, response); return; } } fc.doFilter(req, res); }
/** * Set the timestamp on the session to mark when the authentication happened, * useful for calculating authentication age. This gets stored in the sesion * and can get pulled out by other components. */ @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { Date authTimestamp = new Date(); HttpSession session = request.getSession(); session.setAttribute(AUTH_TIMESTAMP, authTimestamp); if (session.getAttribute(AuthorizationRequestFilter.PROMPT_REQUESTED) != null) { session.setAttribute(AuthorizationRequestFilter.PROMPTED, Boolean.TRUE); session.removeAttribute(AuthorizationRequestFilter.PROMPT_REQUESTED); } logger.info("Successful Authentication of " + authentication.getName() + " at " + authTimestamp.toString()); super.onAuthenticationSuccess(request, response, authentication); }
HttpServletRequest request = this.getThreadLocalRequest(); HttpSession session = request.getSession(); // in your authentication method if(isCorrectPassword) session.setAttribute("authenticatedUserName", "name"); // later if (session.getAttribute("authenticatedUserName") != null)
public boolean verify(HttpServletRequest request) { String postedToken = request.getParameter(TOKEN); String expectedToken = (String) request.getSession().getAttribute(TOKEN); return !StringUtils.isBlank(postedToken) && !StringUtils.isBlank(expectedToken) && postedToken.equals(expectedToken); } }
HttpSession session = request.getSession(); chain.doFilter(req, res); return; session.setAttribute(LOGIN_HINT, loginHint); } else { session.removeAttribute(LOGIN_HINT); chain.doFilter(req, res); } else { logger.info("Client requested no prompt"); response.sendRedirect(uriBuilder.toString()); return; if (session.getAttribute(PROMPTED) == null) { session.setAttribute(PROMPT_REQUESTED, Boolean.TRUE); chain.doFilter(req, res); } else { session.removeAttribute(PROMPTED); chain.doFilter(req, res); Date authTime = (Date) session.getAttribute(AuthenticationTimeStamper.AUTH_TIMESTAMP);
String action = request.getParameter("action"); String currentPath = request.getParameter("currentPath"); String displayPath = request.getParameter("displayPath"); String authRole = (String) request.getSession().getAttribute("authRole"); request.getSession().setAttribute("flashMsg", "Node created!"); dao.insertHistory((String) request.getSession().getAttribute("authName"), request.getRemoteAddr(), "Creating node: " + currentPath + newNode); response.sendRedirect("/home?zkPath=" + displayPath); break; case "Save Property": request.getSession().setAttribute("flashMsg", "Property Saved!"); if (ZooKeeperUtil.INSTANCE.checkIfPwdField(newProperty)) { newValue = ZooKeeperUtil.INSTANCE.SOPA_PIPA; dao.insertHistory((String) request.getSession().getAttribute("authName"), request.getRemoteAddr(), "Saving Property: " + currentPath + "," + newProperty + "=" + newValue); response.sendRedirect("/home?zkPath=" + displayPath); break; case "Update Property": dao.insertHistory((String) request.getSession().getAttribute("authName"), request.getRemoteAddr(), "Updating Property: " + currentPath + "," + newProperty + "=" + newValue); dao.insertHistory((String) request.getSession().getAttribute("authName"), request.getRemoteAddr(), "Deleting Property: " + delPropLst.toString()); dao.insertHistory((String) request.getSession().getAttribute("authName"), request.getRemoteAddr(), "Deleting Nodes: " + delNodeLst.toString());
@Override public void doFilter(HttpServletRequest wrappedRequest) { assertThat(wrappedRequest.getSession().getAttribute(ATTR)) .isEqualTo(VALUE); wrappedRequest.getSession().removeAttribute(ATTR); assertThat(wrappedRequest.getSession().getAttribute(ATTR)).isNull(); } });
@Override public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) servletRequest; HttpSession httpSession = httpRequest.getSession(); if (null == httpSession.getAttribute(RegistryCenterRestfulApi.REG_CENTER_CONFIG_KEY)) { loadActivatedRegCenter(httpSession); } if (null == httpSession.getAttribute(EventTraceDataSourceRestfulApi.DATA_SOURCE_CONFIG_KEY)) { loadActivatedEventTraceDataSource(httpSession); } filterChain.doFilter(servletRequest, servletResponse); }
public class Logout extends HttpServlet { public Logout() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); if(session.getAttribute("user") != null){ session.removeAttribute("user"); response.sendRedirect("login.jsp"); } }
@Override public void doFilter(HttpServletRequest wrappedRequest) { wrappedRequest.getSession().setAttribute(ATTR, VALUE); assertThat(wrappedRequest.getSession().getAttribute(ATTR)) .isEqualTo(VALUE); assertThat( Collections.list(wrappedRequest.getSession().getAttributeNames())) .containsOnly(ATTR); } });
DiscoveryInformation discovered = (DiscoveryInformation) request.getSession() .getAttribute(DISCOVERY_INFO_KEY); .getSession().getAttribute(ATTRIBUTE_LIST_KEY); request.getSession().removeAttribute(DISCOVERY_INFO_KEY); request.getSession().removeAttribute(ATTRIBUTE_LIST_KEY);
for (Enumeration<String> en = session.getAttributeNames(); en.hasMoreElements();) { String tem = en.nextElement(); session_attr.put(tem, session.getAttribute(tem)); for (Object o : Lang.enum2collection(req.getParameterNames(), new ArrayList<String>())) { String key = (String) o; String value = req.getParameter(key); p.put(key, value);
@Override public boolean toggleCollapsed(String paneId) { final HttpSession session = Stapler.getCurrentRequest().getSession(); final String property = format(attribute, paneId); final Object collapsed = session.getAttribute(property); if (collapsed == null) { session.setAttribute(property, true); return true; } session.removeAttribute(property); return false; } }
public void clear() { synchronized (session) { Enumeration<String> ems = session.getAttributeNames(); List<String> keys = new ArrayList<String>(); while (ems.hasMoreElements()) { String key = ems.nextElement(); if (null == key) continue; Object value = session.getAttribute(key); if (value instanceof ObjectProxy) { keys.add(key); ((ObjectProxy) value).depose(); } } for (String key : keys) { session.removeAttribute(key); } } }
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { if (!SessionUtils.hasAuthenticationToken(request)) { LOGGER.debug("Authentication token is not created for the request."); filterChain.doFilter(request, response); return; } final AuthenticationToken<?> authenticationToken = SessionUtils.getAuthenticationToken(request); Assert.notNull(authenticationToken); synchronized (request.getSession(false).getId().intern()) { long localCopyOfLastChangedTime = lastChangedTime;//This is so that the volatile variable is accessed only once. Long previousLastChangedTime = (Long) request.getSession().getAttribute(SECURITY_CONFIG_LAST_CHANGE); if (previousLastChangedTime == null) { request.getSession().setAttribute(SECURITY_CONFIG_LAST_CHANGE, localCopyOfLastChangedTime); } else if (previousLastChangedTime < localCopyOfLastChangedTime) { request.getSession().setAttribute(SECURITY_CONFIG_LAST_CHANGE, localCopyOfLastChangedTime); LOGGER.debug("Invalidating existing token {}", authenticationToken); authenticationToken.invalidate(); } } filterChain.doFilter(request, response); }
private Long lookupSandboxId(HttpServletRequest request) { String sandboxIdStr = request.getParameter(SANDBOX_ID_VAR); Long sandboxId = null; if (sandboxIdStr != null) { try { sandboxId = Long.valueOf(sandboxIdStr); if (LOG.isTraceEnabled()) { LOG.trace("SandboxId found on request " + sandboxId); } } catch (NumberFormatException nfe) { LOG.warn("blcSandboxId parameter could not be converted into a Long", nfe); } } if (sandboxId == null) { // check the session HttpSession session = request.getSession(false); if (session != null) { sandboxId = (Long) session.getAttribute(SANDBOX_ID_VAR); if (LOG.isTraceEnabled()) { if (sandboxId != null) { LOG.trace("SandboxId found in session " + sandboxId); } } } } else { HttpSession session = request.getSession(); session.setAttribute(SANDBOX_ID_VAR, sandboxId); } return sandboxId; }
/** * Adds a session value to the request */ protected void addSessionValue(final HttpServletRequest request, final String key, final Object value) { List l = (List) request.getSession(true).getAttribute(key); if (l == null) { l = new ArrayList(); } l.add(value); request.getSession(true).setAttribute(key, l); }