use of com.workoss.boot.storage.model.StorageSignature in project boot by workoss.
the class StorageServiceFilter method sign.
private void sign(String clientKey, String key, String mimeType, String successActionStatus, HttpServletResponse response) {
try {
StorageClient storageClient = null;
if (StringUtils.isBlank(clientKey)) {
storageClient = storageTemplate.client();
} else {
storageClient = storageTemplate.client(clientKey);
}
StorageSignature storageSignature = storageClient.generateWebUploadSign(key, mimeType, successActionStatus);
writeResponse(response, 200, objectMapper.writeValueAsString(storageSignature));
} catch (Exception e) {
String resp = "{\"errcode\":\"-1\",\"errmsg\":\"" + (e.getMessage() != null ? e.getMessage() : "Storage error") + "\"}";
writeResponse(response, 500, resp);
}
}
use of com.workoss.boot.storage.model.StorageSignature in project boot by workoss.
the class StorageUtil method requestSign.
public static StorageSignature requestSign(StorageHttpFunction httpFunc, StorageClientConfig config, String key, String mimeType, String successActionStatus) {
String url = formatTokenUrl(config.getTokenUrl()) + "/security/stssign";
String paramJson = StorageUtil.buildSignatureParam(config, key, mimeType, successActionStatus);
return request(url, paramJson, httpFunc, jsonNode -> {
StorageSignature storageSignature = JsonMapper.convertValue(jsonNode.get("data"), StorageSignature.class);
boolean check = StringUtils.isNotBlank(storageSignature.getAccessKey()) && StringUtils.isNotBlank(storageSignature.getSignature()) && StringUtils.isNotBlank(storageSignature.getPolicy());
if (!check) {
throw new StorageException("00001", "返回结果不正常");
}
// config 设置了domain 覆盖
if (StringUtils.isNotBlank(config.getDomain())) {
storageSignature.setHost(config.getDomain());
}
return storageSignature;
});
}
Aggregations