@Test public void logoutNullLoginContext() throws Exception { SessionDestroyedEvent event = mock(SessionDestroyedEvent.class); SecurityContext securityContext = mock(SecurityContext.class); JaasAuthenticationToken token = mock(JaasAuthenticationToken.class); when(event.getSecurityContexts()).thenReturn(Arrays.asList(securityContext)); when(securityContext.getAuthentication()).thenReturn(token); provider.onApplicationEvent(event); verify(event).getSecurityContexts(); verify(securityContext).getAuthentication(); verify(token).getLoginContext(); verifyNoMoreInteractions(event, securityContext, token); }
@Test public void logout() throws Exception { SessionDestroyedEvent event = mock(SessionDestroyedEvent.class); SecurityContext securityContext = mock(SecurityContext.class); JaasAuthenticationToken token = mock(JaasAuthenticationToken.class); LoginContext context = mock(LoginContext.class); when(event.getSecurityContexts()).thenReturn(Arrays.asList(securityContext)); when(securityContext.getAuthentication()).thenReturn(token); when(token.getLoginContext()).thenReturn(context); provider.onApplicationEvent(event); verify(event).getSecurityContexts(); verify(securityContext).getAuthentication(); verify(token).getLoginContext(); verify(context).logout(); verifyNoMoreInteractions(event, securityContext, token, context); }
@Test public void logoutLoginException() throws Exception { SessionDestroyedEvent event = mock(SessionDestroyedEvent.class); SecurityContext securityContext = mock(SecurityContext.class); JaasAuthenticationToken token = mock(JaasAuthenticationToken.class); LoginContext context = mock(LoginContext.class); LoginException loginException = new LoginException("Failed Login"); when(event.getSecurityContexts()).thenReturn(Arrays.asList(securityContext)); when(securityContext.getAuthentication()).thenReturn(token); when(token.getLoginContext()).thenReturn(context); doThrow(loginException).when(context).logout(); provider.onApplicationEvent(event); verify(event).getSecurityContexts(); verify(securityContext).getAuthentication(); verify(token).getLoginContext(); verify(context).logout(); verify(log).warn(anyString(), eq(loginException)); verifyNoMoreInteractions(event, securityContext, token, context); }