@@ -2,7 +2,7 @@ import express from 'express';
22import { v4 as uuid } from 'uuid' ;
33import { ObjectId } from 'mongodb' ;
44import SamlService from './service' ;
5- import samlStore from './store' ;
5+ import { SamlStateStoreInterface } from './store/SamlStateStoreInterface ' ;
66import { ContextFactories } from '../../types/graphql' ;
77import { SamlResponseData } from '../types' ;
88import WorkspaceModel from '../../models/workspace' ;
@@ -23,13 +23,21 @@ export default class SamlController {
2323 */
2424 private factories : ContextFactories ;
2525
26+ /**
27+ * SAML state store instance
28+ */
29+ private store : SamlStateStoreInterface ;
30+
2631 /**
2732 * SAML controller constructor used for DI
33+ *
2834 * @param factories - for working with models
35+ * @param store - SAML state store instance
2936 */
30- constructor ( factories : ContextFactories ) {
37+ constructor ( factories : ContextFactories , store : SamlStateStoreInterface ) {
3138 this . samlService = new SamlService ( ) ;
3239 this . factories = factories ;
40+ this . store = store ;
3341 }
3442
3543 /**
@@ -74,10 +82,20 @@ export default class SamlController {
7482 /**
7583 * 3. Save RelayState to temporary storage
7684 */
77- samlStore . saveRelayState ( relayStateId , {
85+ this . log (
86+ 'info' ,
87+ '[Store] Saving RelayState:' ,
88+ sgr ( relayStateId . slice ( 0 , 8 ) , Effect . ForegroundGray ) ,
89+ '| Store:' ,
90+ sgr ( this . store . type , Effect . ForegroundBlue ) ,
91+ '| Workspace:' ,
92+ sgr ( workspaceId , Effect . ForegroundCyan )
93+ ) ;
94+ await this . store . saveRelayState ( relayStateId , {
7895 returnUrl,
7996 workspaceId,
8097 } ) ;
98+ this . log ( 'log' , '[Store] RelayState saved:' , sgr ( relayStateId . slice ( 0 , 8 ) , Effect . ForegroundGray ) ) ;
8199
82100 /**
83101 * 4. Generate AuthnRequest
@@ -105,7 +123,17 @@ export default class SamlController {
105123 /**
106124 * 5. Save AuthnRequest ID for InResponseTo validation
107125 */
108- samlStore . saveAuthnRequest ( requestId , workspaceId ) ;
126+ this . log (
127+ 'info' ,
128+ '[Store] Saving AuthnRequest:' ,
129+ sgr ( requestId . slice ( 0 , 8 ) , Effect . ForegroundGray ) ,
130+ '| Store:' ,
131+ sgr ( this . store . type , Effect . ForegroundBlue ) ,
132+ '| Workspace:' ,
133+ sgr ( workspaceId , Effect . ForegroundCyan )
134+ ) ;
135+ await this . store . saveAuthnRequest ( requestId , workspaceId ) ;
136+ this . log ( 'log' , '[Store] AuthnRequest saved:' , sgr ( requestId . slice ( 0 , 8 ) , Effect . ForegroundGray ) ) ;
109137
110138 /**
111139 * 6. Redirect to IdP
@@ -212,11 +240,34 @@ export default class SamlController {
212240 * Validate InResponseTo against stored AuthnRequest
213241 */
214242 if ( samlData . inResponseTo ) {
215- const isValidRequest = samlStore . validateAndConsumeAuthnRequest (
243+ this . log (
244+ 'info' ,
245+ '[Store] Validating AuthnRequest:' ,
246+ sgr ( samlData . inResponseTo . slice ( 0 , 8 ) , Effect . ForegroundGray ) ,
247+ '| Store:' ,
248+ sgr ( this . store . type , Effect . ForegroundBlue ) ,
249+ '| Workspace:' ,
250+ sgr ( workspaceId , Effect . ForegroundCyan )
251+ ) ;
252+ const isValidRequest = await this . store . validateAndConsumeAuthnRequest (
216253 samlData . inResponseTo ,
217254 workspaceId
218255 ) ;
219256
257+ if ( isValidRequest ) {
258+ this . log (
259+ 'log' ,
260+ '[Store] AuthnRequest validated and consumed:' ,
261+ sgr ( samlData . inResponseTo . slice ( 0 , 8 ) , Effect . ForegroundGray )
262+ ) ;
263+ } else {
264+ this . log (
265+ 'warn' ,
266+ '[Store] AuthnRequest validation failed:' ,
267+ sgr ( samlData . inResponseTo . slice ( 0 , 8 ) , Effect . ForegroundRed )
268+ ) ;
269+ }
270+
220271 if ( ! isValidRequest ) {
221272 this . log (
222273 'error' ,
@@ -274,7 +325,27 @@ export default class SamlController {
274325 * 4. Get RelayState for return URL (before consuming)
275326 * Note: RelayState is consumed after first use, so we need to get it before validation
276327 */
277- const relayState = samlStore . getRelayState ( relayStateId ) ;
328+ this . log (
329+ 'info' ,
330+ '[Store] Getting RelayState:' ,
331+ sgr ( relayStateId . slice ( 0 , 8 ) , Effect . ForegroundGray ) ,
332+ '| Store:' ,
333+ sgr ( this . store . type , Effect . ForegroundBlue )
334+ ) ;
335+ const relayState = await this . store . getRelayState ( relayStateId ) ;
336+
337+ if ( relayState ) {
338+ this . log (
339+ 'log' ,
340+ '[Store] RelayState retrieved and consumed:' ,
341+ sgr ( relayStateId . slice ( 0 , 8 ) , Effect . ForegroundGray ) ,
342+ '| Return URL:' ,
343+ sgr ( relayState . returnUrl , Effect . ForegroundGray )
344+ ) ;
345+ } else {
346+ this . log ( 'warn' , '[Store] RelayState not found or expired:' , sgr ( relayStateId . slice ( 0 , 8 ) , Effect . ForegroundRed ) ) ;
347+ }
348+
278349 const finalReturnUrl = relayState ?. returnUrl || `/workspace/${ workspaceId } ` ;
279350
280351 /**
0 commit comments