|
@@ -2,6 +2,7 @@ package com.bowintek.practice.controller;
|
|
|
|
|
|
import com.alibaba.druid.support.logging.Log;
|
|
|
import com.alibaba.druid.support.logging.LogFactory;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.bowintek.practice.AppConfig;
|
|
|
import com.bowintek.practice.filter.exception.*;
|
|
|
import com.bowintek.practice.model.SysUser;
|
|
@@ -21,6 +22,7 @@ import java.net.URLDecoder;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
@@ -54,7 +56,7 @@ public class OAuthController {
|
|
|
@GetMapping("/getOAuthUrl")
|
|
|
public BaseResponse<String> getOAuthUrl(String appType, String oauthType) {
|
|
|
String url = "";
|
|
|
- String serviceUrl = "web".equals(appType) ? appConfig.oauthconfig_webServiceUrl : appConfig.oauthconfig_mobileServiceUrl;
|
|
|
+ /* String serviceUrl = "web".equals(appType) ? appConfig.oauthconfig_webServiceUrl : appConfig.oauthconfig_mobileServiceUrl;
|
|
|
if ("oauth".equals(oauthType)) {
|
|
|
url = appConfig.oauthconfig_oauthUrl + "/auth/oauth/authorize?";
|
|
|
url += "response_type=code";
|
|
@@ -72,7 +74,7 @@ public class OAuthController {
|
|
|
url += "service=" + serviceUrl;
|
|
|
|
|
|
log.info("getOAuthUrl-cas:" + "appType:" + appType + ",url:" + url);
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
|
|
|
return RespGenerstor.success(url);
|
|
@@ -102,60 +104,29 @@ public class OAuthController {
|
|
|
}
|
|
|
|
|
|
@GetMapping("/oauthLogin")
|
|
|
- public BaseResponse<String> oauthLogin(String appType, String type, String token, String ticket, String tm) {
|
|
|
- log.info("oauthLogin:ticket " + ticket + " , tm " + tm + " , appType " + appType+ " , type " + type);
|
|
|
+ public BaseResponse<String> oauthLogin(String type, String token, String tm) {
|
|
|
+ log.info("oauthLogin:ticket , tm " + tm + " , type " + type);
|
|
|
|
|
|
String userCode = "";
|
|
|
- String serviceUrl = "web".equals(appType) ? appConfig.oauthconfig_webServiceUrl : appConfig.oauthconfig_mobileServiceUrl;
|
|
|
-
|
|
|
- if (!stringUtils.IsNullOrEmpty(tm)) {
|
|
|
- ticket = URLDecoder.decode(ticket);
|
|
|
- tm = URLDecoder.decode(tm);
|
|
|
- if (stringUtils.IsNullOrEmpty(ticket))
|
|
|
- return RespGenerstor.success(false);
|
|
|
-
|
|
|
- LocalDateTime expireDate = dateUtils.DateToDateTime(dateUtils.StrToDate(tm, "yyyy/MM/dd HH:mm:ss"));
|
|
|
- if (LocalDateTime.now().compareTo(expireDate) > 0)
|
|
|
- return RespGenerstor.success(false);
|
|
|
-
|
|
|
- userCode = desUtils.decoder(ticket, expireDate);
|
|
|
- } else {
|
|
|
- if ("oauth".equals(type)) {
|
|
|
- String reData;
|
|
|
- Map<String, String> getParams = new HashMap<>();
|
|
|
- getParams.put("access_token", token);
|
|
|
-
|
|
|
- log.info("getUserInfo-oauth:access_token " + token);
|
|
|
|
|
|
- reData = remoteHelper.getJson(getParams, appConfig.oauthconfig_oauthUrl + "/user/get_user_info", "UTF-8");
|
|
|
-
|
|
|
- log.info("getUserInfo-oauth:result " + reData);
|
|
|
-
|
|
|
- JsonNode result = jsonMapper.jsonToObject(reData, JsonNode.class);
|
|
|
-
|
|
|
- if (result != null && result.get("code") != null && "1".equals(result.get("code").toString()) && result.get("data") != null) {
|
|
|
- userCode = result.get("data").get("user_code") != null ? result.get("data").get("user_code").toString() : "";
|
|
|
- }
|
|
|
+ String reData;
|
|
|
+ Map<String, String> getParams = new HashMap<>();
|
|
|
+ getParams.put("Authorization", "Bearer ${token}");
|
|
|
|
|
|
- } else {
|
|
|
- String reData;
|
|
|
- Map<String, String> getParams = new HashMap<>();
|
|
|
- getParams.put("service", serviceUrl);
|
|
|
- getParams.put("ticket", ticket);
|
|
|
|
|
|
- log.info("getUserInfo-cas:ticket " + ticket);
|
|
|
+ reData = remoteHelper.getJson( new HashMap<>(), appConfig.oauthconfig_oauthUrl + "/api/account/testpost", "UTF-8", getParams);
|
|
|
|
|
|
- reData = remoteHelper.getJson(getParams, appConfig.oauthconfig_oauthUrl + "/auth/cas/p3/serviceValidate", "UTF-8");
|
|
|
+ log.info("getUserInfo-cas:result " + reData);
|
|
|
|
|
|
- log.info("getUserInfo-cas:result " + reData);
|
|
|
+ JSONObject jsonData = JSONObject.parseObject(reData);
|
|
|
|
|
|
- if (reData.indexOf("cas:authenticationSuccess") >= 0 && reData.indexOf("cas:user_code") >= 0) {
|
|
|
- userCode = reData.split("<cas:user_code>")[1].split("</cas:user_code>")[0];
|
|
|
- }
|
|
|
- }
|
|
|
+ if (!"success".equals(jsonData.getString("code"))) {
|
|
|
+ log.info("登录失败:" + jsonData.getString("msg"));
|
|
|
+ return RespGenerstor.success(false);
|
|
|
}
|
|
|
+ userCode = jsonData.getJSONObject("data").getString("id");
|
|
|
|
|
|
- log.info("oauthLogin:ticket " + ticket + " , userCode " + userCode);
|
|
|
+ log.info("oauthLogin:token " + token + " , userCode " + userCode);
|
|
|
|
|
|
if (stringUtils.IsNullOrEmpty(userCode))
|
|
|
return RespGenerstor.success(false);
|
|
@@ -167,10 +138,10 @@ public class OAuthController {
|
|
|
|
|
|
UserModel user = accountService.getUserByUserID(userID);
|
|
|
user.token = TokenUtils.sign(user.getUserId() + '|' + user.getUserTypeId());
|
|
|
- user.dataRangeList = userService.getUserDataRange(user.getUserId());
|
|
|
+ user.dataRangeList =new ArrayList<>();
|
|
|
user.permissionList = accountService.getUserPerms(user.getUserId());
|
|
|
|
|
|
- logService.save("登录","","单点登录",user.userId);
|
|
|
+ logService.save("登录", "", "单点登录", user.userId);
|
|
|
|
|
|
return RespGenerstor.success(user);
|
|
|
|