文档拆分条款-导入拆分结果

This commit is contained in:
liyawei
2022-04-01 09:08:46 +08:00
parent 314a0aa9e6
commit 2af0c7beae
8 changed files with 509 additions and 173 deletions
@@ -1,56 +0,0 @@
package com.jero.modules.opensso;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
/**
* @Description
* @Author liyawei
* @Create 2021/8/17
*/
public class URLRequestResultUtil {
public static String getProxyRequestResult(String url) {
StringBuffer requestResult = new StringBuffer();
BufferedReader in = null;
try {
System.out.println(url);
URL realUrl = new URL(url);
// 打开和URL之间的连接
URLConnection connection = realUrl.openConnection();
// 设置通用的请求属性
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
// 建立实际的连接
connection.connect();
// 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(
connection.getInputStream(), "utf-8"));
String line;
while ((line = in.readLine()) != null) {
requestResult.append(line);
}
}
// 使用finally块来关闭输入流
catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return requestResult.toString();
}
}
@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jero.common.api.vo.Result;
import com.jero.common.aspect.annotation.AutoLog;
import com.jero.common.constant.CommonConstant;
import com.jero.common.system.api.ISysBaseAPI;
import com.jero.common.system.util.JwtUtil;
import com.jero.common.system.vo.LoginUser;
import com.jero.common.util.RedisUtil;
@@ -16,9 +15,7 @@ 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;
@@ -30,7 +27,6 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@@ -53,10 +49,6 @@ public class SSOLoginController {
@Autowired
private ISysUserService sysUserService;
@Autowired
private ISysBaseAPI sysBaseAPI;
@Autowired
private ISysLogService logService;
@Autowired
private RedisUtil redisUtil;
@Autowired
private ISysDepartService sysDepartService;
@@ -64,8 +56,6 @@ public class SSOLoginController {
private ISysDictService sysDictService;
@Resource
private BaseCommonService baseCommonService;
@Autowired
private RestTemplate restTemplate;
private static final String BASE_CHECK_CODES = "qwertyuiplkjhgfdsazxcvbnmQWERTYUPLKJHGFDSAZXCVBNM1234567890";
//密码登录错误的次数前缀
@@ -73,10 +63,14 @@ public class SSOLoginController {
//密码登录错误的最大限制次数
public static final int RETRY_LOGIN_MAX_COUNT = 5;
private String accessTokenUrl = "https://signin-test.nio.com/oauth2/accessToken";
private String profileUrl = "https://signin-test.nio.com/oauth2/profile";
private String clientId = "100679";
private String clientSecret = "CDf2D9404C6ac1B0f7c3e3845ae0282a";
@Value("${opensso.accessTokenUrl}")
private String accessTokenUrl;
@Value("${opensso.profileUrl}")
private String profileUrl;
@Value("${opensso.clientId}")
private String clientId;
@Value("${opensso.clientSecret}")
private String clientSecret;
@Value("${opensso.redirectUri}")
private String redirectUri;
@@ -94,7 +88,9 @@ public class SSOLoginController {
}
}
//https://signin-test.nio.com/oauth2/authorize?client_id=100679&redirect_uri=http%3A%2F%2F139.9.235.66%3A8008%2Fjero-boot%2Fopensso%2Fcallback&response_type=code
//https://signin-test.nio.com/oauth2/authorize?client_id=100679&redirect_uri=http%3A%2F%2F139.9.235.66%3A8010&response_type=code
//http://139.9.235.66:8010
@AutoLog(value = "单点登录回调")
@ApiOperation(value = "单点登录回调", notes = "单点登录回调")
@GetMapping(value = "/callback")
@@ -107,8 +103,8 @@ public class SSOLoginController {
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(getAccessTokenUrl, headerMapToken);
// String accessTokenResult = URLRequestResultUtil.getProxyRequestResult(getAccessTokenUrl);
// String accessTokenResult = HttpRequestUtil.getResponseOfGET(getAccessTokenUrl, headerMapToken);
String accessTokenResult = "access_token=2.0N6OFCARTH7MRCVPSENQONSA67WGHV4FDR25TSHFCCXI6FA3NRVAA----&expires=602405";
log.info("获取access_token返回结果:" + accessTokenResult);
// 返回结果:access_token=2.0N6OFCARTH7MRCVPSENQONSA67WGHV4FDR25TSHFCCXI6FA3NRVAA----&expires=602405
if(StringUtils.isEmpty(accessTokenResult) || !accessTokenResult.contains("access_token")){
@@ -124,10 +120,10 @@ public class SSOLoginController {
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 = "{ id: \"chengjun.wang.o\", attributes: [{workNo: \"\"},{account_id: \"\"},{user_name: \"chengjun.wang.o\"},{email: \"chengjun.wang.o@nio.com\"}]}";
log.info("获取profile返回结果:" + profileResult);
// 返回结果:{ id: "xuetao.li3.o", attributes: [{workNo: "CW19057"},{account_id: ""},{user_name: "xuetao.li3.o"},{email: "xuetao.li3.o@nio.com"}]}
// 返回结果:{ id: "chengjun.wang.o", attributes: [{workNo: ""},{account_id: ""},{user_name: "chengjun.wang.o"},{email: "chengjun.wang.o@nio.com"}]}
JSONObject userThirdIdJson = JSONObject.parseObject(profileResult);
if(ObjectUtil.isEmpty(userThirdIdJson) || !userThirdIdJson.containsKey("id")){
return Result.error("【单点登录】获取用户profile失败");