|
|
@@ -1,54 +1,72 @@
|
|
|
-//package com.xunmei.auth.service;
|
|
|
-//
|
|
|
-//import cn.hutool.core.util.ObjectUtil;
|
|
|
-//import cn.hutool.json.JSONObject;
|
|
|
-//import com.xunmei.common.core.utils.StringUtils;
|
|
|
-//import io.netty.util.internal.StringUtil;
|
|
|
-//import lombok.extern.flogger.Flogger;
|
|
|
-//import org.apache.http.HttpEntity;
|
|
|
-//import org.apache.http.StatusLine;
|
|
|
-//import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
-//import org.apache.http.client.methods.HttpGet;
|
|
|
-//import org.apache.http.client.methods.HttpPost;
|
|
|
-//import org.apache.http.entity.StringEntity;
|
|
|
-//import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
-//import org.apache.http.impl.client.HttpClients;
|
|
|
-//import org.apache.http.message.BasicHeader;
|
|
|
-//import org.apache.http.protocol.HTTP;
|
|
|
-//import org.apache.http.util.EntityUtils;
|
|
|
-//import org.slf4j.ILoggerFactory;
|
|
|
-//import org.springframework.beans.factory.annotation.Value;
|
|
|
-//import org.springframework.stereotype.Component;
|
|
|
-//
|
|
|
-//import java.io.IOException;
|
|
|
-//import java.nio.charset.StandardCharsets;
|
|
|
-//import java.util.ArrayList;
|
|
|
-//import java.util.List;
|
|
|
-//
|
|
|
+package com.xunmei.auth.service;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import com.xunmei.common.core.constant.Constants;
|
|
|
+import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
+import com.xunmei.common.core.domain.R;
|
|
|
+import com.xunmei.common.core.exception.ServiceException;
|
|
|
+import com.xunmei.common.core.utils.StringUtils;
|
|
|
+import com.xunmei.system.api.RemoteLogService;
|
|
|
+import com.xunmei.system.api.RemoteUserService;
|
|
|
+import com.xunmei.system.api.model.LoginUser;
|
|
|
+import io.netty.util.internal.StringUtil;
|
|
|
+import lombok.extern.flogger.Flogger;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.http.HttpEntity;
|
|
|
+import org.apache.http.StatusLine;
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpGet;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
+import org.apache.http.message.BasicHeader;
|
|
|
+import org.apache.http.protocol.HTTP;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
+import org.slf4j.ILoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
//import com.union.api.TUnionTransInfo;
|
|
|
//import com.union.api.UnionEsscAPI;
|
|
|
-//
|
|
|
-//@Component
|
|
|
-//public class FJNXLoginService {
|
|
|
-// @Value("${fjnx.host}")
|
|
|
-// private String host;
|
|
|
-//
|
|
|
-// @Value("${fjnx.systemCode}")
|
|
|
-// private String systemCode;
|
|
|
-//
|
|
|
-// @Value("${fjnx.passIp}")
|
|
|
-// private String passIp;
|
|
|
-//
|
|
|
-// @Value("${fjnx.passPort}")
|
|
|
-// private String passPort;
|
|
|
-//
|
|
|
-// @Value("${fjnx.appCode}")
|
|
|
-// private String appCode;
|
|
|
-//
|
|
|
-// @Value("${fjnx.secretName}")
|
|
|
-// private String secretName;
|
|
|
-//
|
|
|
-// public String logingByPassword(String username, String password) {
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+@Component
|
|
|
+@ConditionalOnProperty(name = "loginPlatform", matchIfMissing = false, havingValue = "fjnx")
|
|
|
+public class FJNXLoginService implements LoginService {
|
|
|
+ @Value("${fjnx.host}")
|
|
|
+ private String host;
|
|
|
+
|
|
|
+ @Value("${fjnx.systemCode}")
|
|
|
+ private String systemCode;
|
|
|
+
|
|
|
+ @Value("${fjnx.passIp}")
|
|
|
+ private String passIp;
|
|
|
+
|
|
|
+ @Value("${fjnx.passPort}")
|
|
|
+ private String passPort;
|
|
|
+
|
|
|
+ @Value("${fjnx.appCode}")
|
|
|
+ private String appCode;
|
|
|
+
|
|
|
+ @Value("${fjnx.secretName}")
|
|
|
+ private String secretName;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private RemoteUserService remoteUserService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private SysRecordLogService recordLogService;
|
|
|
+
|
|
|
+// private String logingByPassword(String username, String password) {
|
|
|
// CloseableHttpClient client = null;
|
|
|
// try {
|
|
|
// List<String> ipList = new ArrayList<>();
|
|
|
@@ -61,21 +79,19 @@
|
|
|
// String pass = StringUtil.toHexString(password.getBytes());
|
|
|
// transInfo = shortApi.unionAPIServiceE160(1, secretName, "", 0, 1, pass, "", 1);
|
|
|
// if (ObjectUtil.isNull(transInfo)) {
|
|
|
-// return null;
|
|
|
+// throw new ServiceException("密码加密失败,返回对象为空");
|
|
|
// }
|
|
|
//
|
|
|
// if (ObjectUtil.notEqual(transInfo.getResponseCode(), 0) || ObjectUtil.notEqual(transInfo.getIsSucess(), 1)) {
|
|
|
-// logger.error("密码加密失败!" + transInfo.getResponseRemark());
|
|
|
-// return null;
|
|
|
+// throw new ServiceException("密码加密失败!" + transInfo.getResponseRemark());
|
|
|
// }
|
|
|
//
|
|
|
// if (ObjectUtil.isNull(transInfo.getReturnBode())) {
|
|
|
-// logger.error("密码加密失败,数据为空!");
|
|
|
-// return null;
|
|
|
+// throw new ServiceException("密码加密失败,数据为空!");
|
|
|
// }
|
|
|
//
|
|
|
// String url = host + "yusp-group/api/login?systemCode=" + systemCode;
|
|
|
-// logger.info(url);
|
|
|
+//
|
|
|
//
|
|
|
// HttpPost post = new HttpPost(url);
|
|
|
// client = HttpClients.createDefault();
|
|
|
@@ -92,12 +108,11 @@
|
|
|
// CloseableHttpResponse response = client.execute(post);
|
|
|
// HttpEntity entity = response.getEntity();
|
|
|
// if (ObjectUtil.isNull(entity)) {
|
|
|
-// logger.error("登录失败,返回数据为空!");
|
|
|
-// return null;
|
|
|
+// throw new ServiceException("登录失败,返回数据为空!");
|
|
|
// }
|
|
|
//
|
|
|
// String body = EntityUtils.toString(entity, "utf-8");
|
|
|
-// logger.warn("登录body返回:" + body);
|
|
|
+//// logger.warn("登录body返回:" + body);
|
|
|
// JSONObject jsonObject = new JSONObject(body);
|
|
|
// String code = jsonObject.getStr("code");
|
|
|
//
|
|
|
@@ -106,17 +121,13 @@
|
|
|
// JSONObject jsonObject1 = new JSONObject(data);
|
|
|
// String userStatus = jsonObject1.getStr("userStatus");
|
|
|
// String tokenThird = jsonObject1.getStr("token");
|
|
|
-// logger.info(tokenThird);
|
|
|
+//// logger.info(tokenThird);
|
|
|
// EntityUtils.consume(entity);
|
|
|
// response.close();
|
|
|
// return tokenThird;
|
|
|
// } else {
|
|
|
-// logger.error("登录失败," + jsonObject.getStr("message"));
|
|
|
-// return null;
|
|
|
+// throw new ServiceException("登录失败," + jsonObject.getStr("message"));
|
|
|
// }
|
|
|
-// } catch (Exception e) {
|
|
|
-// logger.error(e.getMessage());
|
|
|
-// return null;
|
|
|
// } finally {
|
|
|
// if (client != null) {
|
|
|
// try {
|
|
|
@@ -130,7 +141,8 @@
|
|
|
//
|
|
|
// }
|
|
|
//
|
|
|
-// public String loginByToken(String token) throws Exception {
|
|
|
+//
|
|
|
+// private String loginByToken(String token) throws Exception {
|
|
|
// String userName = "";
|
|
|
// CloseableHttpClient client = null;
|
|
|
//
|
|
|
@@ -147,7 +159,7 @@
|
|
|
// if (statusCode == 200) {
|
|
|
// if (entity != null) {
|
|
|
// String body = EntityUtils.toString(entity, "utf-8");
|
|
|
-// logger.warn(body);
|
|
|
+//// logger.warn(body);
|
|
|
// JSONObject jsonObject = new JSONObject(body);
|
|
|
// String code = jsonObject.getStr("code");
|
|
|
// if (StringUtils.isNotNull(code) && "0".equals(code)) {
|
|
|
@@ -159,19 +171,17 @@
|
|
|
// userName = loginName;
|
|
|
// }
|
|
|
// } else {
|
|
|
-// logger.warn("服务异常");
|
|
|
+// throw new ServiceException("服务异常");
|
|
|
// }
|
|
|
// }
|
|
|
// } else {
|
|
|
// if (statusCode == 401) {
|
|
|
-// logger.warn("无效的token");
|
|
|
+// throw new ServiceException("无效的token");
|
|
|
//
|
|
|
// } else {
|
|
|
-// logger.warn("调用单点登录失败");
|
|
|
+// throw new ServiceException("调用单点登录失败");
|
|
|
// }
|
|
|
// }
|
|
|
-// } catch (Exception e) {
|
|
|
-// logger.error("token登录错误:", e);
|
|
|
// } finally {
|
|
|
// if (client != null) {
|
|
|
// client.close();
|
|
|
@@ -180,4 +190,53 @@
|
|
|
//
|
|
|
// return userName;
|
|
|
// }
|
|
|
-//}
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public LoginUser loginByPassword(String username, String password, String platformType) {
|
|
|
+ //todo:
|
|
|
+ String token ="3459238452908345alsdfjalkdfjalskd"; // logingByPassword(username, password);
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(token)) {
|
|
|
+ throw new ServiceException("获取token为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
|
|
+ if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
|
|
|
+ recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在", platformType);
|
|
|
+ throw new ServiceException("登录用户:" + username + " 不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ LoginUser user = userResult.getData();
|
|
|
+ user.setToken(token);
|
|
|
+ user.setPlatformType(platformType);
|
|
|
+ recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功", platformType);
|
|
|
+
|
|
|
+ return user;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public LoginUser loginByToken(String token, String platformType) throws Exception {
|
|
|
+ //todo:
|
|
|
+ String username ="admin";// loginByToken(token);
|
|
|
+ R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
|
|
+ if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
|
|
|
+ recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在", platformType);
|
|
|
+ throw new ServiceException("登录用户:" + username + " 不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (R.FAIL == userResult.getCode()) {
|
|
|
+ throw new ServiceException(userResult.getMsg());
|
|
|
+ }
|
|
|
+ recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功", platformType);
|
|
|
+ LoginUser user = userResult.getData();
|
|
|
+ user.setToken(token);
|
|
|
+ user.setPlatformType(platformType);
|
|
|
+ return user;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void logout(String loginName, String platformType) {
|
|
|
+ recordLogService.recordLogininfor(loginName, Constants.LOGOUT, "退出成功", platformType);
|
|
|
+ }
|
|
|
+}
|