|
package ru.digitalbanana.demoresourceserver.web.controller;
|
|
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.slf4j.Logger;
|
|
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 ru.digitalbanana.demoresourceserver.persistence.model.UserEntity;
|
|
import ru.digitalbanana.demoresourceserver.service.UserService;
|
|
|
|
@CrossOrigin(origins = "*")
|
|
@RestController
|
|
public class UserInfoController {
|
|
|
|
private final UserService userService;
|
|
|
|
private final Logger logger;
|
|
|
|
@Autowired
|
|
public UserInfoController(final Logger logger, final UserService userService) {
|
|
this.logger = logger;
|
|
this.userService = userService;
|
|
}
|
|
|
|
@GetMapping(value = "/userinfo")
|
|
public Map<String, Object> getUser(@AuthenticationPrincipal Jwt principal) {
|
|
return Collections.singletonMap("user_name", 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);
|
|
}
|
|
|
|
}
|