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