package ru.digitalbanana.demoresourceserver.web.controller; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.StreamSupport; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.oauth2.jwt.Jwt; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; import lombok.extern.slf4j.Slf4j; import ru.digitalbanana.demoresourceserver.persistence.model.UserEntity; import ru.digitalbanana.demoresourceserver.service.UserService; @Slf4j @CrossOrigin(origins = "*") @RestController public class UserInfoController { private final UserService userService; @Autowired public UserInfoController(final UserService userService) { this.userService = userService; } @GetMapping(value = "/userinfo") public String userinfo(@AuthenticationPrincipal Jwt principal) { return principal.getClaimAsString("email"); } @GetMapping(value = "/users") public List allUsers() { log.debug("Request all users"); return StreamSupport .stream(userService.findAll().spliterator(), false) .filter(user -> user.getEmail() != null) .collect(Collectors.toList()) ; } }