Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. <html>
  2. <head>
  3. <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script> <script>
  4. $( document ).ready(function() {
  5. var request = $.ajax({
  6. method: "POST",
  7. url: "http://localhost:8081/login",
  8. dataType: "json",
  9. contentType: "application/json; charset=utf-8",
  10. data: { username: "John", password: "Boston" }
  11. })
  12. .done(function( msg ) {
  13. alert( "Done: " + msg );
  14. })
  15. .fail(function( jqXHR, textStatus ) {
  16. alert( "Request failed: " + textStatus );
  17. });
  18. });
  19. </script>
  20. </head>
  21. <body>
  22. </body>
  23. </html>
  24.  
  25. @Override
  26. public Authentication attemptAuthentication(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
  27. throws AuthenticationException, IOException, ServletException {
  28. String contentType = httpServletRequest.getContentType();
  29. String headerPart = httpServletRequest.getHeader("Accept");
  30. String body = httpServletRequest.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
  31. AccountCredentials credentials = new ObjectMapper().readValue(httpServletRequest.getInputStream(),AccountCredentials.class);
  32. UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(credentials.getUsername(), credentials.getPassword());
  33. return getAuthenticationManager().authenticate(token);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement