@Test void givenNoToken_whenLogout_thenHandleFailure() throws ServletException { when(authenticationService.getJwtTokenFromRequest(request)).thenReturn(Optional.empty()); handler.logout(request, response, authentication); verify(failedAuthenticationHandler, times(1)).onAuthenticationFailure(any(), any(), any()); }
@Override public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { Optional<String> token = authenticationService.getJwtTokenFromRequest(request); try { if (token.isPresent()) { invalidateJwtToken(failure, request, response, token.get()); } else { failure.onAuthenticationFailure(request, response, new TokenNotProvidedException("The token you are trying to logout is not present in the header")); } } catch (ServletException e) { log.error("The response cannot be written during the logout exception handler: {}", e.getMessage()); } }
JWTLogoutHandler implements LogoutHandler { @Override public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { Optional<String> token = authenticationService.getJwtTokenFromRequest(request); try { if (token.isPresent()) { invalidateJwtToken(failure, request, response, token.get()); } else { failure.onAuthenticationFailure(request, response, new TokenNotProvidedException("The token you are trying to logout is not present in the header")); } } catch (ServletException e) { log.error("The response cannot be written during the logout exception handler: {}", e.getMessage()); } } }
JWTLogoutHandler implements LogoutHandler { @Override public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { Optional<String> token = authenticationService.getJwtTokenFromRequest(request); try { if (token.isPresent()) { invalidateJwtToken(failure, request, response, token.get()); } else { failure.onAuthenticationFailure(request, response, new TokenNotProvidedException("The token you are trying to logout is not present in the header")); } } catch (ServletException e) { log.error("The response cannot be written during the logout exception handler: {}", e.getMessage()); } }  }
JWTLogoutHandler implements LogoutHandler { @Override public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { Optional<String> token = authenticationService.getJwtTokenFromRequest(request); try { if (token.isPresent()) { invalidateJwtToken(failure, request, response, token.get()); } else { failure.onAuthenticationFailure(request, response, new TokenNotProvidedException("The token you are trying to logout is not present in the header")); } } catch (ServletException e) { log.error("The response cannot be written during the logout exception handler: {}", e.getMessage()); } }  @Override void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication); }
JWTLogoutHandler implements LogoutHandler { @Override public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { Optional<String> token = authenticationService.getJwtTokenFromRequest(request); try { if (token.isPresent()) { invalidateJwtToken(failure, request, response, token.get()); } else { failure.onAuthenticationFailure(request, response, new TokenNotProvidedException("The token you are trying to logout is not present in the header")); } } catch (ServletException e) { log.error("The response cannot be written during the logout exception handler: {}", e.getMessage()); } }  @Override void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication);  }