forked from NeilAlishev/SpringCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloController.java
More file actions
42 lines (35 loc) · 1.27 KB
/
HelloController.java
File metadata and controls
42 lines (35 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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 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")
public String showUserInfo() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
PersonDetails personDetails = (PersonDetails) authentication.getPrincipal();
System.out.println(personDetails.getPerson());
return "hello";
}
@GetMapping("/admin")
public String adminPage() {
adminService.doAdminStuff();
return "admin";
}
}