From 9668172b966b324dfcc8500c030ef719d0d2263c Mon Sep 17 00:00:00 2001 From: fengshuonan Date: Sun, 27 Dec 2020 22:51:05 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90file=E3=80=91=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E6=96=87=E4=BB=B6=E5=AD=98=E5=82=A8=E7=9A=84?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=EF=BC=8C=E6=9B=B4=E6=96=B0getFileAuthUrl?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel-d-file/file-sdk-local/pom.xml | 6 +++--- .../kernel/file/local/LocalFileOperator.java | 16 ++++------------ 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/kernel-d-file/file-sdk-local/pom.xml b/kernel-d-file/file-sdk-local/pom.xml index d41f2a661..0cacf4a0c 100644 --- a/kernel-d-file/file-sdk-local/pom.xml +++ b/kernel-d-file/file-sdk-local/pom.xml @@ -24,11 +24,11 @@ 1.0.0 - - + + cn.stylefeng.roses - jwt-sdk + auth-api 1.0.0 diff --git a/kernel-d-file/file-sdk-local/src/main/java/cn/stylefeng/roses/kernel/file/local/LocalFileOperator.java b/kernel-d-file/file-sdk-local/src/main/java/cn/stylefeng/roses/kernel/file/local/LocalFileOperator.java index 1705fb1c9..0cc4a3bec 100644 --- a/kernel-d-file/file-sdk-local/src/main/java/cn/stylefeng/roses/kernel/file/local/LocalFileOperator.java +++ b/kernel-d-file/file-sdk-local/src/main/java/cn/stylefeng/roses/kernel/file/local/LocalFileOperator.java @@ -3,6 +3,7 @@ package cn.stylefeng.roses.kernel.file.local; import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.system.SystemUtil; +import cn.stylefeng.roses.kernel.auth.api.context.LoginContext; import cn.stylefeng.roses.kernel.file.FileOperatorApi; import cn.stylefeng.roses.kernel.file.constants.FileConstants; import cn.stylefeng.roses.kernel.file.enums.BucketAuthEnum; @@ -10,12 +11,9 @@ import cn.stylefeng.roses.kernel.file.exception.FileException; import cn.stylefeng.roses.kernel.file.exception.enums.FileExceptionEnum; import cn.stylefeng.roses.kernel.file.expander.FileConfigExpander; import cn.stylefeng.roses.kernel.file.pojo.props.LocalFileProperties; -import cn.stylefeng.roses.kernel.jwt.JwtTokenOperator; -import cn.stylefeng.roses.kernel.jwt.api.pojo.config.JwtConfig; import java.io.File; import java.io.InputStream; -import java.util.HashMap; /** * 本地文件的操作 @@ -150,17 +148,11 @@ public class LocalFileOperator implements FileOperatorApi { @Override public String getFileAuthUrl(String bucketName, String key, Long timeoutMillis) { - // 初始化jwt token的生成工具 - JwtConfig jwtConfig = new JwtConfig(); - jwtConfig.setJwtSecret(FileConfigExpander.getFileAuthJwtSecret()); - jwtConfig.setExpiredSeconds(timeoutMillis / 1000); - JwtTokenOperator jwtTokenOperator = new JwtTokenOperator(jwtConfig); - - // 生成token - String token = jwtTokenOperator.generateToken(new HashMap<>()); + // 获取登录用户的token + String token = LoginContext.me().getToken(); // 拼接url = “host” + “预览图片的url” + “?token=xxx” - return FileConfigExpander.getServerDeployHost() + FileConstants.FILE_PREVIEW_URL + "?token=" + token; + return FileConfigExpander.getServerDeployHost() + FileConstants.FILE_PREVIEW_URL + "?fileBucket=" + bucketName + "&fileObjectName=" + key + "&token=" + token; } @Override