Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public Authentication attemptAuthentication(HttpServletRequest req, HttpServletResponse res)
- throws AuthenticationException, IOException, ServletException {
- String reqBody = req.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
- // this appears to be empty on angular client calls
- System.out.println(reqBody);
- ObjectMapper objectMapper = new ObjectMapper().configure(Feature.AUTO_CLOSE_SOURCE, true)
- .enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
- AccountCredentials creds = objectMapper.readValue(reqBody, AccountCredentials.class);
- return getAuthenticationManager().authenticate(new UsernamePasswordAuthenticationToken(creds.getUsername(),
- creds.getPassword(), Collections.emptyList()));
- }
- const user = {
- username: "asdf",
- password: "asdf"
- };
- // imported from '@angular/http'
- const headers = new Headers({
- 'Content-Type': 'application/json'
- });
- const body = JSON.stringify(user);
- return this.http
- .put("http://localhost:8080/api/login", body, {headers})
- .toPromise()
- .then(response => response.json().data as User)
- .catch(this.handleError);
Add Comment
Please, Sign In to add comment