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.

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