forked from kidgrow-microservices-platform

zhaoxiaohao
2020-10-30 6eb3693c10c41d36248a13636709d05d6a7a197b
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
package com.kidgrow.web.controller;
 
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
 
/**
 * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
 *
 * @Description: Security 配置<br>
 * @Project: <br>
 * @CreateDate: Created in 2020/3/04 10:25 <br>
 * @Author: <a href="4345453@kidgrow.com">liuke</a>
 */
@Controller
public class HomeController {
    @GetMapping("/")
    public String home(ModelMap modelMap, Authentication authentication) {
        OAuth2Authentication oauth2Authentication = (OAuth2Authentication)authentication;
        modelMap.put("username", oauth2Authentication.getName());
        modelMap.put("authorities", oauth2Authentication.getAuthorities());
        modelMap.put("clientId", oauth2Authentication.getOAuth2Request().getClientId());
        OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails)oauth2Authentication.getDetails();
        modelMap.put("token", details.getTokenValue());
        return "index";
    }
}