@Test void shouldSetResponseParameters() throws Exception { httpServletResponse = new MockHttpServletResponse(); TokenAuthentication tokenAuthentication = new TokenAuthentication(USER, jwtToken); httpServletResponse.setStatus(HttpStatus.EXPECTATION_FAILED.value()); assertNotEquals(HttpStatus.OK.value(), httpServletResponse.getStatus()); successfulQueryHandler.onAuthenticationSuccess(httpServletRequest, httpServletResponse, tokenAuthentication); assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, httpServletResponse.getContentType()); assertEquals(HttpStatus.OK.value(), httpServletResponse.getStatus()); assertTrue(httpServletResponse.isCommitted()); }
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException { TokenAuthentication tokenAuthentication = (TokenAuthentication) authentication; String token = tokenAuthentication.getCredentials(); response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); response.setStatus(HttpStatus.OK.value()); mapper.writeValue(response.getWriter(), authenticationService.parseJwtToken(token)); response.getWriter().flush(); if (!response.isCommitted()) { throw new IOException("Authentication response has not been committed."); } }
SuccessfulQueryHandler implements AuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException { TokenAuthentication tokenAuthentication = (TokenAuthentication) authentication; String token = tokenAuthentication.getCredentials(); response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); response.setStatus(HttpStatus.OK.value()); mapper.writeValue(response.getWriter(), authenticationService.parseJwtToken(token)); response.getWriter().flush(); if (!response.isCommitted()) { throw new IOException("Authentication response has not been committed."); } } }
SuccessfulQueryHandler implements AuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException { TokenAuthentication tokenAuthentication = (TokenAuthentication) authentication; String token = tokenAuthentication.getCredentials(); response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); response.setStatus(HttpStatus.OK.value()); mapper.writeValue(response.getWriter(), authenticationService.parseJwtToken(token)); response.getWriter().flush(); if (!response.isCommitted()) { throw new IOException("Authentication response has not been committed."); } } SuccessfulQueryHandler(ObjectMapper securityObjectMapper,
                                  AuthenticationService authenticationService); }
SuccessfulQueryHandler implements AuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException { TokenAuthentication tokenAuthentication = (TokenAuthentication) authentication; String token = tokenAuthentication.getCredentials(); response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); response.setStatus(HttpStatus.OK.value()); mapper.writeValue(response.getWriter(), authenticationService.parseJwtToken(token)); response.getWriter().flush(); if (!response.isCommitted()) { throw new IOException("Authentication response has not been committed."); } } SuccessfulQueryHandler(ObjectMapper securityObjectMapper,
                                  AuthenticationService authenticationService); @Override void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication); }
SuccessfulQueryHandler implements AuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException { TokenAuthentication tokenAuthentication = (TokenAuthentication) authentication; String token = tokenAuthentication.getCredentials(); response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); response.setStatus(HttpStatus.OK.value()); mapper.writeValue(response.getWriter(), authenticationService.parseJwtToken(token)); response.getWriter().flush(); if (!response.isCommitted()) { throw new IOException("Authentication response has not been committed."); } } SuccessfulQueryHandler(ObjectMapper securityObjectMapper,
                                  AuthenticationService authenticationService); @Override void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication);  }