@SuppressWarnings("unchecked") Flash(HttpSession session) { this.session = session; this.value = (T) session.getAttribute(ATTRIBUTE); if (this.value != null) { session.removeAttribute(ATTRIBUTE); } }
public static void removeAuthenticationError(HttpServletRequest request) { request.getSession().removeAttribute(AUTHENTICATION_ERROR); }
/** * Set the session attribute with the given name to the given value. * Removes the session attribute if value is null, if a session existed at all. * Does not create a new session if not necessary! * @param request current HTTP request * @param name the name of the session attribute * @param value the value of the session attribute */ public static void setSessionAttribute(HttpServletRequest request, String name, @Nullable Object value) { Assert.notNull(request, "Request must not be null"); if (value != null) { request.getSession().setAttribute(name, value); } else { HttpSession session = request.getSession(false); if (session != null) { session.removeAttribute(name); } } }
@Override public void doFilter(HttpServletRequest wrappedRequest) { assertThat(wrappedRequest.getSession().getAttribute(ATTR)) .isEqualTo(VALUE); wrappedRequest.getSession().removeAttribute(ATTR); assertThat(wrappedRequest.getSession().getAttribute(ATTR)).isNull(); } });
/** * 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); }
@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; } }
/** {@inheritDoc} */ public boolean setAttribute(String name, Object value) { if (name == null) { return false; } if (value == null) { session.removeAttribute(name); } else { session.setAttribute(name, value); } return true; }
final HttpSession session = request.getSession(false); LOG.info( "Invalidating session " + session.getId() ); session.invalidate(); final HttpSession session = request.getSession(); LOG.info("Removing " + (keys.length > 1 ? "keys " : "key ") + Arrays.asList(keys)); for (final String key : keys) { session.removeAttribute(key); while ( attributeNames.hasMoreElements() ) { final String name = attributeNames.nextElement().toString(); final Object value = session.getAttribute( name ); out.println( name + "=" + value );
static final HttpSession createMockHttpSession(final ServletContext context, final Map<String, Object> attributes) { final HttpSession session = Mockito.mock(HttpSession.class); Mockito.when(session.getServletContext()).thenReturn(context); Mockito.when(session.getAttributeNames()).thenAnswer(new GetVariableNamesAnswer(attributes)); Mockito.when(session.getAttribute(Matchers.anyString())).thenAnswer(new GetAttributeAnswer(attributes)); Mockito.doAnswer(new SetAttributeAnswer(attributes)).when(session).setAttribute(Matchers.anyString(), Matchers.anyObject()); Mockito.doAnswer(new RemoveAttributeAnswer(attributes)).when(session).removeAttribute(Matchers.anyString()); return session; }
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); } } }
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);
public static void setUserId(HttpServletRequest request, Long id) { if (id == null || id == NOT_PERSISTED) { request.getSession().removeAttribute(CURRENT_USER_ID); } else { request.getSession().setAttribute(CURRENT_USER_ID, id); } }
HttpSession session = request.getSession(); session.setAttribute(LOGIN_HINT, loginHint); } else { session.removeAttribute(LOGIN_HINT); if (session.getAttribute(PROMPTED) == null) { session.setAttribute(PROMPT_REQUESTED, Boolean.TRUE); session.removeAttribute(PROMPTED); chain.doFilter(req, res); Date authTime = (Date) session.getAttribute(AuthenticationTimeStamper.AUTH_TIMESTAMP);
/** * Remove Object in session. * @param key a String specifying the key of the Object stored in session */ public Controller removeSessionAttr(String key) { HttpSession session = request.getSession(false); if (session != null) session.removeAttribute(key); return this; }
/** * Cleans up the remoting connection client from the HttpSession and client registry. This should also fix APPSERVER-328 */ public void cleanup() { if (session != null) { RemotingClient rc = (RemotingClient) session.getAttribute(CLIENT); session.removeAttribute(CLIENT); if (rc != null) { rc.unregister(this); } } }
HttpSession session = req.getSession(true); try{ if(null != (session.getAttribute("error"))){ session.removeAttribute("error"); }else{ session.setAttribute( "error", "Invalid username or password"); } }catch(Exception er){ er.printStackTrace(); } RequestDispatcher dispatcher = req.getRequestDispatcher("/jsp/LoginTest.jsp"); dispatcher.forward( req, res);
public void touch() throws InvalidSessionException { //just manipulate the session to update the access time: try { httpSession.setAttribute(TOUCH_OBJECT_SESSION_KEY, TOUCH_OBJECT_SESSION_KEY); httpSession.removeAttribute(TOUCH_OBJECT_SESSION_KEY); } catch (Exception e) { throw new InvalidSessionException(e); } }
static final HttpSession createMockHttpSession(final ServletContext context, final Map<String, Object> attributes) { final HttpSession session = Mockito.mock(HttpSession.class); Mockito.when(session.getServletContext()).thenReturn(context); Mockito.when(session.getAttributeNames()).thenAnswer(new GetVariableNamesAnswer(attributes)); Mockito.when(session.getAttribute(Matchers.anyString())).thenAnswer(new GetAttributeAnswer(attributes)); Mockito.doAnswer(new SetAttributeAnswer(attributes)).when(session).setAttribute(Matchers.anyString(), Matchers.anyObject()); Mockito.doAnswer(new RemoveAttributeAnswer(attributes)).when(session).removeAttribute(Matchers.anyString()); return session; }
response.setTimeout(session.getMaxInactiveInterval()); final String user_UUID = (String)session.getAttribute("user_UUID"); response.setUserId(user_UUID); final String domain_UUID = (String)session.getAttribute("domain_UUID"); response.setDomainId(domain_UUID); session.removeAttribute("user_UUID"); session.removeAttribute("domain_UUID"); while (attrNames.hasMoreElements()) { final String attrName = (String) attrNames.nextElement(); final Object attrObj = session.getAttribute(attrName); if (ApiConstants.USERNAME.equalsIgnoreCase(attrName)) { response.setUsername(attrObj.toString());
protected static void setXXSSProtection( HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(false); if ((session != null) && (session.getAttribute(_DISABLE_XSS_AUDITOR) != null)) { session.removeAttribute(_DISABLE_XSS_AUDITOR); response.setHeader(HttpHeaders.X_XSS_PROTECTION, "0"); return; } if (_X_XSS_PROTECTION == null) { return; } response.setHeader(HttpHeaders.X_XSS_PROTECTION, _X_XSS_PROTECTION); }