|
@@ -3,20 +3,22 @@ package com.ims.eval.service.impl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ims.common.utils.MD5Utils;
|
|
|
import com.ims.common.utils.RSAUtils;
|
|
|
import com.ims.common.utils.StringUtils;
|
|
|
import com.ims.eval.config.CustomException;
|
|
|
import com.ims.eval.config.ImaConfig;
|
|
|
-import com.ims.eval.entity.Myuser;
|
|
|
import com.ims.eval.dao.UserMapper;
|
|
|
+import com.ims.eval.entity.Myuser;
|
|
|
import com.ims.eval.entity.dto.response.MyuserResDTO;
|
|
|
import com.ims.eval.feign.RemoteServiceBuilder;
|
|
|
import com.ims.eval.service.IUserService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.http.*;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpMethod;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
@@ -24,10 +26,8 @@ import org.springframework.web.client.RestTemplate;
|
|
|
import springfox.documentation.annotations.Cacheable;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
import java.util.Base64;
|
|
|
import java.util.List;
|
|
|
-import java.util.concurrent.CompletionException;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -92,11 +92,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, Myuser> implements
|
|
|
@Cacheable(value = "user_code")
|
|
|
@Override
|
|
|
public MyuserResDTO getSysUser(String code) {
|
|
|
- try{
|
|
|
+ try {
|
|
|
Object json = remoteServiceBuilder.getGatewayUrl().getSysUser(code);
|
|
|
MyuserResDTO user = JSON.parseObject(json.toString(), MyuserResDTO.class);
|
|
|
return user;
|
|
|
- } catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
@@ -105,12 +105,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, Myuser> implements
|
|
|
public MyuserResDTO getSysUser(HttpServletRequest request) {
|
|
|
|
|
|
try {
|
|
|
- if(null == request.getHeader("code")){
|
|
|
+ if (null == request.getHeader("code")) {
|
|
|
throw new CustomException("请求鉴权信息为空");
|
|
|
}
|
|
|
String code = request.getHeader("code");
|
|
|
JSONObject json = remoteServiceBuilder.getGatewayUrl().getSysUser(code);
|
|
|
- MyuserResDTO user =JSONObject.parseObject(json.getJSONObject("data").toJSONString(), MyuserResDTO.class);
|
|
|
+ MyuserResDTO user = JSONObject.parseObject(json.getJSONObject("data").toJSONString(), MyuserResDTO.class);
|
|
|
return user;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
@@ -125,7 +125,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, Myuser> implements
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public JSONObject getbladeAuth(String tenantId, String username, String password, String grantType, String scope, String type) throws Exception {
|
|
|
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
|
|
@@ -142,7 +141,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, Myuser> implements
|
|
|
|
|
|
// 验证数字签名
|
|
|
boolean isValid = RSAUtils.verify(password.getBytes(), signature, RSAUtils.getKeyPair().getPublic());
|
|
|
- if(!isValid){
|
|
|
+ if (!isValid) {
|
|
|
throw new CustomException("登录密码验证错误");
|
|
|
}
|
|
|
|
|
@@ -151,21 +150,21 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, Myuser> implements
|
|
|
ResponseEntity<String> responseEntity2 = restTemplate.postForEntity(imaConfig.getGatewayUrl() + "blade-auth/oauth/token?tenantId={1}&username={2}&password={3}&grant_type={4}&scope={5}&type={6}",
|
|
|
param, String.class, tenantId, username, pwdstr, grantType, scope, type);
|
|
|
log.info("\n code:{}\n header:{}\n body:{}\n", responseEntity2.getStatusCodeValue(), responseEntity2.getHeaders(), responseEntity2.getBody());
|
|
|
- if(200== responseEntity2.getStatusCodeValue()){
|
|
|
+ if (200 == responseEntity2.getStatusCodeValue()) {
|
|
|
return JSON.parseObject(responseEntity2.getBody());
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public JSONObject pageList(Integer current, Integer size, String orgId, String idCard, String mobile, String no, String name, String loginName,HttpServletRequest request) {
|
|
|
+ public JSONObject pageList(Integer current, Integer size, String orgId, String idCard, String mobile, String no, String name, String loginName, HttpServletRequest request) {
|
|
|
|
|
|
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
|
|
|
- headers.add("Blade-Auth", "bearer "+request.getHeader("Blade-Auth"));
|
|
|
+ headers.add("Blade-Auth", "bearer " + request.getHeader("Blade-Auth"));
|
|
|
HttpEntity<LinkedMultiValueMap<String, Object>> param = new HttpEntity<>(null, headers);
|
|
|
|
|
|
ResponseEntity<String> responseEntity2 = restTemplate.exchange(imaConfig.getGatewayUrl() + "ims-idms/sysuser/page?current={1}&size={2}&orgId={3}&idCard={4}&mobile={5}&no={6}&name={7}&loginName={8}",
|
|
|
- HttpMethod.GET,param, String.class, current, size, orgId, idCard, mobile, no,name,loginName);
|
|
|
+ HttpMethod.GET, param, String.class, current, size, orgId, idCard, mobile, no, name, loginName);
|
|
|
|
|
|
log.info("\n code:{}\n header:{}\n body:{}\n", responseEntity2.getStatusCodeValue(), responseEntity2.getHeaders(), responseEntity2.getBody());
|
|
|
//
|
|
@@ -184,7 +183,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, Myuser> implements
|
|
|
headers.add("Content-Type", "application/x-www-form-urlencoded");
|
|
|
|
|
|
//固定字符串
|
|
|
- String auth ="c2FiZXI6NWMwMmMzZDViNzYxNTNkZGM5ZTczYzc5YzMzNzYzODAxNmE5ZDM2Ng==";
|
|
|
+ String auth = "c2FiZXI6NWMwMmMzZDViNzYxNTNkZGM5ZTczYzc5YzMzNzYzODAxNmE5ZDM2Ng==";
|
|
|
// 使用后端私钥解密数据
|
|
|
byte[] pwdData = RSAUtils.decrypt(Base64.getDecoder().decode(password.replaceAll(" ", "+")), RSAUtils.getKeyPair().getPrivate());
|
|
|
|
|
@@ -194,16 +193,29 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, Myuser> implements
|
|
|
|
|
|
// 验证数字签名
|
|
|
boolean isValid = RSAUtils.verify(password.getBytes(), signature, RSAUtils.getKeyPair().getPublic());
|
|
|
- if(!isValid){
|
|
|
+ if (!isValid) {
|
|
|
throw new CustomException("登录密码验证错误");
|
|
|
}
|
|
|
|
|
|
HttpEntity<LinkedMultiValueMap<String, Object>> param = new HttpEntity<>(null, headers);
|
|
|
|
|
|
ResponseEntity<String> responseEntity2 = restTemplate.postForEntity(imaConfig.getGatewayUrl() + "ims-idas/oauth/IToken?userInfo={1}&password={2}&auth={3}",
|
|
|
- param, String.class, username, pwdstr,auth);
|
|
|
+ param, String.class, username, pwdstr, auth);
|
|
|
log.info("\n code:{}\n header:{}\n body:{}\n", responseEntity2.getStatusCodeValue(), responseEntity2.getHeaders(), responseEntity2.getBody());
|
|
|
- if(200== responseEntity2.getStatusCodeValue()){
|
|
|
+ if (200 == responseEntity2.getStatusCodeValue()) {
|
|
|
+ return JSON.parseObject(responseEntity2.getBody());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject getLoginNameByUserInfo(String info, HttpServletRequest request) {
|
|
|
+ MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
|
|
|
+ headers.add("Authorization", "Basic " + request.getHeader("Blade-Auth"));
|
|
|
+ HttpEntity<LinkedMultiValueMap<String, Object>> param = new HttpEntity<>(null, headers);
|
|
|
+ ResponseEntity<String> responseEntity2 = restTemplate.exchange(imaConfig.getGateway2Url() + "api/ims-idms/sysuser/getLoginNameByUserInfo?info={1}", HttpMethod.GET, param, String.class, info);
|
|
|
+ log.info("\n code:{}\n header:{}\n body:{}\n", responseEntity2.getStatusCodeValue(), responseEntity2.getHeaders(), responseEntity2.getBody());
|
|
|
+ if (200 == responseEntity2.getStatusCodeValue()) {
|
|
|
return JSON.parseObject(responseEntity2.getBody());
|
|
|
}
|
|
|
return null;
|