refactor: 阿里云OSS文件上传路径调整和Security代码优化

This commit is contained in:
haoxr
2023-07-12 19:16:25 +08:00
parent ca91ad714b
commit 105eb6f7c4
4 changed files with 5 additions and 3 deletions

View File

@@ -65,7 +65,6 @@ public class SecurityConfig {
/**
* 不走过滤器链的放行配置
*
*/
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {

View File

@@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Component;
import jakarta.annotation.Resource;
@@ -71,7 +72,7 @@ public class JwtTokenManager {
// 角色放入JWT的claims
Set<String> roles = userDetails.getAuthorities().stream()
.map(item -> item.getAuthority()).collect(Collectors.toSet());
.map(GrantedAuthority::getAuthority).collect(Collectors.toSet());
claims.put("authorities", roles);
// 权限数据多放入Redis

View File

@@ -65,7 +65,7 @@ public class AliyunOssService implements OssService {
// 生成文件名(日期文件夹)
String suffix = FileUtil.getSuffix(file.getOriginalFilename());
String uuid = IdUtil.simpleUUID();
String fileName = DateUtil.format(LocalDateTime.now(), "yyyy/MM/dd") + "/" + uuid + "." + suffix;
String fileName = DateUtil.format(LocalDateTime.now(), "yyyyMMdd") + "/" + uuid + "." + suffix;
// try-with-resource 语法糖自动释放流
try (InputStream inputStream = file.getInputStream()) {

View File

@@ -26,6 +26,8 @@ import java.security.NoSuchAlgorithmException;
import java.time.LocalDateTime;
/**
* MinIO 文件上传服务类
*
* @author haoxr
* @since 2023/6/2
*/