diff --git a/laws-base/laws-base-core/src/main/java/com/jero/common/es/JeroElasticsearchTemplate.java b/laws-base/laws-base-core/src/main/java/com/jero/common/es/JeroElasticsearchTemplate.java index b0f3d35c..e9932cd6 100644 --- a/laws-base/laws-base-core/src/main/java/com/jero/common/es/JeroElasticsearchTemplate.java +++ b/laws-base/laws-base-core/src/main/java/com/jero/common/es/JeroElasticsearchTemplate.java @@ -1,5 +1,6 @@ package com.jero.common.es; +import cn.hutool.http.HttpRequest; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; @@ -32,6 +33,11 @@ public class JeroElasticsearchTemplate { // ElasticSearch 最大可返回条目数 public static final int ES_MAX_SIZE = 10000; + @Value("${jero.elasticsearch.username}") + private String username; + @Value("${jero.elasticsearch.password}") + private String password; + public JeroElasticsearchTemplate(@Value("${jero.elasticsearch.cluster-nodes}") String baseUrl, @Value("${jero.elasticsearch.check-enabled}") boolean checkEnabled) { log.debug("JeroElasticsearchTemplate BaseURL:" + baseUrl); if (StringUtils.isNotEmpty(baseUrl)) { @@ -40,7 +46,11 @@ public class JeroElasticsearchTemplate { if (checkEnabled) { try { this.getElasticsearchVersion(); - RestUtil.get(this.getBaseUrl().toString()); + String basicAuth = this.getBasicAuth(); + HttpRequest.get(this.getBaseUrl().toString()) + .header("Authorization", basicAuth) + .execute() + .body(); log.info("ElasticSearch 服务连接成功"); log.info("ElasticSearch version: " + this.version); } catch (Exception e) { @@ -56,8 +66,12 @@ public class JeroElasticsearchTemplate { */ private void getElasticsearchVersion() { if (this.version == null) { - String url = this.getBaseUrl().toString(); - JSONObject result = RestUtil.get(url); + String basicAuth = this.getBasicAuth(); + String response = HttpRequest.get(this.getBaseUrl().toString()) + .header("Authorization", basicAuth) + .execute() + .body(); + JSONObject result = JSONObject.parseObject(response); if (result != null) { JSONObject v = result.getJSONObject("version"); this.version = v.getString("number"); @@ -65,6 +79,13 @@ public class JeroElasticsearchTemplate { } } + public String getBasicAuth(){ + String authString = username + ":" + password; + String encode = Base64.getEncoder().encodeToString(authString.getBytes()); + String authHeader = "Basic " + encode; + return authHeader; + } + public StringBuilder getBaseUrl(String indexName, String typeName) { typeName = typeName.trim().toLowerCase(); return this.getBaseUrl(indexName).append("/").append(typeName); @@ -79,6 +100,59 @@ public class JeroElasticsearchTemplate { return new StringBuilder("http://").append(this.baseUrl); } + /** + * cat 查询ElasticSearch系统数据,返回json + */ + public JSONArray _cat(String urlAfter) { + String url = this.getBaseUrl().append("/_cat").append(urlAfter).append("?").append(FORMAT_JSON).toString(); + String basicAuth = this.getBasicAuth(); + String response = HttpRequest.get(url) + .header("Authorization", basicAuth) + .execute() + .body(); + JSONArray jsonArray = JSONArray.parseArray(response); + return jsonArray; + } + + public JSONObject put(String url){ + String basicAuth = this.getBasicAuth(); + String response = HttpRequest.put(url) + .header("Authorization", basicAuth) + .execute() + .body(); + JSONObject jsonObject = JSONObject.parseObject(response); + return jsonObject; + } + public JSONObject put(String url, String params){ + String basicAuth = this.getBasicAuth(); + String response = HttpRequest.put(url) + .body(params) + .header("Authorization", basicAuth) + .execute() + .body(); + JSONObject jsonObject = JSONObject.parseObject(response); + return jsonObject; + } + public JSONObject post(String url, JSONObject params){ + String basicAuth = this.getBasicAuth(); + String response = HttpRequest.post(url) + .body(params.toJSONString()) + .header("Authorization", basicAuth) + .execute() + .body(); + JSONObject jsonObject = JSONObject.parseObject(response); + return jsonObject; + } + public JSONObject delete(String url){ + String basicAuth = this.getBasicAuth(); + String response = HttpRequest.delete(url) + .header("Authorization", basicAuth) + .execute() + .body(); + JSONObject jsonObject = JSONObject.parseObject(response); + return jsonObject; + } + /** * cat 查询ElasticSearch系统数据,返回json */ @@ -107,7 +181,7 @@ public class JeroElasticsearchTemplate { if (!StringUtils.isEmpty(indexName)) { urlAfter.append("/").append(indexName.trim().toLowerCase()); } - return _cat(urlAfter.toString(), JSONArray.class).getBody(); + return _cat(urlAfter.toString()); } /** @@ -139,7 +213,12 @@ public class JeroElasticsearchTemplate { public JSONObject getDataById(String indexName, String typeName, String dataId) { String url = this.getBaseUrl(indexName, typeName).append("/").append(dataId).toString(); log.info("url:" + url); - JSONObject result = RestUtil.get(url); + String basicAuth = this.getBasicAuth(); + String response = HttpRequest.get(this.getBaseUrl().toString()) + .header("Authorization", basicAuth) + .execute() + .body(); + JSONObject result = JSONObject.parseObject(response); boolean found = result.getBoolean("found"); if (found) { return result.getJSONObject("_source"); @@ -157,7 +236,7 @@ public class JeroElasticsearchTemplate { String url = this.getBaseUrl(indexName).toString(); try { - return RestUtil.put(url).getBoolean("acknowledged"); + return this.put(url).getBoolean("acknowledged"); } catch (org.springframework.web.client.HttpClientErrorException ex) { if (HttpStatus.BAD_REQUEST == ex.getStatusCode()) { log.warn("索引创建失败:" + indexName + " 已存在,无需再创建"); @@ -176,7 +255,7 @@ public class JeroElasticsearchTemplate { public boolean removeIndex(String indexName) { String url = this.getBaseUrl(indexName).toString(); try { - return RestUtil.delete(url).getBoolean("acknowledged"); + return this.delete(url).getBoolean("acknowledged"); } catch (org.springframework.web.client.HttpClientErrorException ex) { if (HttpStatus.NOT_FOUND == ex.getStatusCode()) { log.warn("索引删除失败:" + indexName + " 不存在,无需删除"); @@ -204,7 +283,13 @@ public class JeroElasticsearchTemplate { } log.info("getIndexMapping-url:" + url); try { - return RestUtil.get(url); + String basicAuth = this.getBasicAuth(); + String response = HttpRequest.get(this.getBaseUrl().toString()) + .header("Authorization", basicAuth) + .execute() + .body(); + JSONObject result = JSONObject.parseObject(response); + return result; } catch (org.springframework.web.client.HttpClientErrorException e) { String message = e.getMessage(); if (message != null && message.contains("404 Not Found")) { @@ -291,7 +376,7 @@ public class JeroElasticsearchTemplate { e.printStackTrace(); } try { - String result = RestUtil.put(url, data).getString("result"); + String result = this.put(url, data.toJSONString()).getString("result"); return "created".equals(result) || "updated".equals(result); } catch (Exception e) { log.error(e.getMessage() + "\n-- url: " + url + "\n-- data: " + data.toJSONString()); @@ -327,8 +412,7 @@ public class JeroElasticsearchTemplate { bodySB.append(data.toJSONString()).append("\n"); } log.info("+-+-+-: bodySB.toString(): " + bodySB.toString()); - HttpHeaders headers = RestUtil.getHeaderApplicationJson(); - RestUtil.request(url, HttpMethod.PUT, headers, null, bodySB, JSONObject.class); + this.put(url,bodySB.toString()); return true; } @@ -340,7 +424,7 @@ public class JeroElasticsearchTemplate { public boolean delete(String indexName, String typeName, String dataId) { String url = this.getBaseUrl(indexName, typeName).append("/").append(dataId).toString(); try { - return "deleted".equals(RestUtil.delete(url).getString("result")); + return "deleted".equals(this.delete(url).getString("result")); } catch (org.springframework.web.client.HttpClientErrorException ex) { if (HttpStatus.NOT_FOUND == ex.getStatusCode()) { return false; @@ -362,7 +446,7 @@ public class JeroElasticsearchTemplate { String url = this.getBaseUrl(indexName, typeName).append("/_search").toString(); log.info("url:" + url + " ,search: " + queryObject.toJSONString()); - JSONObject res = RestUtil.post(url, queryObject); + JSONObject res = this.post(url, queryObject); log.info("url:" + url + " ,return res: \n" + res.toJSONString()); return res; } @@ -486,7 +570,7 @@ public class JeroElasticsearchTemplate { String url = this.getBaseUrl(indexName, typeName).append("/_delete_by_query").toString(); log.info("url:" + url + " ,delete: " + queryObject.toJSONString()); - JSONObject res = RestUtil.post(url, queryObject); + JSONObject res = this.post(url, queryObject); log.info("url:" + url + " ,return res: \n" + res.toJSONString()); return res; } diff --git a/laws-module-system/src/main/java/com/jero/modules/system/service/impl/LoginServiceImpl.java b/laws-module-system/src/main/java/com/jero/modules/system/service/impl/LoginServiceImpl.java index 6c4e2c57..5c53b2ff 100644 --- a/laws-module-system/src/main/java/com/jero/modules/system/service/impl/LoginServiceImpl.java +++ b/laws-module-system/src/main/java/com/jero/modules/system/service/impl/LoginServiceImpl.java @@ -1,6 +1,7 @@ package com.jero.modules.system.service.impl; import cn.hutool.core.util.RandomUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.crypto.asymmetric.RSA; import com.alibaba.fastjson.JSONObject; import com.aliyuncs.exceptions.ClientException; @@ -94,22 +95,22 @@ public class LoginServiceImpl implements ILoginService { String rsaPublicKey = sysLoginModel.getRsaPublicKey(); String rsaPrivateKey = redisUtil.get(rsaPublicKey) != null ? String.valueOf(redisUtil.get(rsaPublicKey)) : null; - //if(StrUtil.isEmpty(rsaPrivateKey)){ - // return Result.error(CommonConstant.SC_RSA_TIMEOUT_600, "页面过期,将刷新页面"); - //} + if(StrUtil.isEmpty(rsaPrivateKey)){ + return Result.error(CommonConstant.SC_RSA_TIMEOUT_600, "页面过期,将刷新页面"); + } - //String captcha = sysLoginModel.getCaptcha(); - //if(captcha==null){ - // return Result.error("验证码无效"); - //} - //String lowerCaseCaptcha = captcha.toLowerCase(); - //String realKey = MD5Util.MD5Encode(lowerCaseCaptcha + sysLoginModel.getCheckKey(), UTF_8); - //Object checkCode = redisUtil.get(realKey); - //// 验证码前后端比较 - //if(checkCode == null || !checkCode.toString().equals(lowerCaseCaptcha)) { - // return Result.error("验证码错误"); - //} - //redisUtil.del(realKey); + String captcha = sysLoginModel.getCaptcha(); + if(captcha==null){ + return Result.error("验证码无效"); + } + String lowerCaseCaptcha = captcha.toLowerCase(); + String realKey = MD5Util.MD5Encode(lowerCaseCaptcha + sysLoginModel.getCheckKey(), UTF_8); + Object checkCode = redisUtil.get(realKey); + // 验证码前后端比较 + if(checkCode == null || !checkCode.toString().equals(lowerCaseCaptcha)) { + return Result.error("验证码错误"); + } + redisUtil.del(realKey); try { //解密获取密码和用户名 password = CommonUtils.decryptBtRsaPriKey(password, rsaPrivateKey); @@ -138,15 +139,15 @@ public class LoginServiceImpl implements ILoginService { return Result.error("密码错误次数过多,请15分钟后重试"); } //2. 校验用户名或密码是否正确 - //String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt()); - //String syspassword = sysUser.getPassword(); - //if (!syspassword.equals(userpassword)) { - // // 重试登录次数加一 - // retryCount++; - // this.setRetryInfoToRedis(username, retryCount); - // String msg = retryCount == RETRY_LOGIN_MAX_COUNT ? "密码错误次数过多,请稍后重试":"用户名或密码错误,剩余可登录次数:"+(RETRY_LOGIN_MAX_COUNT - retryCount); - // return Result.error(msg); - //} + String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt()); + String syspassword = sysUser.getPassword(); + if (!syspassword.equals(userpassword)) { + // 重试登录次数加一 + retryCount++; + this.setRetryInfoToRedis(username, retryCount); + String msg = retryCount == RETRY_LOGIN_MAX_COUNT ? "密码错误次数过多,请稍后重试":"用户名或密码错误,剩余可登录次数:"+(RETRY_LOGIN_MAX_COUNT - retryCount); + return Result.error(msg); + } //登录成功,清除错误登录次数 redisUtil.del(RETRY_LOGIN_PREFIX + username); if (checkSysPermission(username)) { diff --git a/laws-modules/src/main/java/com/jero/modules/laws/standard/service/impl/LawsTreeNodeServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/laws/standard/service/impl/LawsTreeNodeServiceImpl.java index 3a16c8f9..d9b3a92d 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/standard/service/impl/LawsTreeNodeServiceImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/standard/service/impl/LawsTreeNodeServiceImpl.java @@ -112,12 +112,14 @@ public class LawsTreeNodeServiceImpl extends ServiceImpl query = new LambdaQueryWrapper<>(); query.eq(LawsTreeNode::getNodeName, lawsTreeNode.getNodeName()); + query.eq(LawsTreeNode::getParentId, parentId); query.eq(LawsTreeNode::getModuleCode, lawsTreeNode.getModuleCode()); query.eq(LawsTreeNode::getDelFlag, CommonConstant.DEL_FLAG_0.toString()); List lawsTreeNodes = this.list(query); @@ -129,7 +131,6 @@ public class LawsTreeNodeServiceImpl extends ServiceImpl query = new LambdaQueryWrapper<>(); + query.eq(LawsTreeNode::getNodeName, lawsTreeNode.getNodeName()); + query.eq(LawsTreeNode::getParentId, parentId); + query.eq(LawsTreeNode::getModuleCode, lawsTreeNode.getModuleCode()); + query.eq(LawsTreeNode::getDelFlag, CommonConstant.DEL_FLAG_0.toString()); + query.ne(LawsTreeNode::getId,lawsTreeNode.getId()); + List lawsTreeNodes = this.list(query); + if (lawsTreeNodes != null && !lawsTreeNodes.isEmpty()) { + //TODO 翻译 + throw new JeroBootException("已存在名为" + lawsTreeNode.getNodeName() + "的节点"); + } this.updateById(lawsTreeNode); return true; } else { diff --git a/laws-single-startup/src/main/resources/application-dev.yml b/laws-single-startup/src/main/resources/application-dev.yml index e55115a9..e3be421d 100644 --- a/laws-single-startup/src/main/resources/application-dev.yml +++ b/laws-single-startup/src/main/resources/application-dev.yml @@ -259,6 +259,8 @@ jero: staticDomain: jerodev # ElasticSearch 6设置 elasticsearch: + username: grp + password: Grp2023.08 cluster-name: jero-ES cluster-nodes: 10.10.10.45:7900 check-enabled: false diff --git a/laws-single-startup/src/main/resources/application-test.yml b/laws-single-startup/src/main/resources/application-test.yml index bf6dd3e8..a63dd125 100644 --- a/laws-single-startup/src/main/resources/application-test.yml +++ b/laws-single-startup/src/main/resources/application-test.yml @@ -1,5 +1,5 @@ server: - port: 8080 + port: 8184 tomcat: max-swallow-size: -1 error: @@ -230,8 +230,10 @@ jero: staticDomain: jerodev # ElasticSearch 6设置 elasticsearch: + username: grp + password: Grp2023.08 cluster-name: jero-ES - cluster-nodes: 127.0.0.1:9200 + cluster-nodes: 10.186.43.11:9200 check-enabled: false # 表单设计器配置 desform: @@ -360,18 +362,20 @@ iam: # bimRemoteUser: bbcadmin # bimRemotePwd: P@ssw0rd bpmcAppkey: test + # 创建用户默认角色 + defaultRoleIds: 817f7f818bb3506e018bb3506ef70000 # Hiwork集成 hiwork: ip: http://task-test.sinotruk.com/ # 异构系统标识 - sysCode: test + sysCode: SRMS # 统一待办集成 todoUrl: taskapi/task.basedata/integrationCall/workflowIntegration # 统一消息集成 messageUrl: taskapi/task.basedata/notice/noticeCalls/send # 是否发送消息 - isSend: false + isSend: true # 汽车标准数字化平台ASMS asms: @@ -383,6 +387,7 @@ asms: # token过期时间(单位:小时) expire: 48 +# 单点登录配置(所有配置信息需要协调注册,现在都为假) # 单点登录配置(所有配置信息需要协调注册,现在都为假) oauth: # 客户端应用注册ID--客户申请的:SRMS @@ -391,12 +396,37 @@ oauth: clientSecret: 58a1001438de462193bec307826463c2 # 授权码验证 grantType: authorization_code - # 通过授权码获取accessToken请求地址 + # 通过授权码获取accessToken请求地址 https://iam-uat.sinotruk.com:7011 --> https://iam-uat-new.sinotruk.com accessTokenUrl: https://iam-uat.sinotruk.com:7011/idp/oauth2/getToken - # 通过accessToken获取账号信息请求地址 + # 通过accessToken获取账号信息请求地址 https://iam-uat.sinotruk.com:7011 --> https://iam-uat-new.sinotruk.com userInfoUrl: https://iam-uat.sinotruk.com:7011/idp/oauth2/getUserInfo # 防止跨站请求伪造(CSRF)标识(暂时不用) state: zhongQi # 起草部门部门名称 -draftDepartName: 流程与标准化 \ No newline at end of file +draftDepartName: 流程与标准化 +# 管理员权限roleCode,多填用英文逗号拼接 +adminRoleCode: admin + +# 文件下载加解密 +download: + enable: false + # 文件下载、预览拦截路径,多个以逗号分隔 + download_url: /sys/common/download/ + view_url: /sys/common/view/ + # 管理员角色 + admin_role_code: admin,BZGLY + # 加密参数 + encrypt: + url: http://10.2.159.90/intekey/encrypteFile + app_code: SRMS + secret_key: SRMS1234.. + # 解密参数 + decrypt: + url: http://10.2.159.90/intekey/file + app_code: SRMS + secret_key: SRMS1234.. + # 研发域 + scope_dev: 51 + # 办公域 + scope_work: 52 \ No newline at end of file