@Test public void testOnAuthenticationSuccess() throws IOException, ServletException { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); Authentication authentication = mock(Authentication.class); when(authentication.getName()).thenReturn("name"); when(request.getRemoteAddr()).thenReturn("localhost"); PrintWriter printWriter = mock(PrintWriter.class); when(response.getWriter()).thenReturn(printWriter); String token = "token"; User u = new User("usernma", "pass", "salt", "role"); u.setToken("token"); when(userService.createUserToken(authentication.getName(), request.getRemoteAddr())).thenReturn(u); ajaxAuthenticationSuccessHandler.onAuthenticationSuccess(request, response, authentication); verify(response).setStatus(HttpServletResponse.SC_OK); verify(headerHandler).process(request, response); verify(userService).createUserToken(authentication.getName(), request.getRemoteAddr()) ; verify(printWriter).print("{ \"token\" : \"" + u.getToken() + "\"}"); }
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { logger.debug("Authentication Successful"); User u = userService.createUserToken(authentication.getName(), request.getRemoteAddr()); response.getWriter().print("{ \"token\" : \"" + u.getToken() + "\"}"); response.setStatus(HttpServletResponse.SC_OK); headerHandler.process(request, response); }
AjaxAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { logger.debug("Authentication Successful"); User u = userService.createUserToken(authentication.getName(), request.getRemoteAddr()); response.getWriter().print("{ \"token\" : \"" + u.getToken() + "\"}"); response.setStatus(HttpServletResponse.SC_OK); headerHandler.process(request, response); } }
AjaxAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { logger.debug("Authentication Successful"); User u = userService.createUserToken(authentication.getName(), request.getRemoteAddr()); response.getWriter().print("{ \"token\" : \"" + u.getToken() + "\"}"); response.setStatus(HttpServletResponse.SC_OK); headerHandler.process(request, response); }  }
AjaxAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { logger.debug("Authentication Successful"); User u = userService.createUserToken(authentication.getName(), request.getRemoteAddr()); response.getWriter().print("{ \"token\" : \"" + u.getToken() + "\"}"); response.setStatus(HttpServletResponse.SC_OK); headerHandler.process(request, response); }  @Override void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication); }
AjaxAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { logger.debug("Authentication Successful"); User u = userService.createUserToken(authentication.getName(), request.getRemoteAddr()); response.getWriter().print("{ \"token\" : \"" + u.getToken() + "\"}"); response.setStatus(HttpServletResponse.SC_OK); headerHandler.process(request, response); }  @Override void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication);  }