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 ""; } }*/