|
|
@@ -1,10 +1,12 @@
|
|
|
package cn.reghao.oss.store.rpc;
|
|
|
|
|
|
import cn.reghao.oss.store.config.OssProperties;
|
|
|
+import cn.reghao.oss.store.service.ObjectChannelService;
|
|
|
import cn.reghao.oss.store.util.JwtUtil;
|
|
|
import cn.reghao.oss.store.util.SignatureUtil;
|
|
|
import cn.reghao.oss.store.api.constant.ChannelAction;
|
|
|
import cn.reghao.oss.store.api.dto.OssPayload;
|
|
|
+import cn.reghao.oss.store.util.UserContext;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.UUID;
|
|
|
@@ -18,12 +20,14 @@ import java.util.UUID;
|
|
|
@Service
|
|
|
public class SignService {
|
|
|
private final String secretKey;
|
|
|
+ private final ObjectChannelService objectChannelService;
|
|
|
|
|
|
- public SignService(OssProperties ossProperties) {
|
|
|
+ public SignService(OssProperties ossProperties, ObjectChannelService objectChannelService) {
|
|
|
this.secretKey = ossProperties.getSecretKey();
|
|
|
+ this.objectChannelService = objectChannelService;
|
|
|
}
|
|
|
|
|
|
- public String getSignedUrl(int loginUser, String url, int channelId, long expire) {
|
|
|
+ /*public String getSignedUrl(int loginUser, String url, int channelId, long expire) {
|
|
|
long timestamp = System.currentTimeMillis() + expire*1000;
|
|
|
String action = ChannelAction.access.getName();
|
|
|
OssPayload ossPayload = new OssPayload(action, channelId, loginUser);
|
|
|
@@ -34,14 +38,16 @@ public class SignService {
|
|
|
String requestString = String.format("%s%s?%s", "GET", url, queryString);
|
|
|
String sign = SignatureUtil.sign(requestString, secretKey);
|
|
|
return String.format("%s?token=%s&t=%s&nonce=%s&sign=%s", url, token, timestamp, nonce, sign);
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
- public String getSignedUrl(String url, int loginUser) {
|
|
|
- String secretId = loginUser+"";
|
|
|
- long timestamp = System.currentTimeMillis() + 3600*1000;
|
|
|
+ public String getSignedUrl(String url, int expire) {
|
|
|
+ int loginUser = UserContext.getUser();
|
|
|
+ long timestamp = System.currentTimeMillis() + expire*1000L;
|
|
|
+ int channelId = objectChannelService.getChannelId(url);
|
|
|
|
|
|
String action = ChannelAction.download.getName();
|
|
|
- OssPayload ossPayload = new OssPayload(action, 102, loginUser);
|
|
|
+ OssPayload ossPayload = new OssPayload(action, channelId, loginUser);
|
|
|
+
|
|
|
String token = JwtUtil.createToken(ossPayload, timestamp, secretKey);
|
|
|
String nonce = UUID.randomUUID().toString();
|
|
|
String queryString = String.format("token=%s&t=%s&nonce=%s", token, timestamp, nonce);
|