[ADF-3251] Authentication Service - Check if used loggedin based on the provider (#3515)

* check if loggedin based on the provider

* Fix unit tests
This commit is contained in:
Maurizio Vitale
2018-06-21 18:56:00 +01:00
committed by Eugenio Romano
parent 3e0e2609f7
commit 9b2d51dbd5
2 changed files with 68 additions and 6 deletions

View File

@@ -129,6 +129,7 @@ describe('AuthenticationService', () => {
it('should require remember me set for ECM check', () => {
spyOn(cookie, 'isEnabled').and.returnValue(true);
spyOn(authService, 'isRememberMeSet').and.returnValue(false);
spyOn(authService, 'isECMProvider').and.returnValue(true);
spyOn(authService, 'isOauth').and.returnValue(false);
spyOn(apiService, 'getInstance').and.callThrough();
@@ -139,6 +140,7 @@ describe('AuthenticationService', () => {
it('should not require cookie service enabled for ECM check', () => {
spyOn(cookie, 'isEnabled').and.returnValue(false);
spyOn(authService, 'isRememberMeSet').and.returnValue(false);
spyOn(authService, 'isECMProvider').and.returnValue(true);
spyOn(authService, 'isOauth').and.returnValue(false);
spyOn(apiService, 'getInstance').and.callThrough();
@@ -220,6 +222,22 @@ describe('AuthenticationService', () => {
expect(authService.getRedirect(appConfigService.config.providers)).toBeNull();
});
it('[ECM] should return isECMProvider true', () => {
expect(authService.isECMProvider()).toBe(true);
});
it('[ECM] should return isBPMProvider false', () => {
expect(authService.isBPMProvider()).toBe(false);
});
it('[ECM] should return isALLProvider false', () => {
expect(authService.isALLProvider()).toBe(false);
});
it('[ECM] should return isBpmLoggedIn false', () => {
expect(authService.isBpmLoggedIn()).toBe(false);
});
});
describe('when the setting is BPM', () => {
@@ -233,6 +251,7 @@ describe('AuthenticationService', () => {
it('should require remember me set for BPM check', () => {
spyOn(cookie, 'isEnabled').and.returnValue(true);
spyOn(authService, 'isRememberMeSet').and.returnValue(false);
spyOn(authService, 'isBPMProvider').and.returnValue(true);
spyOn(authService, 'isOauth').and.returnValue(false);
spyOn(apiService, 'getInstance').and.callThrough();
@@ -243,6 +262,7 @@ describe('AuthenticationService', () => {
it('should not require cookie service enabled for BPM check', () => {
spyOn(cookie, 'isEnabled').and.returnValue(false);
spyOn(authService, 'isRememberMeSet').and.returnValue(false);
spyOn(authService, 'isBPMProvider').and.returnValue(true);
spyOn(apiService, 'getInstance').and.callThrough();
expect(authService.isBpmLoggedIn()).toBeFalsy();
@@ -317,6 +337,18 @@ describe('AuthenticationService', () => {
expect(authService.getRedirect(appConfigService.config.providers)).toBeNull();
});
it('[BPM] should return isECMProvider false', () => {
expect(authService.isECMProvider()).toBe(false);
});
it('[BPM] should return isBPMProvider true', () => {
expect(authService.isBPMProvider()).toBe(true);
});
it('[BPM] should return isALLProvider false', () => {
expect(authService.isALLProvider()).toBe(false);
});
});
describe('when the setting is both ECM and BPM ', () => {
@@ -441,6 +473,18 @@ describe('AuthenticationService', () => {
expect(authService.getRedirect(appConfigService.config.providers)).toBeNull();
});
it('[ALL] should return isECMProvider false', () => {
expect(authService.isECMProvider()).toBe(false);
});
it('[ALL] should return isBPMProvider false', () => {
expect(authService.isBPMProvider()).toBe(false);
});
it('[ALL] should return isALLProvider true', () => {
expect(authService.isALLProvider()).toBe(true);
});
});
});

View File

@@ -56,6 +56,18 @@ export class AuthenticationService {
return this.alfrescoApi.getInstance().isOauthConfiguration();
}
isECMProvider(): boolean {
return this.alfrescoApi.getInstance().isEcmConfiguration();
}
isBPMProvider(): boolean {
return this.alfrescoApi.getInstance().isBpmConfiguration();
}
isALLProvider(): boolean {
return this.alfrescoApi.getInstance().isEcmBpmConfiguration();
}
/**
* Logs the user in.
* @param username Username for the login
@@ -162,22 +174,28 @@ export class AuthenticationService {
* @returns True if logged in, false otherwise
*/
isEcmLoggedIn(): boolean {
if (this.isECMProvider() || this.isALLProvider()) {
if (!this.isOauth() && this.cookie.isEnabled() && !this.isRememberMeSet()) {
return false;
}
return this.alfrescoApi.getInstance().isEcmLoggedIn();
}
return false;
}
/**
* Checks if the user is logged in on a BPM provider.
* @returns True if logged in, false otherwise
*/
isBpmLoggedIn(): boolean {
if (this.isBPMProvider() || this.isALLProvider()) {
if (!this.isOauth() && this.cookie.isEnabled() && !this.isRememberMeSet()) {
return false;
}
return this.alfrescoApi.getInstance().isBpmLoggedIn();
}
return false;
}
/**
* Gets the ECM username.