[DURACOM-312] set the X-On-Behalf-Of header with impersonatingID in FileUploader.

(cherry picked from commit 727bcdc2cb23ae7fcff1d9ddfa794f872f1d1b8c)
This commit is contained in:
Adamo
2024-12-06 09:20:14 +01:00
parent 70c6af3630
commit 0574c8ed98

View File

@@ -47,6 +47,11 @@ import { UploaderProperties } from './uploader-properties.model';
}) })
export class UploaderComponent implements OnInit, AfterViewInit { export class UploaderComponent implements OnInit, AfterViewInit {
/**
* Header key to impersonate a user
*/
private readonly ON_BEHALF_HEADER = 'X-On-Behalf-Of';
/** /**
* The message to show when drag files on the drop zone * The message to show when drag files on the drop zone
*/ */
@@ -162,7 +167,13 @@ export class UploaderComponent implements OnInit, AfterViewInit {
item.url = this.uploader.options.url; item.url = this.uploader.options.url;
} }
// Ensure the current XSRF token is included in every upload request (token may change between items uploaded) // Ensure the current XSRF token is included in every upload request (token may change between items uploaded)
this.uploader.options.headers = [{ name: XSRF_REQUEST_HEADER, value: this.tokenExtractor.getToken() }]; // Ensure the behalf header is set if impersonating
this.uploader.options.headers = [
{ name: XSRF_REQUEST_HEADER, value: this.tokenExtractor.getToken() },
...(hasValue(this.uploadFilesOptions.impersonatingID)
? [{ name: this.ON_BEHALF_HEADER, value: this.uploadFilesOptions.impersonatingID }]
: [])
];
this.onBeforeUpload(); this.onBeforeUpload();
this.isOverDocumentDropZone = observableOf(false); this.isOverDocumentDropZone = observableOf(false);
}; };