HttpSessionPentahoSessionIntegrationFilter implements Filter, InitializingBean { @VisibleForTesting void setSessionExpirationCookies( final HttpSession httpSession, final IPentahoSession pentahoSession, final HttpServletResponse httpServletResponse ) { if ( null == httpSession || null == pentahoSession ) { return; } final String showDialog = PentahoSystem.getSystemSetting( "session-expired-dialog", "true" ); if ( "true".equals( showDialog ) ) { final List<AuthenticationProvider> authenticationProviders = PentahoSystem.getAll( AuthenticationProvider.class, pentahoSession ); if ( null == authenticationProviders || authenticationProviders.isEmpty() ) { return; } if ( isSsoEnabled() ) { return; } final long serverTime = System.currentTimeMillis(); final long expiryTime = serverTime + httpSession.getMaxInactiveInterval() * 1000; final Cookie sessionExpirationCookie = new Cookie( "session-expiry", String.valueOf( expiryTime ) ); sessionExpirationCookie.setPath( "/" ); final Cookie serverTimeCookie = new Cookie( "server-time", String.valueOf( serverTime ) ); serverTimeCookie.setPath( "/" ); httpServletResponse.addCookie( sessionExpirationCookie ); httpServletResponse.addCookie( serverTimeCookie ); } }  void init( FilterConfig filterConfig ); void destroy(); void afterPropertiesSet(); void doFilter( ServletRequest request, ServletResponse response, FilterChain chain ); boolean isAllowSessionCreation(); void setAllowSessionCreation( boolean allowSessionCreation ); boolean isForceEagerSessionCreation(); void setForceEagerSessionCreation( boolean forceEagerSessionCreation ); void setCallSetAuthenticatedForAnonymousUsers( final boolean callSetAuthenticatedForAnonymousUsers ); boolean isSsoEnabled(); void setSsoEnabled( boolean ssoEnabled );  }
@Test public void testSessionCookieNoHttpSession() { new HttpSessionPentahoSessionIntegrationFilter() .setSessionExpirationCookies( null, pentahoSession, servletResponse ); Mockito.verify( servletResponse, Mockito.never() ).addCookie( Mockito.any() ); }
@Test public void testSessionCookieNoPentahoSession() { new HttpSessionPentahoSessionIntegrationFilter().setSessionExpirationCookies( httpSession, null, servletResponse ); Mockito.verify( servletResponse, Mockito.never() ).addCookie( Mockito.any() ); }
@Test public void testSessionCookieDisabledInSettings() { final ISystemSettings systemSettings = PentahoSystem.getSystemSettings(); try { final ISystemSettings mockSettings = Mockito.mock( ISystemSettings.class ); Mockito.when( mockSettings.getSystemSetting( "session-expired-dialog", "true" ) ).thenReturn( "false" ); PentahoSystem.setSystemSettingsService( mockSettings ); new HttpSessionPentahoSessionIntegrationFilter() .setSessionExpirationCookies( httpSession, pentahoSession, servletResponse ); Mockito.verify( servletResponse, Mockito.never() ).addCookie( Mockito.any() ); } finally { PentahoSystem.setSystemSettingsService( systemSettings ); } }
@Test public void testSessionCookieNoAuthenticationProviders() { final ISystemSettings systemSettings = PentahoSystem.getSystemSettings(); try { final ISystemSettings mockSettings = Mockito.mock( ISystemSettings.class ); Mockito.when( mockSettings.getSystemSetting( "session-expired-dialog", "true" ) ).thenReturn( "true" ); PentahoSystem.setSystemSettingsService( mockSettings ); new HttpSessionPentahoSessionIntegrationFilter() .setSessionExpirationCookies( httpSession, pentahoSession, servletResponse ); Mockito.verify( servletResponse, Mockito.never() ).addCookie( Mockito.any() ); } finally { PentahoSystem.setSystemSettingsService( systemSettings ); } }
@Test public void testSessionCookieNoSettings() throws ObjectFactoryException { final AuthenticationProvider mockObj = Mockito.mock( AuthenticationProvider.class ); PentahoSystem.registerObject( mockObj, AuthenticationProvider.class ); new HttpSessionPentahoSessionIntegrationFilter() .setSessionExpirationCookies( httpSession, pentahoSession, servletResponse ); Mockito.verify( servletResponse, Mockito.times( 2 ) ).addCookie( Mockito.any() ); }
@Test public void testSessionCookieSettingsEnabled() throws ObjectFactoryException { final ISystemSettings systemSettings = PentahoSystem.getSystemSettings(); try { final ISystemSettings mockSettings = Mockito.mock( ISystemSettings.class ); Mockito.when( mockSettings.getSystemSetting( "session-expired-dialog", "true" ) ).thenReturn( "true" ); PentahoSystem.setSystemSettingsService( mockSettings ); final AuthenticationProvider mockObj = Mockito.mock( AuthenticationProvider.class ); PentahoSystem.registerObject( mockObj, AuthenticationProvider.class ); new HttpSessionPentahoSessionIntegrationFilter() .setSessionExpirationCookies( httpSession, pentahoSession, servletResponse ); Mockito.verify( servletResponse, Mockito.times( 2 ) ).addCookie( Mockito.any() ); } finally { PentahoSystem.setSystemSettingsService( systemSettings ); } }