/** * Specifies the time, in seconds, between client requests the web container will invalidate this session. * * @param interval the interval */ public void maxInactiveInterval(int interval) { session.setMaxInactiveInterval(interval); }
public void setMaxInactiveInterval(int maxInactiveInterval) { session.setMaxInactiveInterval(maxInactiveInterval); }
public void setMaxInactiveInterval(int maxInactiveInterval) { session.setMaxInactiveInterval(maxInactiveInterval); }
private synchronized void refreshTimeout(HttpSession session) { if (requestCount.get() > 0) session.setMaxInactiveInterval(internalSessionTimeout); else session.setMaxInactiveInterval(timeout); }
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { boolean hadNoSessionBeforeStarting = request.getSession(false) == null; try { chain.doFilter(request, response); } finally { HttpSession session = request.getSession(false); boolean hasSessionNow = session != null; if (hadNoSessionBeforeStarting && hasSessionNow) { LOGGER.debug("Setting max inactive interval for request: {} to {}.", request.getRequestURI(), maxInactiveInterval); session.setMaxInactiveInterval(maxInactiveInterval); } } } }
public void setTimeout(long maxIdleTimeInMillis) throws InvalidSessionException { try { int timeout = Long.valueOf(maxIdleTimeInMillis / 1000).intValue(); httpSession.setMaxInactiveInterval(timeout); } catch (Exception e) { throw new InvalidSessionException(e); } }
@Override public final void loginSuccess(HttpServletRequest request, HttpServletResponse response, Authentication successfulAuthentication) { if (!this.alwaysRemember && !rememberMeRequested(request, this.rememberMeParameterName)) { logger.debug("Remember-me login not requested."); return; } request.setAttribute(REMEMBER_ME_LOGIN_ATTR, true); request.getSession().setMaxInactiveInterval(this.validitySeconds); }
@Override public void onApplicationEvent(HttpSessionCreatedEvent event) { logger.debug("Setting session timeout["+event.getSession().getId()+"] to :"+timeout); event.getSession().setMaxInactiveInterval(timeout); }
case SET_MAX_INACTIVE: session = request.getSession(); session.setMaxInactiveInterval(Integer.valueOf(value)); break; case GET:
Map<String, Object> templateParam = new HashMap<>(); HttpSession session = request.getSession(true); session.setMaxInactiveInterval(Integer.valueOf(globalProps.getProperty("sessionTimeout")));
@Override public void doFilter(HttpServletRequest wrappedRequest) { wrappedRequest.getSession().setMaxInactiveInterval(interval); assertThat(wrappedRequest.getSession().getMaxInactiveInterval()) .isEqualTo(interval); } });
@Override public void doFilter(HttpServletRequest wrappedRequest) { HttpSession session = wrappedRequest.getSession(); session.invalidate(); // no exception session.getMaxInactiveInterval(); session.setMaxInactiveInterval(3600); } });
@Test public void testDefaultTimeout() { listener.onApplicationEvent(event); verify(session, times(1)).setMaxInactiveInterval(30 * 60); }
@Test public void loginSuccessWithAlwaysRemember() { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); Authentication authentication = mock(Authentication.class); HttpSession session = mock(HttpSession.class); given(request.getSession()).willReturn(session); this.rememberMeServices = new SpringSessionRememberMeServices(); this.rememberMeServices.setAlwaysRemember(true); this.rememberMeServices.loginSuccess(request, response, authentication); verify(request, times(1)).getSession(); verify(request, times(1)).setAttribute( eq(SpringSessionRememberMeServices.REMEMBER_ME_LOGIN_ATTR), eq(true)); verify(session, times(1)).setMaxInactiveInterval(eq(2592000)); verifyZeroInteractions(request, response, session, authentication); }
@Test public void loginSuccess() { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); Authentication authentication = mock(Authentication.class); HttpSession session = mock(HttpSession.class); given(request.getParameter(eq("remember-me"))).willReturn("true"); given(request.getSession()).willReturn(session); this.rememberMeServices = new SpringSessionRememberMeServices(); this.rememberMeServices.loginSuccess(request, response, authentication); verify(request, times(1)).getParameter(eq("remember-me")); verify(request, times(1)).getSession(); verify(request, times(1)).setAttribute( eq(SpringSessionRememberMeServices.REMEMBER_ME_LOGIN_ATTR), eq(true)); verify(session, times(1)).setMaxInactiveInterval(eq(2592000)); verifyZeroInteractions(request, response, session, authentication); }
@Test public void loginSuccessWithCustomValidity() { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); Authentication authentication = mock(Authentication.class); HttpSession session = mock(HttpSession.class); given(request.getParameter(eq("remember-me"))).willReturn("true"); given(request.getSession()).willReturn(session); this.rememberMeServices = new SpringSessionRememberMeServices(); this.rememberMeServices.setValiditySeconds(100000); this.rememberMeServices.loginSuccess(request, response, authentication); verify(request, times(1)).getParameter(eq("remember-me")); verify(request, times(1)).getSession(); verify(request, times(1)).setAttribute( eq(SpringSessionRememberMeServices.REMEMBER_ME_LOGIN_ATTR), eq(true)); verify(session, times(1)).setMaxInactiveInterval(eq(100000)); verifyZeroInteractions(request, response, session, authentication); }
@Test public void loginSuccessWithCustomParameter() { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); Authentication authentication = mock(Authentication.class); HttpSession session = mock(HttpSession.class); given(request.getParameter(eq("test-param"))).willReturn("true"); given(request.getSession()).willReturn(session); this.rememberMeServices = new SpringSessionRememberMeServices(); this.rememberMeServices.setRememberMeParameterName("test-param"); this.rememberMeServices.loginSuccess(request, response, authentication); verify(request, times(1)).getParameter(eq("test-param")); verify(request, times(1)).getSession(); verify(request, times(1)).setAttribute( eq(SpringSessionRememberMeServices.REMEMBER_ME_LOGIN_ATTR), eq(true)); verify(session, times(1)).setMaxInactiveInterval(eq(2592000)); verifyZeroInteractions(request, response, session, authentication); }
@Test public void testNonDefaultTimeout() { listener.setTimeout(15 * 60); listener.onApplicationEvent(event); verify(session, times(1)).setMaxInactiveInterval(15 * 60); }
@Override public void setMaxInactiveInterval(int interval) { session.setMaxInactiveInterval(interval); }
@Override public void setMaxInactiveInterval(int interval) { _session.setMaxInactiveInterval(interval); }