From ddcfd7cea6384e2bad2557acb10548398c8597a5 Mon Sep 17 00:00:00 2001 From: kerry Date: Fri, 18 Jun 2021 14:40:35 +0800 Subject: [PATCH 1/4] =?UTF-8?q?REPORT-53647=E3=80=90=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=A4=8D=E7=94=A8=E6=B6=89=E5=8F=8A=E5=88=B0=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD=E3=80=91=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E5=99=A8=E6=9C=AC=E8=BA=AB=E6=98=AF=E6=B2=A1=E6=9C=89=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E7=9A=84=EF=BC=8C=E6=8D=A2=E6=88=90=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=9A=84nightly=E5=90=8E=EF=BC=8C=E6=89=93=E5=BC=80=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E5=99=A8=E5=90=8E=E6=97=A0=E8=AE=BA=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E7=99=BB=E5=BD=95=EF=BC=8C=E4=B8=8B=E8=BD=BD=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E9=83=BD=E4=BC=9A=E6=8F=90=E7=A4=BA=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5@lanla?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/share/util/DownloadUtils.java | 60 +++++++++++++------ 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java b/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java index 93a8f73b0..7f9a379b5 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java @@ -1,9 +1,9 @@ package com.fr.design.mainframe.share.util; -import com.fr.config.MarketConfig; import com.fr.design.extra.PluginConstants; import com.fr.form.share.base.CancelCheck; import com.fr.form.share.constants.ShareComponentConstants; +import com.fr.ftp.util.Base64; import com.fr.general.CloudCenter; import com.fr.log.FineLoggerFactory; import com.fr.stable.ProductConstants; @@ -21,31 +21,27 @@ import com.fr.third.org.apache.http.impl.client.CloseableHttpClient; import com.fr.third.org.apache.http.impl.client.HttpClients; import org.jetbrains.annotations.NotNull; +import javax.crypto.Cipher; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.security.KeyFactory; +import java.security.interfaces.RSAPublicKey; +import java.security.spec.X509EncodedKeySpec; /** * created by Harrison on 2020/05/27 **/ public class DownloadUtils { - private static final String MARKET_LOGIN_URL = CloudCenter.getInstance().acquireUrlByKind("market.login"); private static final String REUSES_URL = CloudCenter.getInstance().acquireUrlByKind("af.reuseInfo") + "file/"; private static final String PACKAGE_REUSES_URL = CloudCenter.getInstance().acquireUrlByKind("af.reuseInfo") + "package/download/"; + private static final String CERTIFICATE_PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCtsz62CPSWXZE/IYZRiAuTSZkw\n" + + "1WOwer8+JFktK0uKLAUuQoBr+UjAMFtRA8W7JgKMDwZy/2liEAiXEOSPU/hrdV8D\n" + + "tT541LnGi1X/hXiRwuttPWYN3L2GYm/d5blU+FBNwghBIrdAxXTzYBc6P4KL/oYX\n" + + "nMdTIrkz8tYkG3QoFQIDAQAB"; - public static boolean login(CloseableHttpClient client) throws Exception { - - HttpUriRequest login = RequestBuilder.post() - .setUri(MARKET_LOGIN_URL) - .setHeader("User-Agent", "Mozilla/5.0") - .addParameter("username", MarketConfig.getInstance().getBbsUsername()) - .addParameter("password", MarketConfig.getInstance().getBbsPassword()) - .build(); - CloseableHttpResponse loginResponse = client.execute(login); - return loginResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK; - } - private static CloseableHttpClient createClient() { BasicCookieStore cookieStore = new BasicCookieStore(); @@ -59,8 +55,10 @@ public class DownloadUtils { @NotNull public static String download(String id, String fileName, com.fr.design.extra.Process process) throws Exception { CloseableHttpResponse fileRes = getHttpResponse(REUSES_URL, id); + if (fileRes.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) { + fileRes = getHttpResponse(fileRes.getHeaders("Location")[0].getValue()); + } if (fileRes.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { - String realPath = StableUtils.pathJoin(ProductConstants.getEnvHome(), ShareComponentConstants.PLUGIN_CACHE, ShareComponentConstants.DOWNLOAD_SHARE); String filePath; @@ -95,7 +93,9 @@ public class DownloadUtils { public static String downloadPackage(String id, String fileName, CancelCheck cancelCheck) throws Exception { CloseableHttpResponse fileRes = getHttpResponse(PACKAGE_REUSES_URL, id); - + if (fileRes.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) { + fileRes = getHttpResponse(fileRes.getHeaders("Location")[0].getValue()); + } String realPath = StableUtils.pathJoin(ProductConstants.getEnvHome(), ShareComponentConstants.PLUGIN_CACHE, ShareComponentConstants.DOWNLOAD_PACKAGE_SHARE); String filePath; if (fileRes.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { @@ -133,11 +133,35 @@ public class DownloadUtils { //先登录一下。不然可能失败 CloseableHttpClient client = createClient(); FineLoggerFactory.getLogger().info("login fr-market"); - login(client); FineLoggerFactory.getLogger().info("start download widget {}", id); + HttpUriRequest file = RequestBuilder.post() + .setHeader("User-Agent", "Mozilla/5.0") + .setUri(url).addParameter("id", encrypt(id)) + .build(); + return client.execute(file); + } + + + private static CloseableHttpResponse getHttpResponse(String url) throws Exception { + //先登录一下。不然可能失败 + CloseableHttpClient client = createClient(); HttpUriRequest file = RequestBuilder.get() - .setUri(url + id) + .setUri(url) .build(); return client.execute(file); } + + + private static String encrypt(String str) throws Exception { + //base64编码的公钥 + byte[] decoded = Base64.decodeBase64(CERTIFICATE_PUBLIC_KEY); + RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded)); + //RSA加密 + Cipher cipher = Cipher.getInstance("RSA"); + cipher.init(Cipher.ENCRYPT_MODE, pubKey); + String outStr = Base64.encodeBase64String(cipher.doFinal(str.getBytes(StandardCharsets.UTF_8))); + return outStr; + } + + } From 2bd3625d692b717982573762d3a1a51a80b65f1b Mon Sep 17 00:00:00 2001 From: kerry Date: Fri, 18 Jun 2021 15:39:30 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0username=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/mainframe/share/util/DownloadUtils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java b/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java index 7f9a379b5..e415f0055 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java @@ -1,5 +1,6 @@ package com.fr.design.mainframe.share.util; +import com.fr.design.DesignerEnvManager; import com.fr.design.extra.PluginConstants; import com.fr.form.share.base.CancelCheck; import com.fr.form.share.constants.ShareComponentConstants; @@ -136,7 +137,8 @@ public class DownloadUtils { FineLoggerFactory.getLogger().info("start download widget {}", id); HttpUriRequest file = RequestBuilder.post() .setHeader("User-Agent", "Mozilla/5.0") - .setUri(url).addParameter("id", encrypt(id)) + .setUri(url).addParameter("id", encrypt(id)).addParameter("username", + DesignerEnvManager.getEnvManager().getDesignerLoginUsername() ) .build(); return client.execute(file); } From cc792aae6bce6712722897bc31bd848fc6a3b25f Mon Sep 17 00:00:00 2001 From: kerry Date: Fri, 18 Jun 2021 15:49:57 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/mainframe/share/util/DownloadUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java b/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java index e415f0055..499c70156 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java @@ -137,7 +137,7 @@ public class DownloadUtils { FineLoggerFactory.getLogger().info("start download widget {}", id); HttpUriRequest file = RequestBuilder.post() .setHeader("User-Agent", "Mozilla/5.0") - .setUri(url).addParameter("id", encrypt(id)).addParameter("username", + .setUri(url).addParameter("id", encrypt(id)).addParameter("userId", DesignerEnvManager.getEnvManager().getDesignerLoginUsername() ) .build(); return client.execute(file); From 52663464441fc47d316c7fd58cddf94584b7d3e2 Mon Sep 17 00:00:00 2001 From: kerry Date: Fri, 18 Jun 2021 16:15:20 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/mainframe/share/util/DownloadUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java b/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java index 499c70156..2b4dc70c3 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java @@ -138,7 +138,7 @@ public class DownloadUtils { HttpUriRequest file = RequestBuilder.post() .setHeader("User-Agent", "Mozilla/5.0") .setUri(url).addParameter("id", encrypt(id)).addParameter("userId", - DesignerEnvManager.getEnvManager().getDesignerLoginUsername() ) + String.valueOf(DesignerEnvManager.getEnvManager().getDesignerLoginUid())) .build(); return client.execute(file); }