liuxiaolong
2019-05-06 f99bc8c6a1d10610373738edd7d0aa0181c81d99
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package com.cloud.common.utils;
 
import java.util.Map;
 
import com.cloud.model.sys.AppUser;
import com.cloud.model.sys.WechatUserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
//import org.springframework.security.oauth2.provider.OAuth2Authentication;
//import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;
 
import com.alibaba.fastjson.JSONObject;
import com.cloud.model.sys.LoginAppUser;
import org.springframework.stereotype.Service;
 
/**
 * @author lp
 * @date 2018-08-05
 */
/*public class AppUserUtil {
 
    @Autowired
    private static StringRedisTemplate stringRedisTemplate;
 
    *//**
     * 获取登陆的 LoginAppUser
     * 
     * @return
     *//*
    public static LoginAppUser getLoginAppUser() {
 
        String s_user = stringRedisTemplate.opsForValue().get("eea10e44-de5f-4af6-a43e-38c6644cc266");
 
        LoginAppUser user = JSONObject.parseObject(s_user, LoginAppUser.class);
       *//* LoginAppUser user = stringRedisTemplate.opsForValue().get(token);*//*
 
        //Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        //if (authentication instanceof OAuth2Authentication) {
        //    OAuth2Authentication oAuth2Auth = (OAuth2Authentication) authentication;
        //    authentication = oAuth2Auth.getUserAuthentication();
        //
        //    if (authentication instanceof UsernamePasswordAuthenticationToken) {
        //        UsernamePasswordAuthenticationToken authenticationToken = (UsernamePasswordAuthenticationToken) authentication;
        //        Map map = (Map) authenticationToken.getDetails();
        //        map = (Map) map.get("principal");
        //
        //        return JSONObject.parseObject(JSONObject.toJSONString(map), LoginAppUser.class);
        //    }
        //}
 
        return user;
    }
 
    *//**
     * 得到组织机构id的方法,没有返回,返回空串。
     * @return
     *//*
    public static String getOrgId() {
        LoginAppUser loginAppUser = AppUserUtil.getLoginAppUser();
        if (loginAppUser != null) {
            return loginAppUser.getOrgId()+"";
        }
        return "";
    }
 
    *//**
     * 得到当前登录人的名称的方法,没有返回,返回空串。
     * @return
     *//*
    public static String getUserName() {
        LoginAppUser loginAppUser = AppUserUtil.getLoginAppUser();
        if (loginAppUser != null) {
            return loginAppUser.getUsername()+"";
        }
        return "";
    }
    
    *//**
     * 得到access_token
     *//*
    public static String getAccessToken() {
        try {
            //Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
            //if (authentication instanceof OAuth2Authentication) {
            //    OAuth2Authentication oAuth2Auth = (OAuth2Authentication) authentication;
            //    authentication = oAuth2Auth.getUserAuthentication();
            //    OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails)oAuth2Auth.getDetails();
            //    System.out.println("token="+details.getTokenValue());
            //    return details.getTokenValue();
            //
            //}
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
    
}*/