|
@@ -0,0 +1,153 @@
|
|
|
+package nckd.jimin.jyyy.bd.common.oauth;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
+import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
+import kd.bos.dataentity.resource.ResManager;
|
|
|
+import kd.bos.dc.api.model.Account;
|
|
|
+import kd.bos.entity.AppInfo;
|
|
|
+import kd.bos.entity.AppMetadataCache;
|
|
|
+import kd.bos.entity.param.AppParam;
|
|
|
+import kd.bos.exception.ErrorCode;
|
|
|
+import kd.bos.exception.KDException;
|
|
|
+import kd.bos.logging.Log;
|
|
|
+import kd.bos.logging.LogFactory;
|
|
|
+import kd.bos.login.thirdauth.app.AppAuthResult;
|
|
|
+import kd.bos.login.thirdauth.app.ThirdAppAuthtication;
|
|
|
+import kd.bos.login.thirdauth.app.UserType;
|
|
|
+import kd.bos.orm.query.QCP;
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
|
+import kd.bos.sdk.util.KHttpClientUtils;
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
+import kd.bos.servicehelper.parameter.SystemParamServiceHelper;
|
|
|
+import kd.bos.workflow.exception.WFErrorCode;
|
|
|
+import kd.bos.workflow.exception.WFMessageServiceException;
|
|
|
+import nckd.jimin.jyyy.bd.plugin.msg.ecology.HttpUtils;
|
|
|
+import org.apache.commons.codec.binary.Base64;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 泛微OA:E10单点登录拦截,验证token用户
|
|
|
+ * @author wanghaiwu_kd
|
|
|
+ * @date 2025/04/16
|
|
|
+ */
|
|
|
+public class FanWeiSSOAuthtication extends ThirdAppAuthtication {
|
|
|
+ private static Log logger = LogFactory.getLog(FanWeiSSOAuthtication.class);
|
|
|
+ /**
|
|
|
+ * 判断该接口请求是否需要通过此插件认证
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public boolean isNeedHandle(HttpServletRequest request, Account account) {
|
|
|
+ //加密的数据信息
|
|
|
+ String token = request.getParameter("eteams_token");
|
|
|
+ if(StringUtils.isNotBlank(token)){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *用户身份解析
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AppAuthResult appAuthtication(HttpServletRequest request, Account account) {
|
|
|
+ AppAuthResult result = new AppAuthResult();
|
|
|
+ result.setSucceed(false);
|
|
|
+ try{
|
|
|
+ //获取请求连接中的token
|
|
|
+ String token = request.getParameter("eteams_token");
|
|
|
+ if(StringUtils.isBlank(token)){
|
|
|
+ logger.info("FanWeiSSOAuthtication:eteams_token is null");
|
|
|
+
|
|
|
+ result.setErrorMessage("FanWeiSSOAuthtication:eteams_token is null");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ String selectField = "nckd_entryentity.nckd_key, nckd_entryentity.nckd_value";
|
|
|
+
|
|
|
+ QFilter qFilter = new QFilter("number", QCP.equals, "fanwei");
|
|
|
+ DynamicObject commonParam = BusinessDataServiceHelper.loadSingle("nckd_commonparams", selectField, qFilter.toArray());
|
|
|
+ if (ObjectUtils.isEmpty(commonParam)) {
|
|
|
+ logger.info("FanWeiSSOAuthtication:nckd_commonparams is null");
|
|
|
+
|
|
|
+ result.setErrorMessage("FanWeiSSOAuthtication:未配置泛微相关参数");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ DynamicObjectCollection entryentity = commonParam.getDynamicObjectCollection("nckd_entryentity");
|
|
|
+ Map<String, String> mapentity = entryentity.stream().collect(Collectors.toMap(k -> k.getString("nckd_key"), v -> v.getString("nckd_value")));
|
|
|
+
|
|
|
+ if(mapentity == null ){
|
|
|
+ logger.info("FanWeiSSOAuthtication:nckd_entryentity is null");
|
|
|
+
|
|
|
+ result.setErrorMessage("FanWeiSSOAuthtication:未配置泛微相关参数");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ String userUrl = mapentity.get("getuserinfo");
|
|
|
+ if(StringUtils.isEmpty(userUrl)){
|
|
|
+ logger.info("FanWeiSSOAuthtication:getuserinfo is null");
|
|
|
+
|
|
|
+ result.setErrorMessage("FanWeiSSOAuthtication:未配置泛微相关参数");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ String ssouser_dev = mapentity.get("ssouser_dev");
|
|
|
+ String user = "";
|
|
|
+
|
|
|
+// String apiResult = "";
|
|
|
+//
|
|
|
+// Map<String, String> header = new HashMap<>();
|
|
|
+// header.put("Content-Type", "application/json; charset=UTF-8");
|
|
|
+//
|
|
|
+// //获取token
|
|
|
+// try {
|
|
|
+// userUrl = userUrl + "?eteams_token=" + token;
|
|
|
+// logger.info("获取泛微用户url:" + userUrl);
|
|
|
+//
|
|
|
+// apiResult = KHttpClientUtils.postjson(userUrl, header, null);
|
|
|
+// } catch (IOException e) {
|
|
|
+// logger.info(e.getMessage());
|
|
|
+//
|
|
|
+// logger.info("FanWeiSSOAuthtication:getuserinfo fail");
|
|
|
+//
|
|
|
+// result.setErrorMessage("FanWeiSSOAuthtication:获取用户异常" + e.getMessage());
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(kd.bos.util.StringUtils.isEmpty(apiResult)){
|
|
|
+// logger.info("FanWeiSSOAuthtication:getuserinfo fail");
|
|
|
+//
|
|
|
+// result.setErrorMessage("FanWeiSSOAuthtication:获取用户异常");
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//
|
|
|
+// JSONObject userInfo = JSONObject.parseObject(apiResult);
|
|
|
+// if(userInfo.get("mobile") == null){
|
|
|
+// logger.info("FanWeiSSOAuthtication:getuserinfo fail");
|
|
|
+//
|
|
|
+// result.setErrorMessage("FanWeiSSOAuthtication:获取用户异常");
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(ssouser_dev)){
|
|
|
+ user = ssouser_dev;
|
|
|
+
|
|
|
+ }
|
|
|
+ result.setUserFlag(user);
|
|
|
+ result.setUserType(UserType.USER_NAME);
|
|
|
+ result.setSucceed(true);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+}
|