06.세션정보
세션
- JWT로 관리되지만 토큰 검증 시 일시적인 세션을 생성하게 된다
- 생성된 세션은 STATELESS 상태로 관리되기 때문에 요청이 끝나면 소멸한다
- UserController
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@GetMapping("/main")
public ModelAndView mainP(){
String username = SecurityContextHolder.getContext().getAuthentication().getName();
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
Iterator<? extends GrantedAuthority> iterator = authorities.iterator();
GrantedAuthority grantedAuthority = iterator.next();
String role = grantedAuthority.getAuthority();
mav = new ModelAndView("userMain");
mav.addObject("username", username);
mav.addObject("role", role);
return mav;
}
- userMain.mustache
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
userLoginMain
<br>
</body>
</html>
- 응답창에 username과 role이 출력된다