mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-11-15 07:20:40 +00:00
feat: enhance coding harness, model security and system features
This commit is contained in:
@@ -42,5 +42,10 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -89,7 +89,8 @@ public class PlusWebSocketHandler extends AbstractWebSocketHandler {
|
||||
*/
|
||||
@Override
|
||||
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
||||
log.error("[transport error] sessionId: {} , exception:{}", session.getId(), exception.getMessage());
|
||||
log.error("websocket_transport_failed sessionId={} exceptionType={}", session.getId(),
|
||||
exception.getClass().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.server.HandshakeInterceptor;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.ruoyi.common.websocket.constant.WebSocketConstants.LOGIN_USER_KEY;
|
||||
|
||||
@@ -24,6 +25,10 @@ import static org.ruoyi.common.websocket.constant.WebSocketConstants.LOGIN_USER_
|
||||
@Slf4j
|
||||
public class PlusWebSocketInterceptor implements HandshakeInterceptor {
|
||||
|
||||
private static final Pattern CREDENTIAL_PATH_SEGMENT = Pattern.compile(
|
||||
"(?i)(/(?:token(?:[-_]?id)?|access[-_]?token|refresh[-_]?token|api[-_]?key|"
|
||||
+ "monitor/online(?:/myself)?|myself)/)([^/?#;\\s]+)");
|
||||
|
||||
/**
|
||||
* WebSocket握手之前执行的前置处理方法
|
||||
*
|
||||
@@ -54,7 +59,8 @@ public class PlusWebSocketInterceptor implements HandshakeInterceptor {
|
||||
attributes.put(LOGIN_USER_KEY, loginUser);
|
||||
return true;
|
||||
} catch (NotLoginException e) {
|
||||
log.error("WebSocket 认证失败'{}',无法访问系统资源", e.getMessage());
|
||||
log.error("websocket_handshake_failed category=NOT_LOGIN path={} exceptionType={}",
|
||||
safePath(request), e.getClass().getName());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -72,4 +78,10 @@ public class PlusWebSocketInterceptor implements HandshakeInterceptor {
|
||||
// 在这个方法中可以执行一些握手成功后的后续处理逻辑,比如记录日志或者其他操作
|
||||
}
|
||||
|
||||
private static String safePath(ServerHttpRequest request) {
|
||||
String path = request.getURI().getPath();
|
||||
return path == null ? null
|
||||
: CREDENTIAL_PATH_SEGMENT.matcher(path).replaceAll("$1[REDACTED]");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,11 @@ public class WebSocketTopicListener implements ApplicationRunner, Ordered {
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
// 订阅WebSocket消息
|
||||
WebSocketUtils.subscribeMessage((message) -> {
|
||||
log.info("WebSocket主题订阅收到消息session keys={} message={}", message.getSessionKeys(), message.getMessage());
|
||||
boolean broadcast = CollUtil.isEmpty(message.getSessionKeys());
|
||||
int recipientCount = broadcast ? WebSocketSessionHolder.getSessionsAll().size()
|
||||
: message.getSessionKeys().size();
|
||||
log.info("websocket_topic_received broadcast={} recipientCount={} payloadLength={}",
|
||||
broadcast, recipientCount, message.getMessage() == null ? 0 : message.getMessage().length());
|
||||
// 如果key不为空就按照key发消息 如果为空就群发
|
||||
if (CollUtil.isNotEmpty(message.getSessionKeys())) {
|
||||
message.getSessionKeys().forEach(key -> {
|
||||
@@ -40,7 +44,7 @@ public class WebSocketTopicListener implements ApplicationRunner, Ordered {
|
||||
});
|
||||
}
|
||||
});
|
||||
log.info("初始化WebSocket主题订阅监听器成功");
|
||||
log.info("websocket_topic_listener_initialized status=SUCCESS");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -69,8 +69,8 @@ public class WebSocketUtils {
|
||||
broadcastMessage.setMessage(webSocketMessage.getMessage());
|
||||
broadcastMessage.setSessionKeys(unsentSessionKeys);
|
||||
RedisUtils.publish(WEB_SOCKET_TOPIC, broadcastMessage, consumer -> {
|
||||
log.info(" WebSocket发送主题订阅消息topic:{} session keys:{} message:{}",
|
||||
WEB_SOCKET_TOPIC, unsentSessionKeys, webSocketMessage.getMessage());
|
||||
log.info("websocket_publish topic={} broadcast=false recipientCount={} payloadLength={}",
|
||||
WEB_SOCKET_TOPIC, unsentSessionKeys.size(), payloadLength(webSocketMessage.getMessage()));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,8 @@ public class WebSocketUtils {
|
||||
WebSocketMessageDto broadcastMessage = new WebSocketMessageDto();
|
||||
broadcastMessage.setMessage(message);
|
||||
RedisUtils.publish(WEB_SOCKET_TOPIC, broadcastMessage, consumer -> {
|
||||
log.info("WebSocket发送主题订阅消息topic:{} message:{}", WEB_SOCKET_TOPIC, message);
|
||||
log.info("websocket_publish topic={} broadcast=true recipientCount=all payloadLength={}",
|
||||
WEB_SOCKET_TOPIC, payloadLength(message));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -120,8 +121,14 @@ public class WebSocketUtils {
|
||||
try {
|
||||
session.sendMessage(message);
|
||||
} catch (IOException e) {
|
||||
log.error("[send] session({}) 发送消息({}) 异常", session, message, e);
|
||||
log.error("websocket_send_failed sessionId={} payloadType={} payloadLength={} exceptionType={}",
|
||||
session.getId(), message.getClass().getSimpleName(), message.getPayloadLength(),
|
||||
e.getClass().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int payloadLength(String message) {
|
||||
return message == null ? 0 : message.length();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user