Skip to content
This repository was archived by the owner on Jan 27, 2026. It is now read-only.

Commit 8ef7e53

Browse files
committed
feat: CyreneMsp 鉴权
1 parent 8f2b8f6 commit 8ef7e53

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

ClassIsland.ManagementServer.Server/Services/GrpcInterceptors/CyreneMspFrontedInterceptor.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33

44
namespace ClassIsland.ManagementServer.Server.Services.GrpcInterceptors;
55

6-
public class CyreneMspFrontedInterceptor(ILogger<CyreneMspFrontedInterceptor> logger) : Interceptor
6+
public class CyreneMspFrontedInterceptor(ILogger<CyreneMspFrontedInterceptor> logger,
7+
CyreneMspConnectionService cyreneMspConnectionService) : Interceptor
78
{
9+
private CyreneMspConnectionService CyreneMspConnectionService { get; } = cyreneMspConnectionService;
10+
811
private const string ProtocolName = "Cyrene_MSP";
912

1013
public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>(
@@ -18,6 +21,15 @@ public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>(
1821
throw new RpcException(new Status(StatusCode.InvalidArgument,
1922
$"客户端使用的协议 {clientProtocolName} 与服务端协议 {ProtocolName} 不符。"));
2023
}
24+
25+
if (!context.Method.StartsWith("/ClassIsland.Shared.Protobuf.Service.Handshake/") &&
26+
(!CyreneMspConnectionService.Sessions.TryGetValue(Guid.Parse(context.RequestHeaders.GetValue("cuid")!),
27+
out var session) ||
28+
session?.SessionId != context.RequestHeaders.GetValue("session"))
29+
)
30+
{
31+
throw new RpcException(new Status(StatusCode.PermissionDenied, "会话无效"));
32+
}
2133

2234
return await continuation(request, context);
2335
}

0 commit comments

Comments
 (0)