添加启用配置.

This commit is contained in:
lijiahang
2023-07-08 00:59:19 +08:00
parent 36193f56fc
commit b417503a9e
5 changed files with 45 additions and 14 deletions

View File

@@ -1,9 +1,12 @@
package com.orion.ops.framework.security.core.filter;
import com.orion.lang.utils.Strings;
import com.orion.ops.framework.common.constant.ErrorCode;
import com.orion.ops.framework.common.security.LoginUser;
import com.orion.ops.framework.security.core.service.SecurityFrameworkService;
import com.orion.ops.framework.security.core.utils.SecurityUtils;
import com.orion.web.servlet.web.Servlets;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
@@ -20,6 +23,7 @@ import java.io.IOException;
* @version 1.0.0
* @since 2023/7/6 18:39
*/
@Slf4j
public class TokenAuthenticationFilter extends OncePerRequestFilter {
private final SecurityFrameworkService securityFrameworkService;
@@ -30,17 +34,22 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
// 获取请求头 token
String token = SecurityUtils.obtainAuthorization(request);
if (!Strings.isBlank(token)) {
// 通过 token 获取用户信息
LoginUser loginUser = securityFrameworkService.getUserByToken(token);
// 设置上下文
if (loginUser != null) {
SecurityUtils.setLoginUser(loginUser, request);
try {
// 获取请求头 token
String token = SecurityUtils.obtainAuthorization(request);
if (!Strings.isBlank(token)) {
// 通过 token 获取用户信息
LoginUser loginUser = securityFrameworkService.getUserByToken(token);
// 设置上下文
if (loginUser != null) {
SecurityUtils.setLoginUser(loginUser, request);
}
}
} catch (Exception e) {
log.error("TokenAuthenticationFilter.doFilterInternal error", e);
Servlets.writeHttpWrapper(response, ErrorCode.INTERNAL_SERVER_ERROR.getWrapper());
return;
}
// todo 全局异常返回 mock模式
// 继续执行
chain.doFilter(request, response);
}

View File

@@ -3,10 +3,13 @@ package com.orion.ops.framework.storage.config;
import com.orion.ops.framework.storage.core.client.FileClient;
import com.orion.ops.framework.storage.core.client.local.LocalFileClient;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import javax.annotation.Resource;
/**
* 存储配置类
*
@@ -20,12 +23,16 @@ import org.springframework.context.annotation.Primary;
@EnableConfigurationProperties(StorageConfig.class)
public class OrionStorageAutoConfiguration {
@Resource
private StorageConfig config;
/**
* 本地文件客户端
*/
@Bean
@Primary
public FileClient localFileClient(StorageConfig config) {
@ConditionalOnProperty(value = "orion.storage.local.enabled", havingValue = "true")
public FileClient localFileClient() {
return new LocalFileClient(config.getLocal());
}

View File

@@ -12,6 +12,11 @@ import lombok.Data;
@Data
public class FileClientConfig {
/**
* 是否启用
*/
protected boolean enabled;
/**
* 是否自动拼接 traceId 前缀. 没有则使用 UUID
*/

View File

@@ -4,23 +4,34 @@
"name": "orion.storage",
"type": "com.orion.ops.framework.storage.config.StorageConfig",
"sourceType": "com.orion.ops.framework.storage.config.StorageConfig"
},
{
"name": "orion.storage.local",
"type": "com.orion.ops.framework.storage.core.client.local.LocalFileClientConfig",
"sourceType": "com.orion.ops.framework.storage.core.client.local.LocalFileClientConfig"
}
],
"properties": [
{
"name": "orion.storage.local.nameAppendTraceId",
"name": "orion.storage.local.enabled",
"type": "java.lang.Boolean",
"description": "是否启用.",
"defaultValue": false
},
{
"name": "orion.storage.local.name-append-trace-id",
"type": "java.lang.Boolean",
"description": "是否自动拼接 traceId 前缀. 没有则使用 UUID.",
"defaultValue": false
},
{
"name": "orion.storage.local.storagePath",
"name": "orion.storage.local.storage-path",
"type": "java.lang.String",
"description": "存储路径.",
"defaultValue": ""
},
{
"name": "orion.storage.local.basePath",
"name": "orion.storage.local.base-path",
"type": "java.lang.String",
"description": "基础路径.",
"defaultValue": ""

View File

@@ -27,7 +27,6 @@ public class EmptySecurityImpl implements SecurityFrameworkService {
@Override
public LoginUser getUserByToken(String token) {
// TODO MOCK
LoginUser user = new LoginUser();
user.setId(123L);
user.setUsername("username");