@@ -214,7 +214,10 @@ export const setActiveNamespace = (namespace: string = '') => {
214
214
return action ( ActionType . SetActiveNamespace , { namespace } ) ;
215
215
} ;
216
216
217
- export const startImpersonate = ( kind : string , name : string ) => async ( dispatch , getState ) => {
217
+ export const startImpersonate = ( kind : string , name : string , groups ?: string [ ] ) => async (
218
+ dispatch ,
219
+ getState ,
220
+ ) => {
218
221
const textEncoder = new TextEncoder ( ) ;
219
222
220
223
const imp = getImpersonate ( getState ( ) ) ;
@@ -235,12 +238,24 @@ export const startImpersonate = (kind: string, name: string) => async (dispatch,
235
238
let subprotocols ;
236
239
if ( kind === 'User' ) {
237
240
subprotocols = [ `Impersonate-User.${ encodedName } ` ] ;
238
- }
239
- if ( kind === 'Group' ) {
241
+ } else if ( kind === 'Group' ) {
240
242
subprotocols = [ `Impersonate-Group.${ encodedName } ` ] ;
243
+ } else if ( kind === 'UserWithGroups' && groups && groups . length > 0 ) {
244
+ // User with multiple groups impersonation
245
+ // Encode user subprotocol
246
+ subprotocols = [ `Impersonate-User.${ encodedName } ` ] ;
247
+ // Encode each group as a separate subprotocol
248
+ groups . forEach ( ( group ) => {
249
+ const encodedGroup = Base64 . encode (
250
+ String . fromCharCode . apply ( String , textEncoder . encode ( group ) ) ,
251
+ )
252
+ . replace ( / = / g, '_' )
253
+ . replace ( / \/ / g, '-' ) ;
254
+ subprotocols . push ( `Impersonate-Group.${ encodedGroup } ` ) ;
255
+ } ) ;
241
256
}
242
257
243
- dispatch ( beginImpersonate ( kind , name , subprotocols ) ) ;
258
+ dispatch ( beginImpersonate ( kind , name , subprotocols , groups ) ) ;
244
259
subsClient . close ( false , true ) ;
245
260
dispatch ( clearSSARFlags ( ) ) ;
246
261
dispatch ( detectFeatures ( ) ) ;
0 commit comments