Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Autowired
- private AuthenticationManager authenticationManager;
- @ResponseBody
- @RequestMapping(value = "/auth", method = RequestMethod.POST)
- public Map auth(@RequestBody Map<String, String> params, HttpServletRequest request) {
- String username = params.get("username");
- String password = params.get("password");
- UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);
- Authentication authenticate = authenticationManager.authenticate(token);
- Map<String, String> result = new HashMap<>();
- QuicktechUserDetails principal = (QuicktechUserDetails) authenticate.getPrincipal();
- SecurityContextHolder.getContext().setAuthentication(authenticate);
- User user = principal.getUser();
- result.put("username", principal.getUsername());
- result.put("firstname", user.getFirstName());
- result.put("lastname", user.getLastName());
- result.put("id", user.getId());
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement