Search in sources :

Example 1 with StorageSignature

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);
    }
}
Also used : StorageClient(com.workoss.boot.storage.client.StorageClient) StorageSignature(com.workoss.boot.storage.model.StorageSignature) IOException(java.io.IOException)

Example 2 with StorageSignature

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;
    });
}
Also used : StorageSignature(com.workoss.boot.storage.model.StorageSignature) StorageException(com.workoss.boot.storage.exception.StorageException)

Aggregations

StorageSignature (com.workoss.boot.storage.model.StorageSignature)2 StorageClient (com.workoss.boot.storage.client.StorageClient)1 StorageException (com.workoss.boot.storage.exception.StorageException)1 IOException (java.io.IOException)1