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.
 
 
 
 
 

43 lines
1.5 KiB

package ru.digitalbanana.demoresourceserver.web.controller;
import java.util.Collections;
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 reactor.core.publisher.Flux;
import ru.digitalbanana.demoresourceserver.persistence.model.UserEntity;
import ru.digitalbanana.demoresourceserver.service.UserService;
@CrossOrigin
@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 Flux<UserEntity> getMethodName(@PathVariable String email) {
logger.debug("Request user by email {}", email);
return userService.findByEmail(email);
}
}