/
NikolayIvkin
/
tutorials1
Обзор
Документация
Войти
/
NikolayIvkin
/
tutorials1
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
libraries-security/src/main/java/com/baeldung/scribejava/controller/UserController.java
46 строк
1 KB
Gaetano Piazzolla
JAVA-28925 | Upgrade libraries-security to Spring Boot 3 (#15500)
30 дек 2023, 00:17
30 дек 2023, 00:17
f471384
Код
Авторство
О чём код?
package com.baeldung.scribejava.controller; import com.baeldung.scribejava.service.MyService; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import jakarta.servlet.http.HttpServletResponse; import java.security.Principal; @RestController(value = "/user") public class UserController { @Autowired private MyService service; @GetMapping("/me/myapi") public String me(@RequestParam String username, @RequestParam String password, HttpServletResponse responsehttp) { try { OAuth2AccessToken token = service.getService().getAccessTokenPasswordGrant(username, password); OAuthRequest request = new OAuthRequest(Verb.GET, "http://localhost:8080/me"); service.getService().signRequest(token, request); Response response = service.getService().execute(request); return response.getBody(); } catch (Exception e) { responsehttp.setStatus(HttpServletResponse.SC_BAD_REQUEST); } return null; } @GetMapping("/me") public Principal user(Principal principal) { return principal; } }