From 15d91ca5e0fffbee491964073cf98fefcea018a0 Mon Sep 17 00:00:00 2001 From: Dharan <14145706+dhrn@users.noreply.github.com> Date: Thu, 4 Nov 2021 16:25:30 +0530 Subject: [PATCH] [ADF-5465] Not being redirected to login page when Kerberos is enabled (#7348) * [ADF-5465] Not being redirected to login page when Kerberos is enabled * [ci:force] force CI * [ci:force] force CI --- .../components/user-info.component.spec.ts | 39 +++++++++++++++++++ .../components/user-info.component.ts | 27 ++++++++----- 2 files changed, 57 insertions(+), 9 deletions(-) diff --git a/lib/core/userinfo/components/user-info.component.spec.ts b/lib/core/userinfo/components/user-info.component.spec.ts index 35e6d86e1d..8002e44205 100644 --- a/lib/core/userinfo/components/user-info.component.spec.ts +++ b/lib/core/userinfo/components/user-info.component.spec.ts @@ -567,5 +567,44 @@ describe('User info component', () => { expect(element.querySelector('.adf-userinfo-profile-image')).not.toBeNull(); }); }); + + describe('kerberos', () => { + + beforeEach(async () => { + isOauthStub.and.returnValue(false); + isEcmLoggedInStub.and.returnValue(false); + isBpmLoggedInStub.and.returnValue(false); + isLoggedInStub.and.returnValue(false); + spyOn(authService, 'isKerberosEnabled').and.returnValue(true); + spyOn(authService, 'isALLProvider').and.returnValue(true); + spyOn(bpmUserService, 'getCurrentUserInfo').and.returnValue(of(fakeBpmUser)); + getCurrenEcmtUserInfoStub.and.returnValue(of(fakeEcmUser)); + + await whenFixtureReady(); + }); + + it('should show the bpm user information', async () => { + openUserInfo(); + const bpmTab = fixture.debugElement.queryAll(By.css('#tab-group-env .mat-tab-labels .mat-tab-label'))[1]; + bpmTab.triggerEventHandler('click', null); + fixture.detectChanges(); + await fixture.whenStable(); + const bpmUsername = fixture.debugElement.query(By.css('#bpm-username')); + const bpmImage = fixture.debugElement.query(By.css('#bpm-user-detail-image')); + expect(bpmImage.properties.src).toContain('app/rest/admin/profile-picture'); + expect(bpmUsername.nativeElement.textContent).toContain('fake-bpm-first-name fake-bpm-last-name'); + expect(fixture.debugElement.query(By.css('#bpm-tenant')).nativeElement.textContent).toContain('fake-tenant-name'); + }); + + it('should show the ecm user information', async () => { + openUserInfo(); + const ecmTab = fixture.debugElement.queryAll(By.css('#tab-group-env .mat-tab-labels .mat-tab-label'))[0]; + ecmTab.triggerEventHandler('click', null); + fixture.detectChanges(); + await fixture.whenStable(); + expect(fixture.debugElement.query(By.css('#ecm-full-name')).nativeElement.textContent).toContain('fake-ecm-first-name fake-ecm-last-name'); + expect(fixture.debugElement.query(By.css('#ecm-job-title')).nativeElement.textContent).toContain('job-ecm-test'); + }); + }); }); }); diff --git a/lib/core/userinfo/components/user-info.component.ts b/lib/core/userinfo/components/user-info.component.ts index a0d70c477b..3929fc1ab2 100644 --- a/lib/core/userinfo/components/user-info.component.ts +++ b/lib/core/userinfo/components/user-info.component.ts @@ -25,7 +25,6 @@ import { EcmUserService } from '../../services/ecm-user.service'; import { IdentityUserService } from '../../services/identity-user.service'; import { of, Observable, Subject } from 'rxjs'; import { MatMenuTrigger, MenuPositionX, MenuPositionY } from '@angular/material/menu'; -import { filter, takeUntil } from 'rxjs/operators'; @Component({ selector: 'adf-userinfo', @@ -75,11 +74,6 @@ export class UserInfoComponent implements OnInit, OnDestroy { private bpmUserService: BpmUserService, private identityUserService: IdentityUserService, private authService: AuthenticationService) { - this.authService.onLogin - .pipe( - filter(() => this.authService.isKerberosEnabled()), - takeUntil(this.destroy$) - ).subscribe(() => this.getUserInfo()); } ngOnInit() { @@ -100,14 +94,14 @@ export class UserInfoComponent implements OnInit, OnDestroy { this.loadEcmUserInfo(); } - } else if (this.authService.isEcmLoggedIn() && this.authService.isBpmLoggedIn()) { + } else if (this.isAllLoggedIn()) { this.loadEcmUserInfo(); this.loadBpmUserInfo(); this.mode = 'ALL'; - } else if (this.authService.isEcmLoggedIn()) { + } else if (this.isEcmLoggedIn()) { this.loadEcmUserInfo(); this.mode = 'CONTENT'; - } else if (this.authService.isBpmLoggedIn()) { + } else if (this.isBpmLoggedIn()) { this.loadBpmUserInfo(); this.mode = 'PROCESS'; } @@ -124,6 +118,9 @@ export class UserInfoComponent implements OnInit, OnDestroy { } get isLoggedIn(): boolean { + if (this.authService.isKerberosEnabled()) { + return true; + } return this.authService.isLoggedIn(); } @@ -139,6 +136,18 @@ export class UserInfoComponent implements OnInit, OnDestroy { this.identityUser$ = of(this.identityUserService.getCurrentUserInfo()); } + private isAllLoggedIn() { + return (this.authService.isEcmLoggedIn() && this.authService.isBpmLoggedIn()) || (this.authService.isALLProvider() && this.authService.isKerberosEnabled()); + } + + private isBpmLoggedIn() { + return this.authService.isBpmLoggedIn() || (this.authService.isECMProvider() && this.authService.isKerberosEnabled()); + } + + private isEcmLoggedIn() { + return this.authService.isEcmLoggedIn() || (this.authService.isECMProvider() && this.authService.isKerberosEnabled()); + } + stopClosing(event: Event) { event.stopPropagation(); }