11use contextforge_gateway_rs_apis:: user_store:: { UserConfig , VirtualHost } ;
2+ use std:: sync:: Arc ;
3+
24use http:: request:: Parts ;
3- //use rmcp::{ErrorData, RoleServer, model::ErrorCode, service::RequestContext, transport::DownstreamSessionId};
45use rmcp:: {
5- ErrorData , RoleServer , model:: ErrorCode , service:: RequestContext ,
6+ ErrorData , RoleServer ,
7+ model:: { ErrorCode , Extensions } ,
8+ service:: RequestContext ,
69 transport:: streamable_http_server:: tower:: DownstreamSessionId ,
710} ;
811use tracing:: info;
912
1013use crate :: {
1114 common:: ContextForgeClaims ,
15+ gateway:: UserSession ,
1216 layers:: { session_id:: SessionId , virtual_host_id:: VirtualHostId } ,
1317} ;
1418
@@ -33,6 +37,20 @@ impl SessionKey {
3337 session_id : session_id. to_owned ( ) ,
3438 }
3539 }
40+
41+ pub ( crate ) fn from_authorized_extensions ( extensions : & Extensions ) -> Option < Self > {
42+ let parts = extensions. get :: < Parts > ( ) ?;
43+ let session_id = parts. extensions . get :: < SessionId > ( ) ?;
44+ let user_config = parts. extensions . get :: < UserConfig > ( ) ?;
45+ let virtual_host_id = parts. extensions . get :: < VirtualHostId > ( ) ?;
46+ let claims = parts. extensions . get :: < ContextForgeClaims > ( ) ?;
47+ user_config. virtual_hosts . get ( virtual_host_id. value ( ) ) ?;
48+ Some ( Self :: new ( & claims. sub , virtual_host_id. value ( ) , session_id. value ( ) ) )
49+ }
50+
51+ pub ( crate ) fn to_user_session ( & self ) -> UserSession {
52+ UserSession :: new ( self . subject . clone ( ) , self . virtual_host_id . clone ( ) , Arc :: from ( self . session_id . as_str ( ) ) )
53+ }
3654}
3755
3856impl std:: fmt:: Display for SessionKey {
@@ -54,6 +72,7 @@ pub struct AuthorizedCallContext<'a> {
5472
5573pub struct InitializeCallContext < ' a > {
5674 pub virtual_host : & ' a VirtualHost ,
75+ pub virtual_host_id : & ' a str ,
5776 pub downstream_session_id : & ' a DownstreamSessionId ,
5877 pub principal : & ' a str ,
5978 pub session_key : SessionKey ,
@@ -194,6 +213,7 @@ impl<'a> InitializeCallValidator<'a> {
194213
195214 Ok ( InitializeCallContext {
196215 virtual_host,
216+ virtual_host_id : virtual_host_id. value ( ) ,
197217 downstream_session_id,
198218 principal : & claims. sub ,
199219 session_key : SessionKey :: new ( & claims. sub , virtual_host_id. value ( ) , downstream_session_id. value ( ) ) ,
0 commit comments