规范命名.

This commit is contained in:
lijiahang
2023-10-09 16:25:19 +08:00
parent 7a26e6f89c
commit 890afa093c
13 changed files with 40 additions and 67 deletions

View File

@@ -11,8 +11,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* @since 2023/7/10 15:49
*/
@Data
@ConfigurationProperties(prefix = "orion.thread.pool")
public class ThreadPoolConfig {
@ConfigurationProperties(prefix = "orion.async.executor")
public class AsyncExecutorConfig {
/**
* 核心线程数量
@@ -34,7 +34,7 @@ public class ThreadPoolConfig {
*/
private int keepAliveSeconds;
public ThreadPoolConfig() {
public AsyncExecutorConfig() {
this.corePoolSize = 8;
this.maxPoolSize = 16;
this.queueCapacity = 200;

View File

@@ -23,7 +23,7 @@ import java.util.concurrent.ThreadPoolExecutor;
@EnableAsync
@AutoConfiguration
@AutoConfigureOrder(AutoConfigureOrderConst.FRAMEWORK_COMMON)
@EnableConfigurationProperties(ThreadPoolConfig.class)
@EnableConfigurationProperties(AsyncExecutorConfig.class)
public class OrionCommonAutoConfiguration {
/**
@@ -43,7 +43,7 @@ public class OrionCommonAutoConfiguration {
*/
@Primary
@Bean(name = "asyncExecutor")
public TaskExecutor asyncExecutor(ThreadPoolConfig config) {
public TaskExecutor asyncExecutor(AsyncExecutorConfig config) {
ThreadPoolMdcTaskExecutor executor = new ThreadPoolMdcTaskExecutor();
executor.setCorePoolSize(config.getCorePoolSize());
executor.setMaxPoolSize(config.getMaxPoolSize());

View File

@@ -1,34 +0,0 @@
package com.orion.ops.framework.common.utils;
import com.orion.lang.utils.Strings;
import com.orion.ops.framework.common.constant.Const;
/**
* 工具类
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023/7/14 16:34
*/
public class Kits {
private Kits() {
}
/**
* 获取登陆凭证
*
* @param authorization authorization
* @return token
*/
public static String getAuthorization(String authorization) {
if (Strings.isEmpty(authorization)) {
return null;
}
if (!authorization.contains(Const.BEARER) || authorization.length() <= Const.BEARER_PREFIX_LEN) {
return null;
}
return authorization.substring(Const.BEARER_PREFIX_LEN).trim();
}
}

View File

@@ -1,32 +1,32 @@
{
"groups": [
{
"name": "orion.thread.pool",
"type": "com.orion.ops.framework.common.config.ThreadPoolConfig",
"sourceType": "com.orion.ops.framework.common.config.ThreadPoolConfig"
"name": "orion.async.executor",
"type": "com.orion.ops.framework.common.config.AsyncExecutorConfig",
"sourceType": "com.orion.ops.framework.common.config.AsyncExecutorConfig"
}
],
"properties": [
{
"name": "orion.thread.pool.core-pool-size",
"name": "orion.async.executor.core-pool-size",
"type": "java.lang.Integer",
"description": "核心线程数量",
"defaultValue": "8"
},
{
"name": "orion.thread.pool.max-pool-size",
"name": "orion.async.executor.max-pool-size",
"type": "java.lang.Integer",
"description": "最大线程数量.",
"defaultValue": "16"
},
{
"name": "orion.thread.pool.queue-capacity",
"name": "orion.async.executor.queue-capacity",
"type": "java.lang.Integer",
"description": "队列容量.",
"defaultValue": "200"
},
{
"name": "orion.thread.pool.keep-alive-seconds",
"name": "orion.async.executor.keep-alive-seconds",
"type": "java.lang.Integer",
"description": "活跃时间.",
"defaultValue": "300"

View File

@@ -1,8 +1,9 @@
package com.orion.ops.framework.security.core.utils;
import com.orion.lang.constant.StandardHttpHeader;
import com.orion.lang.utils.Strings;
import com.orion.ops.framework.common.constant.Const;
import com.orion.ops.framework.common.security.LoginUser;
import com.orion.ops.framework.common.utils.Kits;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
@@ -31,7 +32,14 @@ public class SecurityUtils {
* @return token
*/
public static String obtainAuthorization(HttpServletRequest request) {
return Kits.getAuthorization(request.getHeader(StandardHttpHeader.AUTHORIZATION));
String authorization = request.getHeader(StandardHttpHeader.AUTHORIZATION);
if (Strings.isEmpty(authorization)) {
return null;
}
if (!authorization.contains(Const.BEARER) || authorization.length() <= Const.BEARER_PREFIX_LEN) {
return null;
}
return authorization.substring(Const.BEARER_PREFIX_LEN).trim();
}
/**

View File

@@ -45,9 +45,9 @@ public enum WsCloseCode {
VALID(4150, WsCloseReason.AUTHENTICATION_FAILURE),
/**
* 机不合法
* 机不合法
*/
INVALID_MACHINE(4200, WsCloseReason.CLOSED_CONNECTION),
INVALID_HOST(4200, WsCloseReason.CLOSED_CONNECTION),
/**
* 连接远程服务器连接超时
@@ -70,9 +70,9 @@ public enum WsCloseCode {
CONNECTION_EXCEPTION(4210, WsCloseReason.UNABLE_TO_CONNECT_REMOTE_SERVER),
/**
* 机未启用
* 机未启用
*/
MACHINE_DISABLED(4215, WsCloseReason.MACHINE_DISABLED),
HOST_DISABLED(4215, WsCloseReason.HOST_DISABLED),
/**
* 打开shell出现异常

View File

@@ -21,7 +21,7 @@ public interface WsCloseReason {
String REMOTE_SERVER_AUTHENTICATION_FAILURE = "remote server authentication failure...";
String MACHINE_DISABLED = "machine disabled...";
String HOST_DISABLED = "host disabled...";
String UNABLE_TO_CONNECT_REMOTE_SERVER = "unable to connect remote server...";

View File

@@ -101,7 +101,7 @@ public class WebSockets {
} else if (Exceptions.isCausedBy(e, AuthenticationException.class)) {
close(session, WsCloseCode.CONNECTION_AUTH_FAILURE);
} else if (Exceptions.isCausedBy(e, DisabledException.class)) {
close(session, WsCloseCode.MACHINE_DISABLED);
close(session, WsCloseCode.HOST_DISABLED);
} else {
close(session, WsCloseCode.CONNECTION_EXCEPTION);
}