Browse Source

客户端携带鉴权

feature/big-screen
alex.sung 5 years ago
parent
commit
d453a5be06
  1. 18
      designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/solid/SolidCollectConstants.java
  2. 47
      designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/solid/SolidCollector.java

18
designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/solid/SolidCollectConstants.java

@ -0,0 +1,18 @@
package com.fr.design.mainframe.messagecollect.solid;
/**
* Created by alex sung on 2019/9/5.
*/
public class SolidCollectConstants {
private SolidCollectConstants(){}
/**
* 客户端请求subject
*/
public static final String REQUEST_SUBJECT = "solid";
/**
* 客户端请求超时鉴权时间默认1h失效
*/
public static final long TIME_OUT = 60 * 60 * 1000;
}

47
designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/solid/SolidCollector.java

@ -2,14 +2,21 @@ package com.fr.design.mainframe.messagecollect.solid;
import com.fr.general.CloudCenter; import com.fr.general.CloudCenter;
import com.fr.general.http.HttpToolbox; import com.fr.general.http.HttpToolbox;
import com.fr.json.JSON;
import com.fr.json.JSONFactory;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.security.JwtUtils;
import com.fr.stable.CommonUtils; import com.fr.stable.CommonUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static com.fr.design.mainframe.messagecollect.solid.SolidCollectConstants.REQUEST_SUBJECT;
import static com.fr.design.mainframe.messagecollect.solid.SolidCollectConstants.TIME_OUT;
/** /**
* 设计器固化信息回传类 * 设计器固化信息回传类
* Created by alex sung on 2019/8/22. * Created by alex sung on 2019/8/22.
@ -19,6 +26,7 @@ import java.util.Map;
public class SolidCollector { public class SolidCollector {
private static final String CONTENT_URL = "/v10/collect/solid"; private static final String CONTENT_URL = "/v10/collect/solid";
private static final String DELETE_URL = "/v10/collect/solid/delete"; private static final String DELETE_URL = "/v10/collect/solid/delete";
private static final String UNLOCK_URL = "/v10/collect/solid/unlock";
private static final String ATTR_CIPHER_TEXT = "cipherText"; private static final String ATTR_CIPHER_TEXT = "cipherText";
private static final String ATTR_SIGNATURE = "signature"; private static final String ATTR_SIGNATURE = "signature";
private static final String SOLID_UPLOAD_URL = CloudCenter.getInstance().acquireUrlByKind("design.solid"); private static final String SOLID_UPLOAD_URL = CloudCenter.getInstance().acquireUrlByKind("design.solid");
@ -40,19 +48,32 @@ public class SolidCollector {
* 回传文件给云中心并删除服务端本地文件 * 回传文件给云中心并删除服务端本地文件
*/ */
public void sendToCloudCenterAndDeleteFile() { public void sendToCloudCenterAndDeleteFile() {
if (WorkContext.getCurrent().isLocal()) {
return;
}
try { try {
String content = requestContent(); String content = requestContent();
if(StringUtils.isNotEmpty(content)){ if (StringUtils.isNotEmpty(content)) {
Map<String, Object> params = new HashMap<>(); String cipherText = JSONFactory.createJSON(JSON.OBJECT).optString("data");
params.put(ATTR_CIPHER_TEXT, requestContent()); if(StringUtils.isNotEmpty(cipherText)){
params.put(ATTR_SIGNATURE, String.valueOf(CommonUtils.signature())); Map<String, Object> params = new HashMap<>();
HttpToolbox.post(SOLID_UPLOAD_URL, params); params.put(ATTR_CIPHER_TEXT, cipherText);
params.put(ATTR_SIGNATURE, String.valueOf(CommonUtils.signature()));
HttpToolbox.post(SOLID_UPLOAD_URL, params);
String deleteUrl = WorkContext.getCurrent().getPath() + DELETE_URL; String deleteUrl = WorkContext.getCurrent().getPath() + DELETE_URL;
HttpToolbox.post(deleteUrl, new HashMap<String, Object>()); HttpToolbox.post(deleteUrl, getParams());
}
} }
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().info(e.getMessage(), e); FineLoggerFactory.getLogger().info(e.getMessage(), e);
} finally {
String unlockUrl = WorkContext.getCurrent().getPath() + UNLOCK_URL;
try {
HttpToolbox.post(unlockUrl, getParams());
} catch (IOException e) {
FineLoggerFactory.getLogger().warn(e.getMessage(), e);
}
} }
} }
@ -60,7 +81,15 @@ public class SolidCollector {
* 获取服务端固化文件内容 * 获取服务端固化文件内容
* @return 回传内容 * @return 回传内容
*/ */
public String requestContent() throws Exception{ public String requestContent() throws Exception {
return HttpToolbox.get(WorkContext.getCurrent().getPath() + CONTENT_URL); Map<String, String> params = new HashMap<String, String>();
params.put("token", JwtUtils.createDefaultJWT(REQUEST_SUBJECT, TIME_OUT));
return HttpToolbox.get(WorkContext.getCurrent().getPath() + CONTENT_URL, params);
}
private Map<String, Object> getParams() {
Map<String, Object> params = new HashMap<String, Object>();
params.put("token", JwtUtils.createDefaultJWT(REQUEST_SUBJECT, TIME_OUT));
return params;
} }
} }

Loading…
Cancel
Save