[AAE-12501] Replace oauth2Auth with authentication service, define get username as abstract

This commit is contained in:
Amedeo Lepore
2023-03-31 12:12:02 +02:00
parent 39d6674ee5
commit b9ceb7f758
4 changed files with 43 additions and 31 deletions
@@ -16,9 +16,9 @@
*/
import { Injectable } from '@angular/core';
import { OAuthService, OAuthStorage } from 'angular-oauth2-oidc';
import { OAuthEvent, OAuthService, OAuthStorage } from 'angular-oauth2-oidc';
import { EMPTY, Observable } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { catchError, filter, map } from 'rxjs/operators';
import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service';
import { OauthConfigModel } from '../models/oauth-config.model';
import { AlfrescoApiService } from '../../services/alfresco-api.service';
@@ -46,11 +46,6 @@ export class OIDCAuthenticationService extends BaseAuthenticationService {
private readonly auth: AuthService
) {
super(alfrescoApi, appConfig, cookie, logService);
this.alfrescoApi.alfrescoApiInitialized.subscribe(() => {
this.alfrescoApi.getInstance().reply('logged-in', () => {
this.onLogin.next();
});
});
}
isEcmLoggedIn(): boolean {
@@ -97,6 +92,14 @@ export class OIDCAuthenticationService extends BaseAuthenticationService {
);
}
getEcmUsername(): string {
return (this.oauthService.getIdentityClaims() as any).preferred_username;
}
getBpmUsername(): string {
return (this.oauthService.getIdentityClaims() as any).preferred_username;
}
ssoImplicitLogin() {
this.oauthService.initLoginFlow();
}
@@ -127,4 +130,8 @@ export class OIDCAuthenticationService extends BaseAuthenticationService {
this.auth.login();
}
}
once(event: string): Observable<OAuthEvent> {
return this.oauthService.events.pipe(filter(_event => _event.type === event));
}
}
@@ -161,6 +161,24 @@ export class AuthenticationService extends BaseAuthenticationService {
return false;
}
/**
* Gets the ECM username.
*
* @returns The ECM username
*/
getEcmUsername(): string {
return this.alfrescoApi.getInstance().getEcmUsername();
}
/**
* Gets the BPM username
*
* @returns The BPM username
*/
getBpmUsername(): string {
return this.alfrescoApi.getInstance().getBpmUsername();
}
isImplicitFlow(): boolean {
const oauth2: OauthConfigModel = Object.assign({}, this.appConfig.get<OauthConfigModel>(AppConfigValues.OAUTHCONFIG, null));
return !!oauth2?.implicitFlow;
@@ -179,5 +197,11 @@ export class AuthenticationService extends BaseAuthenticationService {
return this.storageService.getItem(JwtHelperService.USER_ACCESS_TOKEN);
}
reset() {}
reset() { }
once(event: string): Observable<any> {
return new Observable((subscriber) => {
this.alfrescoApi.getInstance().once(event, () => subscriber.next());
});
}
}
@@ -65,7 +65,10 @@ export abstract class BaseAuthenticationService {
abstract logout(): Observable<any>;
abstract isEcmLoggedIn(): boolean;
abstract isBpmLoggedIn(): boolean;
abstract getEcmUsername(): string;
abstract getBpmUsername(): string;
abstract reset(): void;
abstract once(event: string): Observable<any>;
getBearerExcludedUrls(): readonly string[] {
return this.bearerExcludedUrls;
@@ -127,24 +130,6 @@ export abstract class BaseAuthenticationService {
return header.set('Authorization', ticket);
}
/**
* Gets the ECM username.
*
* @returns The ECM username
*/
getEcmUsername(): string {
return this.alfrescoApi.getInstance().getEcmUsername();
}
/**
* Gets the BPM username
*
* @returns The BPM username
*/
getBpmUsername(): string {
return this.alfrescoApi.getInstance().getBpmUsername();
}
isPublicUrl(): boolean {
return this.alfrescoApi.getInstance().isPublicUrl();
}