[ADF-5465] Not being redirected to login page when Kerberos is enabled (#7272)

* Revert "[MNT-22334] ADW - User information not displayed when Kerberos is in use (#7172)"

This reverts commit 4befb779

* [ADF-5465] Not being redirected to login page when Kerberos is enabled

* * fix user info

* * add providers

* * fix test
This commit is contained in:
Dharan 2021-10-05 13:54:38 +05:30 committed by GitHub
parent 6f968f7e4a
commit 8a3c49ebf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 147 additions and 170 deletions

View File

@ -73,6 +73,16 @@ if [[ -n "${APP_CONFIG_ECM_HOST}" ]]; then
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
fi
if [[ -n "${APP_CONFIG_KERBEROS_ENABLED}" ]]; then
sed -e "s/\"withCredentials\": [^,]*/\"withCredentials\": ${APP_CONFIG_KERBEROS_ENABLED}/g" \
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
fi
if [[ -n "${APP_CONFIG_PROVIDERS}" ]]; then
sed -e "s/\"providers\": [^,]*/\"providers\": \"${APP_CONFIG_PROVIDERS}\"/g" \
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
fi
if [ -n "${APP_CONFIG_APPS_DEPLOYED}" ]; then
sed -e "s/\"alfresco-deployed-apps\": \[.*\]/\"alfresco-deployed-apps\": ${APP_CONFIG_APPS_DEPLOYED}/g" \
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"

View File

@ -20,4 +20,6 @@ docker run --rm -it \
--env APP_CONFIG_OAUTH2_REDIRECT_LOGOUT=$APP_CONFIG_OAUTH2_REDIRECT_LOGOUT \
--env APP_CONFIG_BPM_HOST=$APP_CONFIG_BPM_HOST \
--env APP_CONFIG_ECM_HOST=$APP_CONFIG_ECM_HOST \
--env APP_CONFIG_PROVIDERS=$APP_CONFIG_PROVIDERS \
--env APP_CONFIG_KERBEROS_ENABLED=$APP_CONFIG_KERBEROS_ENABLED \
--user 1000:1000 --publish $HOST_PORT:$CONTAINER_PORT $DOCKER_IMAGE_REPO

View File

@ -60,11 +60,29 @@ describe('AuthenticationService', () => {
jasmine.Ajax.uninstall();
});
describe('kerberos', () => {
beforeEach(() => {
appConfigService.config.providers = 'ALL';
appConfigService.config.auth = { withCredentials: true };
});
it('should emit login event for kerberos', (done) => {
spyOn(authService.peopleApi, 'getPerson').and.returnValue(Promise.resolve({}));
spyOn(authService.profileApi, 'getProfile').and.returnValue(Promise.resolve({}));
const disposableLogin = authService.onLogin.subscribe(() => {
expect(authService.profileApi.getProfile).toHaveBeenCalledTimes(1);
expect(authService.peopleApi.getPerson).toHaveBeenCalledTimes(1);
disposableLogin.unsubscribe();
done();
});
appConfigService.load();
});
});
describe('when the setting is ECM', () => {
beforeEach(() => {
appConfigService.config.providers = 'ECM';
appConfigService.config.auth = { withCredentials: false };
appConfigService.load();
apiService.reset();
});
@ -186,20 +204,12 @@ describe('AuthenticationService', () => {
it('[ECM] should return isBpmLoggedIn false', () => {
expect(authService.isBpmLoggedIn()).toBe(false);
});
it('[ECM] should return true if kerberos configured', () => {
appConfigService.config.auth.withCredentials = true;
expect(authService.isLoggedInWith('ECM')).toBe(true);
expect(authService.isLoggedIn()).toBe(true);
});
});
describe('when the setting is BPM', () => {
beforeEach(() => {
appConfigService.config.providers = 'BPM';
appConfigService.config.auth = { withCredentials: false };
appConfigService.load();
apiService.reset();
});
@ -311,14 +321,12 @@ describe('AuthenticationService', () => {
it('[BPM] should return isALLProvider false', () => {
expect(authService.isALLProvider()).toBe(false);
});
});
describe('remember me', () => {
beforeEach(() => {
appConfigService.config.providers = 'ECM';
appConfigService.config.auth = { withCredentials: false };
appConfigService.load();
apiService.reset();
});
@ -356,8 +364,7 @@ describe('AuthenticationService', () => {
it('[ECM] should not save the remember me cookie after failed login', (done) => {
const disposableLogin = authService.login('fake-username', 'fake-password').subscribe(
() => {
},
() => {},
() => {
expect(cookie['ALFRESCO_REMEMBER_ME']).toBeUndefined();
disposableLogin.unsubscribe();
@ -384,7 +391,6 @@ describe('AuthenticationService', () => {
beforeEach(() => {
appConfigService.config.providers = 'ALL';
appConfigService.config.auth = { withCredentials: false };
appConfigService.load();
apiService.reset();
});
@ -414,8 +420,7 @@ describe('AuthenticationService', () => {
it('[ALL] should return login fail if only ECM call fail', (done) => {
const disposableLogin = authService.login('fake-username', 'fake-password').subscribe(
() => {
},
() => {},
() => {
expect(authService.isLoggedIn()).toBe(false, 'isLoggedIn');
expect(authService.getTicketEcm()).toBe(null, 'getTicketEcm');
@ -437,8 +442,7 @@ describe('AuthenticationService', () => {
it('[ALL] should return login fail if only BPM call fail', (done) => {
const disposableLogin = authService.login('fake-username', 'fake-password').subscribe(
() => {
},
() => {},
() => {
expect(authService.isLoggedIn()).toBe(false);
expect(authService.getTicketEcm()).toBe(null);
@ -461,8 +465,7 @@ describe('AuthenticationService', () => {
it('[ALL] should return ticket undefined when the credentials are wrong', (done) => {
const disposableLogin = authService.login('fake-username', 'fake-password').subscribe(
() => {
},
() => {},
() => {
expect(authService.isLoggedIn()).toBe(false);
expect(authService.getTicketEcm()).toBe(null);

View File

@ -16,13 +16,13 @@
*/
import { Injectable } from '@angular/core';
import { Observable, from, throwError, Observer, ReplaySubject } from 'rxjs';
import { Observable, from, throwError, Observer, ReplaySubject, forkJoin } from 'rxjs';
import { AlfrescoApiService } from './alfresco-api.service';
import { CookieService } from './cookie.service';
import { LogService } from './log.service';
import { RedirectionModel } from '../models/redirection.model';
import { AppConfigService, AppConfigValues } from '../app-config/app-config.service';
import { UserProfileApi, UserRepresentation } from '@alfresco/js-api';
import { PeopleApi, UserProfileApi, UserRepresentation } from '@alfresco/js-api';
import { map, catchError, tap } from 'rxjs/operators';
import { HttpHeaders } from '@angular/common/http';
import { JwtHelperService } from './jwt-helper.service';
@ -39,7 +39,7 @@ export class AuthenticationService {
private bearerExcludedUrls: string[] = ['auth/realms', 'resources/', 'assets/'];
/**
* Emits Basic auth login event
* Emits login event
*/
onLogin: ReplaySubject<any> = new ReplaySubject<any>(1);
@ -48,6 +48,12 @@ export class AuthenticationService {
*/
onLogout: ReplaySubject<any> = new ReplaySubject<any>(1);
_peopleApi: PeopleApi;
get peopleApi(): PeopleApi {
this._peopleApi = this._peopleApi ?? new PeopleApi(this.alfrescoApi.getInstance());
return this._peopleApi;
}
_profileApi: UserProfileApi;
get profileApi(): UserProfileApi {
this._profileApi = this._profileApi ?? new UserProfileApi(this.alfrescoApi.getInstance());
@ -64,18 +70,31 @@ export class AuthenticationService {
this.alfrescoApi.getInstance().reply('logged-in', () => {
this.onLogin.next();
});
if (this.isKerberosEnabled()) {
this.loadUserDetails();
}
});
}
private loadUserDetails() {
const ecmUser$ = from(this.peopleApi.getPerson('-me-'));
const bpmUser$ = this.getBpmLoggedUser();
if (this.isALLProvider()) {
forkJoin([ecmUser$, bpmUser$]).subscribe(() => this.onLogin.next());
} else if (this.isECMProvider()) {
ecmUser$.subscribe(() => this.onLogin.next());
} else {
bpmUser$.subscribe(() => this.onLogin.next());
}
}
/**
* Checks if the user logged in.
* @returns True if logged in, false otherwise
*/
isLoggedIn(): boolean {
if (this.isKerberosConfigured()) {
return true;
}
if (!this.isOauth() && this.cookie.isEnabled() && !this.isRememberMeSet()) {
return false;
}
@ -92,6 +111,14 @@ export class AuthenticationService {
}
}
/**
* Does kerberos enabled?
* @returns True if enabled, false otherwise
*/
isKerberosEnabled(): boolean {
return this.appConfig.get<boolean>(AppConfigValues.AUTH_WITH_CREDENTIALS, false);
}
/**
* Does the provider support OAuth?
* @returns True if supported, false otherwise
@ -236,10 +263,6 @@ export class AuthenticationService {
* @returns True if logged in, false otherwise
*/
isEcmLoggedIn(): boolean {
if (this.isKerberosConfigured()) {
return true;
}
if (this.isECMProvider() || this.isALLProvider()) {
if (!this.isOauth() && this.cookie.isEnabled() && !this.isRememberMeSet()) {
return false;
@ -263,10 +286,6 @@ export class AuthenticationService {
return false;
}
isKerberosConfigured(): boolean {
return this.appConfig.get<boolean>(AppConfigValues.AUTH_WITH_CREDENTIALS, false);
}
/**
* Gets the ECM username.
* @returns The ECM username

View File

@ -27,7 +27,7 @@ import { IdentityUserService } from '../../services/identity-user.service';
import { BpmUserModel } from '../../models/bpm-user.model';
import { EcmUserModel } from '../../models/ecm-user.model';
import { UserInfoComponent } from './user-info.component';
import { of } from 'rxjs';
import { of, timer } from 'rxjs';
import { setupTestBed } from '../../testing/setup-test-bed';
import { CoreTestingModule } from '../../testing/core.testing.module';
import { TranslateModule } from '@ngx-translate/core';
@ -86,6 +86,12 @@ describe('User info component', () => {
fixture.detectChanges();
}
async function whenFixtureReady() {
fixture.detectChanges();
await timer(500).toPromise();
fixture.detectChanges();
}
setupTestBed({
imports: [
TranslateModule.forRoot(),
@ -160,11 +166,8 @@ describe('User info component', () => {
it('should show ecm only last name when user first name is null ', async () => {
getCurrenEcmtUserInfoStub.and.returnValue(of(fakeEcmEditedUser));
component.getUserInfo();
fixture.detectChanges();
await whenFixtureReady();
await fixture.whenStable();
fixture.detectChanges();
openUserInfo();
expect(element.querySelector('#userinfo_container')).toBeDefined();
const ecmUsername = fixture.debugElement.query(By.css('#ecm-username'));
@ -175,51 +178,39 @@ describe('User info component', () => {
});
it('should show the username when showName attribute is true', async () => {
await fixture.whenStable().then(() => {
fixture.detectChanges();
await whenFixtureReady();
expect(component.showName).toBeTruthy();
expect(element.querySelector('#adf-userinfo-ecm-name-display')).not.toBeNull();
});
});
it('should hide the username when showName attribute is false', async () => {
component.showName = false;
await fixture.whenStable();
fixture.detectChanges();
await whenFixtureReady();
expect(element.querySelector('#adf-userinfo-ecm-name-display')).toBeNull();
});
it('should have the defined class to show the name on the right side', async () => {
fixture.detectChanges();
await fixture.whenStable();
fixture.detectChanges();
await whenFixtureReady();
expect(element.querySelector('#userinfo_container').classList).toContain('adf-userinfo-name-right');
});
it('should not have the defined class to show the name on the left side', async () => {
component.namePosition = 'left';
fixture.detectChanges();
await fixture.whenStable();
fixture.detectChanges();
await whenFixtureReady();
expect(element.querySelector('#userinfo_container').classList).not.toContain('adf-userinfo-name-right');
});
describe('and has image', () => {
beforeEach(() => {
beforeEach(async () => {
isOauthStub.and.returnValue(false);
isEcmLoggedInStub.and.returnValue(true);
isLoggedInStub.and.returnValue(true);
getCurrenEcmtUserInfoStub.and.returnValue(of(fakeEcmUser));
fixture.detectChanges();
await whenFixtureReady();
});
it('should get the ecm current user image from the service', async () => {
await fixture.whenStable();
fixture.detectChanges();
openUserInfo();
const loggedImage = fixture.debugElement.query(By.css('#logged-user-img'));
@ -229,9 +220,6 @@ describe('User info component', () => {
});
it('should display the current user image if user has avatarId', (done) => {
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
openUserInfo();
const loggedImage = fixture.debugElement.query(By.css('#logged-user-img'));
component.ecmUser$.subscribe((response: EcmUserModel) => {
@ -243,12 +231,8 @@ describe('User info component', () => {
expect(loggedImage).not.toBeNull();
expect(loggedImage.properties.src).toContain('alfresco-logo.svg');
});
});
it('should get the ecm user information from the service', async () => {
fixture.detectChanges();
await fixture.whenStable();
fixture.detectChanges();
openUserInfo();
const ecmImage = fixture.debugElement.query(By.css('#ecm-user-detail-image'));
const ecmFullName = fixture.debugElement.query(By.css('#ecm-full-name'));
@ -271,8 +255,7 @@ describe('User info component', () => {
isLoggedInStub.and.returnValue(true);
isBpmLoggedInStub.and.returnValue(false);
getCurrenEcmtUserInfoStub.and.returnValue(of(fakeEcmUserNoImage));
fixture.detectChanges();
await fixture.whenStable();
await whenFixtureReady();
});
it('should show N/A when the job title is null', () => {
@ -295,20 +278,19 @@ describe('User info component', () => {
});
it('should display the current user Initials if the user dose not have avatarId', (done) => {
fixture.whenStable().then(() => {
fixture.detectChanges();
const pipe = new InitialUsernamePipe(new FakeSanitizer());
component.ecmUser$.subscribe((response: EcmUserModel) => {
expect(response).toBeDefined();
expect(response.avatarId).toBeNull();
done();
});
expect(pipe.transform({
const expected = pipe.transform({
id: 13,
firstName: 'Wilbur',
lastName: 'Adams',
email: 'wilbur@app.com'
})).toBe('<div id="user-initials-image" class="">WA</div>');
});
expect(expected).toBe('<div id="user-initials-image" class="">WA</div>');
component.ecmUser$.subscribe((response: EcmUserModel) => {
expect(response).toBeDefined();
expect(response.avatarId).toBeNull();
done();
});
});
});
@ -341,11 +323,7 @@ describe('User info component', () => {
});
it('should show full name next the user image', async () => {
getCurrentUserInfoStub.and.returnValue(of(fakeBpmUser));
component.getUserInfo();
fixture.detectChanges();
await fixture.whenStable();
fixture.detectChanges();
await whenFixtureReady();
openUserInfo();
const bpmUserName = fixture.debugElement.query(By.css('#bpm-username'));
expect(element.querySelector('#userinfo_container')).not.toBeNull();
@ -355,10 +333,7 @@ describe('User info component', () => {
});
it('should get the bpm current user image from the service', async () => {
getCurrentUserInfoStub.and.returnValue(of(fakeBpmUser));
fixture.detectChanges();
await fixture.whenStable();
fixture.detectChanges();
await whenFixtureReady();
expect(element.querySelector('#userinfo_container')).not.toBeNull();
expect(element.querySelector('#logged-user-img')).not.toBeNull();
expect(element.querySelector('#logged-user-img').getAttribute('src'))
@ -366,15 +341,12 @@ describe('User info component', () => {
});
it('should show last name if first name is null', async () => {
fixture.detectChanges();
const wrongBpmUser: BpmUserModel = new BpmUserModel({
firstName: null,
lastName: 'fake-last-name'
});
getCurrentUserInfoStub.and.returnValue(of(wrongBpmUser));
component.getUserInfo();
fixture.detectChanges();
await fixture.whenStable();
await whenFixtureReady();
const fullNameElement = (element.querySelector('#adf-userinfo-bpm-name-display'));
fixture.detectChanges();
expect(element.querySelector('#userinfo_container')).toBeDefined();
@ -389,10 +361,8 @@ describe('User info component', () => {
lastName: 'fake-last-name'
});
getCurrentUserInfoStub.and.returnValue(of(wrongFirstNameBpmUser));
await whenFixtureReady();
fixture.detectChanges();
await fixture.whenStable();
fixture.detectChanges();
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#adf-userinfo-bpm-name-display')).toBeDefined();
expect(element.querySelector('#adf-userinfo-bpm-name-display').textContent).toContain('fake-last-name');
@ -405,11 +375,8 @@ describe('User info component', () => {
lastName: 'null'
});
getCurrentUserInfoStub.and.returnValue(of(wrongLastNameBpmUser));
component.getUserInfo();
fixture.detectChanges();
await whenFixtureReady();
await fixture.whenStable();
fixture.detectChanges();
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#adf-userinfo-bpm-name-display')).toBeDefined();
expect(element.querySelector('#adf-userinfo-bpm-name-display').textContent).toContain('fake-first-name');
@ -417,7 +384,7 @@ describe('User info component', () => {
});
it('should not show the tabs', async () => {
fixture.detectChanges();
await whenFixtureReady();
openUserInfo();
await fixture.whenStable();
fixture.detectChanges();
@ -437,35 +404,8 @@ describe('User info component', () => {
spyOn(bpmUserService, 'getCurrentUserInfo').and.returnValue(of(fakeBpmUser));
});
it('should able to fetch ecm userInfo', (done) => {
fixture.detectChanges();
fixture.whenStable().then(() => {
component.ecmUser$.subscribe((response: EcmUserModel) => {
expect(response).toBeDefined();
expect(response.firstName).toBe('fake-ecm-first-name');
expect(response.lastName).toBe('fake-ecm-last-name');
expect(response.email).toBe('fakeEcm@ecmUser.com');
done();
});
});
});
it('should able to fetch bpm userInfo', (done) => {
fixture.detectChanges();
fixture.whenStable().then(() => {
component.bpmUser$.subscribe((response: BpmUserModel) => {
expect(response).toBeDefined();
expect(response.firstName).toBe('fake-bpm-first-name');
expect(response.lastName).toBe('fake-bpm-last-name');
expect(response.email).toBe('fakeBpm@fake.com');
done();
});
});
});
it('should get the bpm user information from the service', async () => {
await whenFixtureReady();
openUserInfo();
const bpmTab = fixture.debugElement.queryAll(By.css('#tab-group-env .mat-tab-labels .mat-tab-label'))[1];
bpmTab.triggerEventHandler('click', null);
@ -482,6 +422,7 @@ describe('User info component', () => {
});
it('should get the ecm user information from the service', async () => {
await whenFixtureReady();
openUserInfo();
const ecmUsername = fixture.debugElement.query(By.css('#ecm-username'));
const ecmImage = fixture.debugElement.query(By.css('#ecm-user-detail-image'));
@ -496,7 +437,8 @@ describe('User info component', () => {
expect(fixture.debugElement.query(By.css('#ecm-job-title')).nativeElement.textContent).toContain('job-ecm-test');
});
it('should show the ecm image if exists', () => {
it('should show the ecm image if exists', async () => {
await whenFixtureReady();
openUserInfo();
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#logged-user-img')).toBeDefined();
@ -505,15 +447,14 @@ describe('User info component', () => {
it('should show the ecm initials if the ecm user has no image', async () => {
getCurrenEcmtUserInfoStub.and.returnValue(of(fakeEcmUserNoImage));
fixture.detectChanges();
await whenFixtureReady();
await fixture.whenStable();
fixture.detectChanges();
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#user-initials-image').textContent).toContain('ff');
});
it('should show the tabs for the env', () => {
it('should show the tabs for the env', async () => {
await whenFixtureReady();
openUserInfo();
const tabGroup = fixture.debugElement.query(By.css('#tab-group-env'));
const tabs = fixture.debugElement.queryAll(By.css('#tab-group-env .mat-tab-labels .mat-tab-label'));
@ -523,7 +464,8 @@ describe('User info component', () => {
expect(tabs.length).toBe(2);
});
it('should not close the menu when a tab is clicked', () => {
it('should not close the menu when a tab is clicked', async () => {
await whenFixtureReady();
openUserInfo();
const tabGroup = fixture.debugElement.query(By.css('#tab-group-env'));
const tabs = fixture.debugElement.queryAll(By.css('#tab-group-env .mat-tab-labels .mat-tab-label'));
@ -547,9 +489,7 @@ describe('User info component', () => {
});
it('should show the identity user initials if is not ecm user', async () => {
fixture.detectChanges();
await fixture.whenStable();
fixture.detectChanges();
await whenFixtureReady();
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#user-initials-image').textContent).toContain('ff');
});
@ -569,8 +509,8 @@ describe('User info component', () => {
});
it('should show full name next the user image', async () => {
fixture.detectChanges();
await fixture.whenStable();
await whenFixtureReady();
const imageButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#identity-user-image');
imageButton.click();
fixture.detectChanges();
@ -582,13 +522,9 @@ describe('User info component', () => {
});
it('should show last name if first name is null', async () => {
fixture.detectChanges();
getCurrentUserInfoStub.and.returnValue(identityUserWithOutFirstNameMock);
component.getUserInfo();
await whenFixtureReady();
fixture.detectChanges();
await fixture.whenStable();
fixture.detectChanges();
const fullNameElement = element.querySelector('#adf-userinfo-identity-name-display');
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#adf-userinfo-identity-name-display')).not.toBeNull();
@ -598,9 +534,8 @@ describe('User info component', () => {
it('should not show first name if it is null string', async () => {
getCurrentUserInfoStub.and.returnValue(identityUserWithOutFirstNameMock);
component.getUserInfo();
fixture.detectChanges();
await fixture.whenStable();
await whenFixtureReady();
const fullNameElement = element.querySelector('#adf-userinfo-identity-name-display');
fixture.detectChanges();
expect(element.querySelector('#userinfo_container')).toBeDefined();
@ -611,10 +546,8 @@ describe('User info component', () => {
it('should not show last name if it is null string', async () => {
getCurrentUserInfoStub.and.returnValue(identityUserWithOutLastNameMock);
component.getUserInfo();
fixture.detectChanges();
await whenFixtureReady();
await fixture.whenStable();
const fullNameElement = element.querySelector('#adf-userinfo-identity-name-display');
fixture.detectChanges();
expect(element.querySelector('#userinfo_container')).toBeDefined();
@ -627,10 +560,8 @@ describe('User info component', () => {
getCurrentUserInfoStub.and.returnValue(identityUserWithOutLastNameMock);
getCurrenEcmtUserInfoStub.and.returnValue(of(fakeEcmUser));
isEcmLoggedInStub.and.returnValue(true);
fixture.detectChanges();
await whenFixtureReady();
await fixture.whenStable();
fixture.detectChanges();
expect(element.querySelector('.adf-userinfo-pic')).toBeNull();
expect(element.querySelector('.adf-userinfo-profile-image')).toBeDefined();
expect(element.querySelector('.adf-userinfo-profile-image')).not.toBeNull();

View File

@ -15,7 +15,7 @@
* limitations under the License.
*/
import { Component, Input, OnInit, ViewEncapsulation, ViewChild } from '@angular/core';
import { Component, Input, OnInit, ViewEncapsulation, ViewChild, OnDestroy } from '@angular/core';
import { AuthenticationService } from '../../services/authentication.service';
import { BpmUserModel } from '../../models/bpm-user.model';
import { EcmUserModel } from '../../models/ecm-user.model';
@ -23,8 +23,9 @@ import { IdentityUserModel } from '../../models/identity-user.model';
import { BpmUserService } from '../../services/bpm-user.service';
import { EcmUserService } from '../../services/ecm-user.service';
import { IdentityUserService } from '../../services/identity-user.service';
import { of, Observable } from 'rxjs';
import { of, Observable, Subject } from 'rxjs';
import { MatMenuTrigger, MenuPositionX, MenuPositionY } from '@angular/material/menu';
import { debounceTime, startWith, takeUntil } from 'rxjs/operators';
@Component({
selector: 'adf-userinfo',
@ -32,7 +33,7 @@ import { MatMenuTrigger, MenuPositionX, MenuPositionY } from '@angular/material/
styleUrls: ['./user-info.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class UserInfoComponent implements OnInit {
export class UserInfoComponent implements OnInit, OnDestroy {
@ViewChild(MatMenuTrigger) trigger: MatMenuTrigger;
@ -68,6 +69,7 @@ export class UserInfoComponent implements OnInit {
bpmUser$: Observable<BpmUserModel>;
identityUser$: Observable<IdentityUserModel>;
selectedIndex: number;
private destroy$ = new Subject();
constructor(private ecmUserService: EcmUserService,
private bpmUserService: BpmUserService,
@ -76,7 +78,17 @@ export class UserInfoComponent implements OnInit {
}
ngOnInit() {
this.getUserInfo();
this.authService.onLogin
.pipe(
startWith(this.authService.isLoggedIn()),
debounceTime(500),
takeUntil(this.destroy$)
).subscribe(() => this.getUserInfo());
}
ngOnDestroy(): void {
this.destroy$.next(true);
this.destroy$.complete();
}
getUserInfo() {