单点登录-修改

This commit is contained in:
liyawei
2022-03-18 19:13:39 +08:00
parent bebfae957a
commit ab9cd1fd20
@@ -12,13 +12,13 @@ import com.jero.common.system.vo.LoginUser;
import com.jero.common.util.RedisUtil;
import com.jero.common.util.oConvertUtils;
import com.jero.modules.base.service.BaseCommonService;
import com.jero.modules.opensso.URLRequestResultUtil;
import com.jero.modules.system.entity.SysDepart;
import com.jero.modules.system.entity.SysUser;
import com.jero.modules.system.service.ISysDepartService;
import com.jero.modules.system.service.ISysDictService;
import com.jero.modules.system.service.ISysLogService;
import com.jero.modules.system.service.ISysUserService;
import com.jero.modules.system.util.HttpRequestUtil;
import com.jero.modules.system.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -36,7 +36,6 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -104,12 +103,12 @@ public class SSOLoginController {
Result<JSONObject> result = new Result<JSONObject>();
// 获取access_token
String getAccessTokenUrl = accessTokenUrl + "?client_id=" + clientId + "&client_secret="
+ clientSecret + "&redirect_uri=" + redirectUri + "&code=" + URLEncoder.encode(code, "utf-8");
+ clientSecret + "&redirect_uri=" + redirectUri + "&code=" + code;
log.info("access_token_url:" + getAccessTokenUrl);
Map<String, String> headerMapToken = new HashMap<>();
headerMapToken.put("Content-Type", "text/html;charset=utf-8");
// String accessTokenResult = HttpRequestUtil.getResponseOfGET(accessTokenUrl, headerMapToken);
String accessTokenResult = URLRequestResultUtil.getProxyRequestResult(accessTokenUrl);
String accessTokenResult = HttpRequestUtil.getResponseOfGET(getAccessTokenUrl, headerMapToken);
// String accessTokenResult = URLRequestResultUtil.getProxyRequestResult(getAccessTokenUrl);
log.info("获取access_token返回结果:" + accessTokenResult);
// 返回结果:access_token=2.0N6OFCARTH7MRCVPSENQONSA67WGHV4FDR25TSHFCCXI6FA3NRVAA----&expires=602405
if(StringUtils.isEmpty(accessTokenResult) || !accessTokenResult.contains("access_token")){
@@ -121,12 +120,12 @@ public class SSOLoginController {
//https://signin-test.nio.com/oauth2/profile?access_token=2.0N6OFCARTH7MRCVPSENQONSA67WGHV4FDR25TSHFCCXI6FA3NRVAA----
//获取登录用户
String getProfileUrl = profileUrl + "?access_token=" + URLEncoder.encode(accessToken, "utf-8");
String getProfileUrl = profileUrl + "?access_token=" + accessToken;
log.info("profile_url:" + getProfileUrl);
Map<String, String> headerMapProfile = new HashMap<>();
headerMapProfile.put("Content-Type", "application/json; charset=utf-8");
// String profileResult = HttpRequestUtil.getResponseOfGET(getProfileUrl, headerMapProfile);
String profileResult = URLRequestResultUtil.getProxyRequestResult(getProfileUrl);
String profileResult = HttpRequestUtil.getResponseOfGET(getProfileUrl, headerMapProfile);
// String profileResult = URLRequestResultUtil.getProxyRequestResult(getProfileUrl);
log.info("获取profile返回结果:" + profileResult);
// 返回结果:{ id: "xuetao.li3.o", attributes: [{workNo: "CW19057"},{account_id: ""},{user_name: "xuetao.li3.o"},{email: "xuetao.li3.o@nio.com"}]}
JSONObject userThirdIdJson = JSONObject.parseObject(profileResult);