Guest User

Untitled

a guest
Nov 1st, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. @Override
  2. public Authentication attemptAuthentication(HttpServletRequest req, HttpServletResponse res)
  3. throws AuthenticationException, IOException, ServletException {
  4. String reqBody = req.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
  5.  
  6. // this appears to be empty on angular client calls
  7. System.out.println(reqBody);
  8.  
  9. ObjectMapper objectMapper = new ObjectMapper().configure(Feature.AUTO_CLOSE_SOURCE, true)
  10. .enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
  11. AccountCredentials creds = objectMapper.readValue(reqBody, AccountCredentials.class);
  12.  
  13. return getAuthenticationManager().authenticate(new UsernamePasswordAuthenticationToken(creds.getUsername(),
  14. creds.getPassword(), Collections.emptyList()));
  15. }
  16.  
  17. const user = {
  18. username: "asdf",
  19. password: "asdf"
  20. };
  21.  
  22. // imported from '@angular/http'
  23. const headers = new Headers({
  24. 'Content-Type': 'application/json'
  25. });
  26. const body = JSON.stringify(user);
  27. return this.http
  28. .put("http://localhost:8080/api/login", body, {headers})
  29. .toPromise()
  30. .then(response => response.json().data as User)
  31. .catch(this.handleError);
Add Comment
Please, Sign In to add comment