WSUserEditHandler.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package com.kingdee.shr.base.syssetting.web.handler;
  2. import com.kingdee.bos.BOSException;
  3. import com.kingdee.bos.Context;
  4. import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
  5. import com.kingdee.bos.util.BOSUuid;
  6. import com.kingdee.eas.base.permission.PermItemInfo;
  7. import com.kingdee.eas.common.EASBizException;
  8. import com.kingdee.shr.base.permission.api.service.SHRFunctionPermissionService;
  9. import com.kingdee.shr.base.syssetting.app.cache.PermItemURLCache;
  10. import com.kingdee.shr.base.syssetting.context.SHRContext;
  11. import com.kingdee.shr.base.syssetting.exception.SHRWebException;
  12. import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
  13. import com.kingdee.shr.base.syssetting.ml.SHRWebResource;
  14. import com.kingdee.shr.base.syssetting.util.FileOperateUtil;
  15. import com.kingdee.shr.base.syssetting.util.SHRSyssettingUtil;
  16. import com.kingdee.shr.websso.IWSUser;
  17. import com.kingdee.shr.websso.WSUserFactory;
  18. import com.kingdee.shr.websso.WSUserInfo;
  19. import com.kingdee.util.StringUtils;
  20. import com.kingdee.util.UuidException;
  21. import org.apache.log4j.Logger;
  22. import org.springframework.ui.ModelMap;
  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;
  25. import java.io.*;
  26. import java.util.Properties;
  27. /**
  28. * description: WSUserEditHandler <br>
  29. * date: 20/11/2025 ÉÏÎç 11:19 <br>
  30. * author: lhbj <br>
  31. * version: 1.0 <br>
  32. */
  33. public class WSUserEditHandler extends EditHandler {
  34. private static Logger logger = Logger.getLogger(WSUserEditHandler.class);
  35. public WSUserEditHandler() {
  36. }
  37. protected void beforeRender(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  38. WSUserInfo wsUser = (WSUserInfo)modelMap.get("model");
  39. if (wsUser != null && wsUser.getId() != null && !StringUtils.isEmpty(wsUser.getPasswd())) {
  40. String operateStatus = this.getOperateStatus(request, modelMap);
  41. if ("EDIT".equalsIgnoreCase(operateStatus)) {
  42. wsUser.setPasswd((String)null);
  43. } else {
  44. String bs = this.substitution(wsUser.getPasswd());
  45. wsUser.setPasswd(bs);
  46. }
  47. }
  48. super.beforeRender(request, response, modelMap);
  49. }
  50. public String downloadAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  51. String wsUserId = request.getParameter("billId");
  52. if (StringUtils.isEmpty(wsUserId)) {
  53. throw new ShrWebBizException(SHRWebResource.getString("com.kingdee.shr.base.syssetting.CommonserviceResource", "sdk_non_existent"));
  54. } else {
  55. File propFile = null;
  56. try {
  57. Context ctx = SHRContext.getInstance().getContext();
  58. String permItemUrl = "/dynamic.do?method=initalize#uri=com.kingdee.shr.websso.app.WSUser.form";
  59. PermItemInfo permItem = PermItemURLCache.getPermItemInfoByURL(ctx, permItemUrl);
  60. SHRFunctionPermissionService.checkCurrnetUserFunctionPermission(ctx, permItem);
  61. IWSUser instance = WSUserFactory.getRemoteInstance();
  62. WSUserInfo wsUser = (WSUserInfo)((WSUserInfo)instance.getValue(new ObjectUuidPK(BOSUuid.read(wsUserId))));
  63. String realPath = SHRSyssettingUtil.getShrPropertiesPath();
  64. StringBuffer sb = new StringBuffer();
  65. String zipPath = sb.append(realPath).append(File.separator).append("osf_ws_client").append(File.separator).toString();
  66. propFile = new File(zipPath + "userInfo.properties");
  67. if (!propFile.exists()) {
  68. propFile.createNewFile();
  69. }
  70. boolean isCloudServ = false;
  71. this.writePropFile(propFile, wsUser, isCloudServ);
  72. String userInfoP = "com/kingdee/shr/osf/webservice/client/userInfo.properties";
  73. FileOperateUtil.downloadSDK(zipPath, propFile, userInfoP, response);
  74. } catch (IOException var21) {
  75. logger.error(var21.getMessage());
  76. throw new SHRWebException(var21.getMessage(), var21);
  77. } catch (EASBizException var22) {
  78. throw new ShrWebBizException(SHRWebResource.getString("com.kingdee.shr.base.syssetting.CommonserviceResource", "download_fails"), var22);
  79. } catch (UuidException | BOSException var23) {
  80. throw new SHRWebException(var23.getMessage(), var23);
  81. } finally {
  82. if (propFile != null) {
  83. propFile.delete();
  84. }
  85. }
  86. return null;
  87. }
  88. }
  89. private void writePropFile(File propFile, WSUserInfo wsUser, boolean isCloudServ) throws ShrWebBizException {
  90. Properties prop = new Properties();
  91. prop.setProperty("easAddr", wsUser.getShrAddr());
  92. prop.setProperty("userName", wsUser.getUserName());
  93. String pwd = wsUser.getPasswd();
  94. prop.setProperty("password", pwd);
  95. prop.setProperty("dcName", wsUser.getDcName());
  96. prop.setProperty("slnName", wsUser.getSlnName());
  97. prop.setProperty("language", wsUser.getLanguage().getValue());
  98. prop.setProperty("dbType", (String)wsUser.get("dbtype"));
  99. if (isCloudServ) {
  100. prop.setProperty("isCloudServ", "true");
  101. }
  102. FileOutputStream fos = null;
  103. try {
  104. fos = new FileOutputStream(propFile, false);
  105. prop.store(fos, (String)null);
  106. } catch (FileNotFoundException var12) {
  107. throw new ShrWebBizException(SHRWebResource.getString("com.kingdee.shr.base.syssetting.CommonserviceResource", "api_user_config_non_exist"), var12);
  108. } catch (IOException var13) {
  109. throw new ShrWebBizException(SHRWebResource.getString("com.kingdee.shr.base.syssetting.CommonserviceResource", "api_user_config_add_fails"), var13);
  110. } finally {
  111. FileOperateUtil.closeStream(new Closeable[]{fos});
  112. }
  113. }
  114. private String substitution(String str) {
  115. int length = str.length();
  116. StringBuffer sb = new StringBuffer();
  117. for(int i = 0; i < length; ++i) {
  118. sb.append("*");
  119. }
  120. return sb.toString();
  121. }
  122. }