feat: 主机终端访问.

This commit is contained in:
lijiahang
2023-12-28 19:18:46 +08:00
parent 638fbb9613
commit a1e372148a
22 changed files with 254 additions and 308 deletions

View File

@@ -1,15 +1,17 @@
package com.orion.ops.framework.biz.operator.log.core.constant;
import com.orion.ops.framework.common.constant.FieldConst;
package com.orion.ops.framework.common.constant;
/**
* 操作日志常量
* 额外字段常量
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023/10/10 19:00
* @since 2023/12/28 18:34
*/
public interface OperatorLogKeys extends FieldConst {
public interface ExtraFieldConst extends FieldConst {
String USER_ID = "userId";
String TRACE_ID = "traceId";
String GROUP_NAME = "groupName";

View File

@@ -3,7 +3,7 @@ package com.orion.ops.framework.common.entity;
import java.io.Serializable;
/**
* 请求身份
* 请求留痕
*
* @author Jiahang Li
* @version 1.0.0

View File

@@ -20,7 +20,7 @@ public class Requests {
}
/**
* 填充请求身份信息
* 填充请求留痕信息
*
* @param identity identity
*/

View File

@@ -242,7 +242,7 @@ public class OperatorLogAspect {
}
/**
* 填充请求信息
* 填充请求留痕信息
*
* @param model model
*/

View File

@@ -2,7 +2,7 @@ package com.orion.ops.framework.biz.operator.log.core.uitls;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeFilter;
import com.orion.ops.framework.biz.operator.log.core.constant.OperatorLogKeys;
import com.orion.ops.framework.common.constant.ExtraFieldConst;
import com.orion.ops.framework.common.security.LoginUser;
import java.util.HashMap;
@@ -15,7 +15,7 @@ import java.util.Map;
* @version 1.0.0
* @since 2023/10/10 11:32
*/
public class OperatorLogs implements OperatorLogKeys {
public class OperatorLogs implements ExtraFieldConst {
private static final String UN_SAVE_FLAG = "__un__save__";

View File

@@ -1,13 +1,11 @@
package com.orion.ops.framework.websocket.config;
import com.orion.ops.framework.common.constant.AutoConfigureOrderConst;
import com.orion.ops.framework.websocket.core.interceptor.UserHandshakeInterceptor;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.server.HandshakeInterceptor;
import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean;
/**
@@ -35,12 +33,4 @@ public class OrionWebSocketAutoConfiguration {
return factory;
}
/**
* @return 用户认证拦截器 按需注入
*/
@Bean
public HandshakeInterceptor userHandshakeInterceptor() {
return new UserHandshakeInterceptor();
}
}

View File

@@ -1,22 +0,0 @@
package com.orion.ops.framework.websocket.core.constant;
/**
* websocket 属性
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023/6/25 20:25
*/
public interface WsAttr {
String USER = "user";
String UID = "uid";
String TOKEN = "token";
String READONLY = "readonly";
String CONNECTED = "connected";
}

View File

@@ -1,79 +0,0 @@
package com.orion.ops.framework.websocket.core.constant;
import com.orion.lang.utils.Exceptions;
import com.orion.lang.utils.Strings;
import com.orion.lang.utils.Valid;
import lombok.AllArgsConstructor;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
/**
* ws服务端响应常量
*
* @author Jiahang Li
* @version 1.0.0
* @since 2021/4/16 21:48
*/
@AllArgsConstructor
public enum WsProtocol {
/**
* 正常返回
*/
OK("0"),
/**
* 连接成功
*/
CONNECTED("1"),
/**
* ping
*/
PING("2"),
/**
* pong
*/
PONG("3"),
/**
* 未知操作
*/
ERROR("4"),
;
private final String code;
/**
* 分隔符
*/
public static final String SYMBOL = "|";
public byte[] get() {
return Strings.bytes(code);
}
public byte[] msg(String body) {
Valid.notNull(body);
return this.msg(Strings.bytes(body));
}
public byte[] msg(byte[] body) {
return this.msg(body, 0, body.length);
}
public byte[] msg(byte[] body, int offset, int len) {
Valid.notNull(body);
try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
o.write(Strings.bytes(code + SYMBOL));
o.write(body, offset, len);
return o.toByteArray();
} catch (IOException e) {
throw Exceptions.ioRuntime(e);
}
}
}

View File

@@ -1,41 +0,0 @@
package com.orion.ops.framework.websocket.core.interceptor;
import com.orion.ops.framework.common.security.SecurityHolder;
import com.orion.ops.framework.websocket.core.constant.WsAttr;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.HandshakeInterceptor;
import javax.annotation.Resource;
import java.util.Map;
/**
* 用户拦截器
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023/6/25 20:16
*/
public class UserHandshakeInterceptor implements HandshakeInterceptor {
@Resource
private SecurityHolder securityHolder;
@Override
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) {
// TODO TEST
attributes.put(WsAttr.USER, securityHolder.getLoginUserId());
// if (user == null){
// return false;
// response.setStatusCode(HttpStatus.MULTI_STATUS);
// }
// HttpSessionHandshakeInterceptor
return true;
}
@Override
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) {
}
}