/
Hipahopa808
/
SpringCourse
Обзор
Документация
Войти
/
Hipahopa808
/
SpringCourse
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
JWTApp/src/main/java/ru/alishev/springcourse/FirstSecurityApp/controllers/HelloController.java
43 строки
1 KB
Neil Alishev
Add JWT App
20 фев 2022, 14:54
20 фев 2022, 14:54
3ad9194
Код
Авторство
О чём код?
package ru.alishev.springcourse.FirstSecurityApp.controllers; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody; import ru.alishev.springcourse.FirstSecurityApp.security.PersonDetails; import ru.alishev.springcourse.FirstSecurityApp.services.AdminService; /** * @author Neil Alishev */ @Controller public class HelloController { private final AdminService adminService; @Autowired public HelloController(AdminService adminService) { this.adminService = adminService; } @GetMapping("/hello") public String sayHello() { return "hello"; } @GetMapping("/showUserInfo") @ResponseBody public String showUserInfo() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); PersonDetails personDetails = (PersonDetails) authentication.getPrincipal(); return personDetails.getUsername(); } @GetMapping("/admin") public String adminPage() { adminService.doAdminStuff(); return "admin"; } }