refactor: 阿里云OSS文件上传路径调整和Security代码优化
This commit is contained in:
@@ -65,7 +65,6 @@ public class SecurityConfig {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 不走过滤器链的放行配置
|
* 不走过滤器链的放行配置
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public WebSecurityCustomizer webSecurityCustomizer() {
|
public WebSecurityCustomizer webSecurityCustomizer() {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
@@ -71,7 +72,7 @@ public class JwtTokenManager {
|
|||||||
|
|
||||||
// 角色放入JWT的claims
|
// 角色放入JWT的claims
|
||||||
Set<String> roles = userDetails.getAuthorities().stream()
|
Set<String> roles = userDetails.getAuthorities().stream()
|
||||||
.map(item -> item.getAuthority()).collect(Collectors.toSet());
|
.map(GrantedAuthority::getAuthority).collect(Collectors.toSet());
|
||||||
claims.put("authorities", roles);
|
claims.put("authorities", roles);
|
||||||
|
|
||||||
// 权限数据多放入Redis
|
// 权限数据多放入Redis
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public class AliyunOssService implements OssService {
|
|||||||
// 生成文件名(日期文件夹)
|
// 生成文件名(日期文件夹)
|
||||||
String suffix = FileUtil.getSuffix(file.getOriginalFilename());
|
String suffix = FileUtil.getSuffix(file.getOriginalFilename());
|
||||||
String uuid = IdUtil.simpleUUID();
|
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-with-resource 语法糖自动释放流
|
||||||
try (InputStream inputStream = file.getInputStream()) {
|
try (InputStream inputStream = file.getInputStream()) {
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import java.security.NoSuchAlgorithmException;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* MinIO 文件上传服务类
|
||||||
|
*
|
||||||
* @author haoxr
|
* @author haoxr
|
||||||
* @since 2023/6/2
|
* @since 2023/6/2
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user