update:第三方待办添加用户名后缀并加密,第三方点击可跳转至审批处理页面22

This commit is contained in:
luoluogit 2024-12-19 16:06:25 +08:00
parent 922ac72513
commit 2b89841beb
4 changed files with 80 additions and 10 deletions

View File

@ -13,6 +13,7 @@ import kd.bos.login.thirdauth.UserProperType;
import kd.bos.servicehelper.user.UserServiceHelper;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import shkd.sys.sys.utils.RSAUtil;
import shkd.sys.sys.utils.RSAUtils;
import javax.servlet.http.*;
@ -110,9 +111,8 @@ public class SSOPluginLogin implements ThirdSSOAuthHandler {
}
}else if (StringUtils.isNotEmpty(userName)){
try{
PrivateKey privateKey1 = RSAUtils.getPrivateKey(Base64.decodeBase64(RSAUtils.privateKey));
String sourceData = new String(RSAUtils.decryptByKey(privateKey1, Base64.decodeBase64(userName.getBytes())));
result.setUser(sourceData);
String user = RSAUtil.decrypt(userName,RSAUtil.getPrivateKeyFromString());
result.setUser(user);
result.setSucess(true);
logger.info("SSO用户登录成功进入苍穹系统");
}catch (Exception e){

View File

@ -21,6 +21,7 @@ import shkd.sys.sys.midservice.handler.CreateToDoHandler;
import shkd.sys.sys.midservice.handler.DealToDoHandler;
import shkd.sys.sys.midservice.handler.deleteToDoHandler;
import shkd.sys.sys.midservice.utils.GetUrlUtils;
import shkd.sys.sys.utils.RSAUtil;
import shkd.sys.sys.utils.RSAUtils;
import java.util.*;
@ -175,13 +176,11 @@ public class ToDoResendTack extends AbstractTask {
"phone,username", new QFilter[]{new QFilter("id", "=", next.getString("freceiveuserid"))});
String userName;
try {
userName = new String(org.apache.commons.codec.binary.Base64.encodeBase64(RSAUtils.encryptByKey(
RSAUtils.getPublicKey(Base64.decodeBase64(RSAUtils.publicKey)),
dynamicObject.getString("username").getBytes())));
userName = RSAUtil.decrypt(dynamicObject.getString("username"),RSAUtil.getPrivateKeyFromString());
}catch (Exception e){
ErrorCode errorCode = new ErrorCode("error_code", "公钥加密出现异常,请联系运维人员排查!");
throw new KDException(errorCode, e);
}// String number = dynamicObject.getString("number");
}
switch (t_status) {
case "0":
//标题

View File

@ -15,6 +15,7 @@ import org.apache.commons.codec.binary.Base64;
import shkd.sys.sys.midservice.handler.CreateToDoHandler;
import shkd.sys.sys.midservice.handler.DealToDoHandler;
import shkd.sys.sys.midservice.handler.deleteToDoHandler;
import shkd.sys.sys.utils.RSAUtil;
import shkd.sys.sys.utils.RSAUtils;
import java.util.List;
@ -45,9 +46,7 @@ public class BacklogServiceHandle extends AbstractServiceHandler {
for (DynamicObject query_one : query) {
String userName;
try {
userName = new String(Base64.encodeBase64(RSAUtils.encryptByKey(
RSAUtils.getPublicKey(Base64.decodeBase64(RSAUtils.publicKey)),
query_one.getString("username").getBytes())));
userName = RSAUtil.decrypt(query_one.getString("username"),RSAUtil.getPrivateKeyFromString());
}catch (Exception e){
ErrorCode errorCode = new ErrorCode("error_code", "公钥加密出现异常,请联系运维人员排查!");
throw new KDException(errorCode, e);

View File

@ -0,0 +1,72 @@
package shkd.sys.sys.utils;
import javax.crypto.Cipher;
import java.security.KeyFactory;
import java.security.PublicKey;
import java.security.PrivateKey;
import java.security.spec.X509EncodedKeySpec;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;
public class RSAUtil {
private static String key = "kingdee20241219";
/**
* 加密
*
* @param data 需加密的数据
* @param key 公钥
* @return 加密后的数据
* @throws Exception 异常
*/
public static String encrypt(String data, PublicKey key) throws Exception {
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encryptedBytes = cipher.doFinal(data.getBytes());
return Base64.getEncoder().encodeToString(encryptedBytes);
}
/**
* 解密
*
* @param data 需加密的数据
* @param key 私密
* @return 解密后的数据
* @throws Exception 异常
*/
public static String decrypt(String data, PrivateKey key) throws Exception {
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] original = cipher.doFinal(Base64.getDecoder().decode(data));
return new String(original);
}
/**
* 获取公钥
*
* @return 公钥
* @throws Exception 异常
*/
public static PublicKey getPublicKeyFromString() throws Exception {
byte[] keyBytes = Base64.getDecoder().decode(key);
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
return keyFactory.generatePublic(keySpec);
}
/**
* 获取秘钥
*
* @return 私钥
* @throws Exception 异常
*/
public static PrivateKey getPrivateKeyFromString() throws Exception {
byte[] keyBytes = Base64.getDecoder().decode(key);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
return keyFactory.generatePrivate(keySpec);
}
}