mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-17 14:21:29 +00:00
[MNT-24628] Handle difference between config object ticket and browser storage ticket (#10270)
* [MNT-24628] Handle difference between config object ticket and browser storage ticket * [MNT-24628] Add unit tests * [MNT-24628] Added null/undefined checks
This commit is contained in:
committed by
MichalKinas
parent
a6d6cbb0a0
commit
e1df4d8471
@@ -78,6 +78,7 @@ export class AlfrescoApi implements Emitter, AlfrescoApiType {
|
||||
this.clientsFactory();
|
||||
|
||||
this.errorListeners();
|
||||
this.ticketMismatchListeners();
|
||||
if (this.config.oauthInit) {
|
||||
this.initAuth(config);
|
||||
|
||||
@@ -131,6 +132,10 @@ export class AlfrescoApi implements Emitter, AlfrescoApiType {
|
||||
this.emitBuffer('logged-in');
|
||||
});
|
||||
|
||||
this.processAuth?.on('ticket_mismatch', (error: any) => {
|
||||
this.ticketMismatchHandler(error);
|
||||
});
|
||||
|
||||
if (!this.contentAuth) {
|
||||
this.contentAuth = new ContentAuth(this.config, this, this.httpClient);
|
||||
} else {
|
||||
@@ -141,6 +146,10 @@ export class AlfrescoApi implements Emitter, AlfrescoApiType {
|
||||
this.emitBuffer('logged-in');
|
||||
});
|
||||
|
||||
this.contentAuth?.on('ticket_mismatch', (error: any) => {
|
||||
this.ticketMismatchHandler(error);
|
||||
});
|
||||
|
||||
this.setAuthenticationClientECMBPM(this.contentAuth.getAuthentication(), this.processAuth.getAuthentication());
|
||||
}
|
||||
}
|
||||
@@ -228,6 +237,19 @@ export class AlfrescoApi implements Emitter, AlfrescoApiType {
|
||||
});
|
||||
}
|
||||
|
||||
ticketMismatchListeners() {
|
||||
this.contentClient?.off('ticket_mismatch', () => {});
|
||||
this.processClient?.off('ticket_mismatch', () => {});
|
||||
|
||||
this.contentClient?.on('ticket_mismatch', (error: any) => {
|
||||
this.ticketMismatchHandler(error);
|
||||
});
|
||||
|
||||
this.processClient?.on('ticket_mismatch', (error: any) => {
|
||||
this.ticketMismatchHandler(error);
|
||||
});
|
||||
}
|
||||
|
||||
/**@private? */
|
||||
errorHandler(error: { status?: number }) {
|
||||
if (this.config.oauthInit && error.status === 401) {
|
||||
@@ -237,6 +259,15 @@ export class AlfrescoApi implements Emitter, AlfrescoApiType {
|
||||
this.emitBuffer('error', error);
|
||||
}
|
||||
|
||||
ticketMismatchHandler(error: { newTicket?: string }) {
|
||||
if (error.newTicket) {
|
||||
this.config.ticketEcm = error.newTicket;
|
||||
this.initConfig(this.config);
|
||||
}
|
||||
|
||||
this.emitBuffer('ticket_mismatch', error);
|
||||
}
|
||||
|
||||
changeWithCredentialsConfig(withCredentials: boolean) {
|
||||
this.config.withCredentials = withCredentials;
|
||||
}
|
||||
|
@@ -243,10 +243,18 @@ export class AlfrescoApiClient implements ee.Emitter, LegacyHttpClient {
|
||||
|
||||
if (ticket) {
|
||||
return ticketParam + ticket;
|
||||
} else if (this.config.ticketEcm) {
|
||||
return ticketParam + this.config.ticketEcm;
|
||||
} else if (this.storage.getItem('ticket-ECM')) {
|
||||
return ticketParam + this.storage.getItem('ticket-ECM');
|
||||
} else {
|
||||
const ticketConfig = this.config.ticketEcm;
|
||||
const ticketStorage = this.storage.getItem('ticket-ECM');
|
||||
|
||||
if (ticketConfig && ticketStorage && ticketConfig !== ticketStorage) {
|
||||
this.emit('ticket_mismatch', { newTicket: ticketStorage });
|
||||
return ticketParam + ticketStorage;
|
||||
} else if (ticketConfig) {
|
||||
return ticketParam + ticketConfig;
|
||||
} else if (ticketStorage) {
|
||||
return ticketParam + ticketStorage;
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
|
Reference in New Issue
Block a user