You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.6 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package ru.digitalbanana.demoresourceserver.web.controller;
  2. import java.util.Collections;
  3. import java.util.List;
  4. import java.util.Map;
  5. import java.util.Objects;
  6. import java.util.Set;
  7. import java.util.stream.Collectors;
  8. import java.util.stream.StreamSupport;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.security.core.annotation.AuthenticationPrincipal;
  11. import org.springframework.security.oauth2.jwt.Jwt;
  12. import org.springframework.web.bind.annotation.CrossOrigin;
  13. import org.springframework.web.bind.annotation.GetMapping;
  14. import org.springframework.web.bind.annotation.PathVariable;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import lombok.extern.slf4j.Slf4j;
  17. import ru.digitalbanana.demoresourceserver.persistence.model.UserEntity;
  18. import ru.digitalbanana.demoresourceserver.service.UserService;
  19. @Slf4j
  20. @CrossOrigin(origins = "*")
  21. @RestController
  22. public class UserInfoController {
  23. private final UserService userService;
  24. @Autowired
  25. public UserInfoController(final UserService userService) {
  26. this.userService = userService;
  27. }
  28. @GetMapping(value = "/userinfo")
  29. public String userinfo(@AuthenticationPrincipal Jwt principal) {
  30. return principal.getClaimAsString("email");
  31. }
  32. @GetMapping(value = "/users")
  33. public List<UserEntity> allUsers() {
  34. log.debug("Request all users");
  35. return StreamSupport
  36. .stream(userService.findAll().spliterator(), false)
  37. .filter(user -> user.getEmail() != null)
  38. .collect(Collectors.toList())
  39. ;
  40. }
  41. }