@Test void shouldWriteModelToBody() throws Exception { httpServletResponse = new MockHttpServletResponse(); TokenAuthentication tokenAuthentication = new TokenAuthentication(USER, jwtToken); successfulQueryHandler.onAuthenticationSuccess(httpServletRequest, httpServletResponse, tokenAuthentication); assertNotNull(httpServletResponse.getContentAsString()); String response = httpServletResponse.getContentAsString(); assertTrue(response.contains("\"domain\":\"" + DOMAIN + "\"")); assertTrue(response.contains("\"userId\":\"" + USER + "\"")); assertTrue(response.contains("\"creation\":")); assertTrue(response.contains("\"expiration\":")); }
@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);  }