mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-10 14:11:42 +00:00
[ACS-9768] remove deprecated methods from auth related components (#11031)
* [ACS-9768] remove deprecated methods from auth related components * [ACS-9768] remove deprecated method, adjust unit tests * [ACS-9768] fix sonar cloud issues * [ACS-9768] fix auth mocks * [ACS-9768] fix sonar cloud alerts * [ACS-9768] update method name in docs
This commit is contained in:
committed by
GitHub
parent
dabab63f78
commit
04d488b8ea
@@ -65,7 +65,7 @@ class AppComponent {
|
|||||||
|
|
||||||
onLoggedIn() {
|
onLoggedIn() {
|
||||||
this.userPreferences.setStoragePrefix(
|
this.userPreferences.setStoragePrefix(
|
||||||
this.authService.getEcmUsername()
|
this.authService.getUsername()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -38,11 +38,14 @@ export class DiscoveryApiService {
|
|||||||
*/
|
*/
|
||||||
ecmProductInfo$ = new Subject<RepositoryInfo>();
|
ecmProductInfo$ = new Subject<RepositoryInfo>();
|
||||||
|
|
||||||
constructor(private authenticationService: AuthenticationService, private alfrescoApiService: AlfrescoApiService) {
|
constructor(
|
||||||
|
private readonly authenticationService: AuthenticationService,
|
||||||
|
private readonly alfrescoApiService: AlfrescoApiService
|
||||||
|
) {
|
||||||
this.authenticationService.onLogin.subscribe(() => {
|
this.authenticationService.onLogin.subscribe(() => {
|
||||||
this.alfrescoApiService.alfrescoApiInitialized
|
this.alfrescoApiService.alfrescoApiInitialized
|
||||||
.pipe(
|
.pipe(
|
||||||
filter(() => this.authenticationService.isEcmLoggedIn()),
|
filter(() => this.authenticationService.isLoggedIn()),
|
||||||
take(1),
|
take(1),
|
||||||
switchMap(() => this.getEcmProductInfo())
|
switchMap(() => this.getEcmProductInfo())
|
||||||
)
|
)
|
||||||
|
@@ -36,7 +36,6 @@ class AlfrescoApiMock {
|
|||||||
isOauthConfiguration = () => true;
|
isOauthConfiguration = () => true;
|
||||||
isLoggedIn = () => true;
|
isLoggedIn = () => true;
|
||||||
isEcmConfiguration = () => true;
|
isEcmConfiguration = () => true;
|
||||||
isEcmLoggedIn = () => true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ContentApiMock {
|
export class ContentApiMock {
|
||||||
|
@@ -50,7 +50,7 @@ describe('NodeDownloadDirective', () => {
|
|||||||
oauth2Auth: {
|
oauth2Auth: {
|
||||||
callCustomApi: () => Promise.resolve()
|
callCustomApi: () => Promise.resolve()
|
||||||
},
|
},
|
||||||
isEcmLoggedIn: jasmine.createSpy('isEcmLoggedIn'),
|
isLoggedIn: jasmine.createSpy('isLoggedIn'),
|
||||||
reply: jasmine.createSpy('reply')
|
reply: jasmine.createSpy('reply')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -69,7 +69,7 @@ describe('SearchControlComponent', () => {
|
|||||||
searchService = TestBed.inject(SearchService);
|
searchService = TestBed.inject(SearchService);
|
||||||
authService = TestBed.inject(AuthenticationService);
|
authService = TestBed.inject(AuthenticationService);
|
||||||
userPreferencesService = TestBed.inject(UserPreferencesService);
|
userPreferencesService = TestBed.inject(UserPreferencesService);
|
||||||
spyOn(authService, 'isEcmLoggedIn').and.returnValue(true);
|
spyOn(authService, 'isLoggedIn').and.returnValue(true);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
element = fixture.nativeElement;
|
element = fixture.nativeElement;
|
||||||
|
|
||||||
|
@@ -109,13 +109,16 @@ export class SearchControlComponent {
|
|||||||
noSearchResultTemplate: TemplateRef<any> = null;
|
noSearchResultTemplate: TemplateRef<any> = null;
|
||||||
searchTerm: string = '';
|
searchTerm: string = '';
|
||||||
|
|
||||||
constructor(public authService: AuthenticationService, private thumbnailService: ThumbnailService) {}
|
constructor(
|
||||||
|
public authService: AuthenticationService,
|
||||||
|
private readonly thumbnailService: ThumbnailService
|
||||||
|
) {}
|
||||||
|
|
||||||
isNoSearchTemplatePresent(): boolean {
|
isNoSearchTemplatePresent(): boolean {
|
||||||
return !!this.emptySearchTemplate;
|
return !!this.emptySearchTemplate;
|
||||||
}
|
}
|
||||||
isLoggedIn(): boolean {
|
isLoggedIn(): boolean {
|
||||||
return this.authService.isEcmLoggedIn();
|
return this.authService.isLoggedIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
inputChange(value: string) {
|
inputChange(value: string) {
|
||||||
|
@@ -127,22 +127,6 @@ describe('BasicAlfrescoAuthService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('isBpmLoggedIn should return value from processAuth', () => {
|
|
||||||
spyOn(processAuth, 'isLoggedIn').and.returnValue(true);
|
|
||||||
const result = basicAlfrescoAuthService.isBpmLoggedIn();
|
|
||||||
|
|
||||||
expect(result).toBeTrue();
|
|
||||||
expect(processAuth.isLoggedIn).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('isEcmLoggedIn should return value from contentAuth', () => {
|
|
||||||
spyOn(contentAuth, 'isLoggedIn').and.returnValue(true);
|
|
||||||
const result = basicAlfrescoAuthService.isEcmLoggedIn();
|
|
||||||
|
|
||||||
expect(result).toBeTrue();
|
|
||||||
expect(contentAuth.isLoggedIn).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('isLoggedIn', () => {
|
describe('isLoggedIn', () => {
|
||||||
let contentAuthSpy: jasmine.Spy;
|
let contentAuthSpy: jasmine.Spy;
|
||||||
let processAuthSpy: jasmine.Spy;
|
let processAuthSpy: jasmine.Spy;
|
||||||
|
@@ -43,7 +43,12 @@ export class BasicAlfrescoAuthService extends BaseAuthenticationService {
|
|||||||
type: 'basic'
|
type: 'basic'
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(appConfig: AppConfigService, cookie: CookieService, private contentAuth: ContentAuth, private processAuth: ProcessAuth) {
|
constructor(
|
||||||
|
appConfig: AppConfigService,
|
||||||
|
cookie: CookieService,
|
||||||
|
private readonly contentAuth: ContentAuth,
|
||||||
|
private readonly processAuth: ProcessAuth
|
||||||
|
) {
|
||||||
super(appConfig, cookie);
|
super(appConfig, cookie);
|
||||||
|
|
||||||
this.appConfig.onLoad.subscribe(() => {
|
this.appConfig.onLoad.subscribe(() => {
|
||||||
@@ -214,30 +219,6 @@ export class BasicAlfrescoAuthService extends BaseAuthenticationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* @returns content auth token
|
|
||||||
*/
|
|
||||||
getTicketEcm(): string {
|
|
||||||
return this.contentAuth.getToken();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* @returns process auth token
|
|
||||||
*/
|
|
||||||
getTicketBpm(): string {
|
|
||||||
return this.processAuth.getToken();
|
|
||||||
}
|
|
||||||
|
|
||||||
isBpmLoggedIn(): boolean {
|
|
||||||
return this.processAuth.isLoggedIn();
|
|
||||||
}
|
|
||||||
|
|
||||||
isEcmLoggedIn(): boolean {
|
|
||||||
return this.contentAuth.isLoggedIn();
|
|
||||||
}
|
|
||||||
|
|
||||||
isLoggedIn(): boolean {
|
isLoggedIn(): boolean {
|
||||||
const authWithCredentials = this.isKerberosEnabled();
|
const authWithCredentials = this.isKerberosEnabled();
|
||||||
|
|
||||||
@@ -317,22 +298,6 @@ export class BasicAlfrescoAuthService extends BaseAuthenticationService {
|
|||||||
return this.redirectUrl && (this.redirectUrl.provider === 'ALL' || provider === 'ALL');
|
return this.redirectUrl && (this.redirectUrl.provider === 'ALL' || provider === 'ALL');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated use `getUsername()` instead
|
|
||||||
* @returns the username of the authenticated user
|
|
||||||
*/
|
|
||||||
getBpmUsername(): string {
|
|
||||||
return this.processAuth.getUsername();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated use `getUsername()` instead
|
|
||||||
* @returns the username of the authenticated user
|
|
||||||
*/
|
|
||||||
getEcmUsername(): string {
|
|
||||||
return this.contentAuth.getUsername();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the username of the authenticated user.
|
* Gets the username of the authenticated user.
|
||||||
*
|
*
|
||||||
|
@@ -71,7 +71,7 @@ describe('AuthGuardService BPM', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should redirect url if the alfresco js api is NOT logged in and isOAuth with silentLogin', async () => {
|
it('should redirect url if the alfresco js api is NOT logged in and isOAuth with silentLogin', async () => {
|
||||||
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isLoggedIn').and.returnValue(false);
|
||||||
spyOn(authService, 'isOauth').and.returnValue(true);
|
spyOn(authService, 'isOauth').and.returnValue(true);
|
||||||
spyOn(oidcAuthenticationService, 'isPublicUrl').and.returnValue(false);
|
spyOn(oidcAuthenticationService, 'isPublicUrl').and.returnValue(false);
|
||||||
spyOn(oidcAuthenticationService, 'ssoLogin').and.stub();
|
spyOn(oidcAuthenticationService, 'ssoLogin').and.stub();
|
||||||
@@ -101,7 +101,7 @@ describe('AuthGuardService BPM', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('if the alfresco js api is configured with withCredentials true should canActivate be true', async () => {
|
it('if the alfresco js api is configured with withCredentials true should canActivate be true', async () => {
|
||||||
spyOn(authService, 'isBpmLoggedIn').and.returnValue(true);
|
spyOn(authService, 'isLoggedIn').and.returnValue(true);
|
||||||
appConfigService.config.auth.withCredentials = true;
|
appConfigService.config.auth.withCredentials = true;
|
||||||
|
|
||||||
authGuard = TestBed.runInInjectionContext(() => AuthGuardBpm(route, state)) as Promise<boolean>;
|
authGuard = TestBed.runInInjectionContext(() => AuthGuardBpm(route, state)) as Promise<boolean>;
|
||||||
@@ -110,7 +110,7 @@ describe('AuthGuardService BPM', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('if the alfresco js api is NOT logged in should canActivate be false', async () => {
|
it('if the alfresco js api is NOT logged in should canActivate be false', async () => {
|
||||||
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isLoggedIn').and.returnValue(false);
|
||||||
|
|
||||||
authGuard = TestBed.runInInjectionContext(() => AuthGuardBpm(route, state)) as Promise<boolean>;
|
authGuard = TestBed.runInInjectionContext(() => AuthGuardBpm(route, state)) as Promise<boolean>;
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ describe('AuthGuardService BPM', () => {
|
|||||||
|
|
||||||
it('if the alfresco js api is NOT logged in should trigger a redirect event', async () => {
|
it('if the alfresco js api is NOT logged in should trigger a redirect event', async () => {
|
||||||
appConfigService.config.loginRoute = 'login';
|
appConfigService.config.loginRoute = 'login';
|
||||||
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isLoggedIn').and.returnValue(false);
|
||||||
|
|
||||||
authGuard = TestBed.runInInjectionContext(() => AuthGuardBpm(route, state)) as Promise<boolean>;
|
authGuard = TestBed.runInInjectionContext(() => AuthGuardBpm(route, state)) as Promise<boolean>;
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ describe('AuthGuardService BPM', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async () => {
|
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async () => {
|
||||||
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isLoggedIn').and.returnValue(false);
|
||||||
spyOn(authService, 'isOauth').and.returnValue(true);
|
spyOn(authService, 'isOauth').and.returnValue(true);
|
||||||
appConfigService.config.oauth2.silentLogin = false;
|
appConfigService.config.oauth2.silentLogin = false;
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ describe('AuthGuardService BPM', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async () => {
|
it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async () => {
|
||||||
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isLoggedIn').and.returnValue(false);
|
||||||
spyOn(authService, 'isOauth').and.returnValue(true);
|
spyOn(authService, 'isOauth').and.returnValue(true);
|
||||||
appConfigService.config.oauth2.silentLogin = undefined;
|
appConfigService.config.oauth2.silentLogin = undefined;
|
||||||
|
|
||||||
|
@@ -71,7 +71,7 @@ describe('AuthGuardService ECM', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('if the alfresco js api is logged in should canActivate be true', async () => {
|
it('if the alfresco js api is logged in should canActivate be true', async () => {
|
||||||
spyOn(authService, 'isEcmLoggedIn').and.returnValue(true);
|
spyOn(authService, 'isLoggedIn').and.returnValue(true);
|
||||||
|
|
||||||
authGuard = TestBed.runInInjectionContext(() => AuthGuardEcm(route, state)) as Promise<boolean>;
|
authGuard = TestBed.runInInjectionContext(() => AuthGuardEcm(route, state)) as Promise<boolean>;
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ describe('AuthGuardService ECM', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('if the alfresco js api is configured with withCredentials true should canActivate be true', async () => {
|
it('if the alfresco js api is configured with withCredentials true should canActivate be true', async () => {
|
||||||
spyOn(authService, 'isBpmLoggedIn').and.returnValue(true);
|
spyOn(authService, 'isLoggedIn').and.returnValue(true);
|
||||||
appConfigService.config.auth.withCredentials = true;
|
appConfigService.config.auth.withCredentials = true;
|
||||||
|
|
||||||
authGuard = TestBed.runInInjectionContext(() => AuthGuardEcm(route, state)) as Promise<boolean>;
|
authGuard = TestBed.runInInjectionContext(() => AuthGuardEcm(route, state)) as Promise<boolean>;
|
||||||
@@ -88,7 +88,7 @@ describe('AuthGuardService ECM', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('if the alfresco js api is NOT logged in should canActivate be false', async () => {
|
it('if the alfresco js api is NOT logged in should canActivate be false', async () => {
|
||||||
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isLoggedIn').and.returnValue(false);
|
||||||
|
|
||||||
authGuard = TestBed.runInInjectionContext(() => AuthGuardEcm(route, state)) as Promise<boolean>;
|
authGuard = TestBed.runInInjectionContext(() => AuthGuardEcm(route, state)) as Promise<boolean>;
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ describe('AuthGuardService ECM', () => {
|
|||||||
|
|
||||||
it('if the alfresco js api is NOT logged in should trigger a redirect event', async () => {
|
it('if the alfresco js api is NOT logged in should trigger a redirect event', async () => {
|
||||||
appConfigService.config.loginRoute = 'login';
|
appConfigService.config.loginRoute = 'login';
|
||||||
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isLoggedIn').and.returnValue(false);
|
||||||
|
|
||||||
authGuard = TestBed.runInInjectionContext(() => AuthGuardEcm(route, state)) as Promise<boolean>;
|
authGuard = TestBed.runInInjectionContext(() => AuthGuardEcm(route, state)) as Promise<boolean>;
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ describe('AuthGuardService ECM', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async () => {
|
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async () => {
|
||||||
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isLoggedIn').and.returnValue(false);
|
||||||
spyOn(authService, 'isOauth').and.returnValue(true);
|
spyOn(authService, 'isOauth').and.returnValue(true);
|
||||||
appConfigService.config.oauth2.silentLogin = false;
|
appConfigService.config.oauth2.silentLogin = false;
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ describe('AuthGuardService ECM', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should redirect url if the alfresco js api is NOT logged in and isOAuth with silentLogin', async () => {
|
it('should redirect url if the alfresco js api is NOT logged in and isOAuth with silentLogin', async () => {
|
||||||
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isLoggedIn').and.returnValue(false);
|
||||||
spyOn(authService, 'isOauth').and.returnValue(true);
|
spyOn(authService, 'isOauth').and.returnValue(true);
|
||||||
spyOn(oidcAuthenticationService, 'isPublicUrl').and.returnValue(false);
|
spyOn(oidcAuthenticationService, 'isPublicUrl').and.returnValue(false);
|
||||||
spyOn(oidcAuthenticationService, 'ssoLogin').and.stub();
|
spyOn(oidcAuthenticationService, 'ssoLogin').and.stub();
|
||||||
@@ -139,7 +139,7 @@ describe('AuthGuardService ECM', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not redirect url if NOT logged in and isOAuth but no silentLogin configured', async () => {
|
it('should not redirect url if NOT logged in and isOAuth but no silentLogin configured', async () => {
|
||||||
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isLoggedIn').and.returnValue(false);
|
||||||
spyOn(authService, 'isOauth').and.returnValue(true);
|
spyOn(authService, 'isOauth').and.returnValue(true);
|
||||||
appConfigService.config.oauth2.silentLogin = undefined;
|
appConfigService.config.oauth2.silentLogin = undefined;
|
||||||
|
|
||||||
|
@@ -28,7 +28,7 @@ export const AuthGuardEcm: CanActivateFn = async (_: ActivatedRouteSnapshot, sta
|
|||||||
return authGuardBaseService.redirectSSOSuccessURL();
|
return authGuardBaseService.redirectSSOSuccessURL();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (authenticationService.isEcmLoggedIn() || authGuardBaseService.withCredentials) {
|
if (authenticationService.isLoggedIn() || authGuardBaseService.withCredentials) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -89,7 +89,7 @@ describe('AuthGuardService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('if the alfresco js api is configured with withCredentials true should canActivate be true', async () => {
|
it('if the alfresco js api is configured with withCredentials true should canActivate be true', async () => {
|
||||||
spyOn(authService, 'isBpmLoggedIn').and.returnValue(true);
|
spyOn(authService, 'isLoggedIn').and.returnValue(true);
|
||||||
appConfigService.config.auth.withCredentials = true;
|
appConfigService.config.auth.withCredentials = true;
|
||||||
|
|
||||||
authGuard = TestBed.runInInjectionContext(() => AuthGuard(route, state)) as Promise<boolean>;
|
authGuard = TestBed.runInInjectionContext(() => AuthGuard(route, state)) as Promise<boolean>;
|
||||||
|
@@ -42,14 +42,4 @@ export interface AuthenticationServiceInterface {
|
|||||||
getAuthHeaders(requestUrl: string, header: HttpHeaders): HttpHeaders;
|
getAuthHeaders(requestUrl: string, header: HttpHeaders): HttpHeaders;
|
||||||
addTokenToHeader(requestUrl: string, headersArg?: HttpHeaders): Observable<HttpHeaders>;
|
addTokenToHeader(requestUrl: string, headersArg?: HttpHeaders): Observable<HttpHeaders>;
|
||||||
reset(): void;
|
reset(): void;
|
||||||
|
|
||||||
/** @deprecated use `isLoggedIn` instead, use `isECMProvider` if you need to know the auth type */
|
|
||||||
isEcmLoggedIn(): boolean;
|
|
||||||
/** @deprecated use `isLoggedIn` instead, use `isBPMProvider` if you need to know the auth type */
|
|
||||||
isBpmLoggedIn(): boolean;
|
|
||||||
|
|
||||||
/** @deprecated use `getUsername` instead */
|
|
||||||
getEcmUsername(): string;
|
|
||||||
/** @deprecated use `getUsername` instead */
|
|
||||||
getBpmUsername(): string;
|
|
||||||
}
|
}
|
||||||
|
@@ -66,7 +66,6 @@ const mockAuthService = {
|
|||||||
describe('OidcAuthenticationService', () => {
|
describe('OidcAuthenticationService', () => {
|
||||||
let service: OidcAuthenticationService;
|
let service: OidcAuthenticationService;
|
||||||
let oauthService: OAuthService;
|
let oauthService: OAuthService;
|
||||||
let appConfig: AppConfigService;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
@@ -81,7 +80,6 @@ describe('OidcAuthenticationService', () => {
|
|||||||
});
|
});
|
||||||
service = TestBed.inject(OidcAuthenticationService);
|
service = TestBed.inject(OidcAuthenticationService);
|
||||||
oauthService = TestBed.inject(OAuthService);
|
oauthService = TestBed.inject(OAuthService);
|
||||||
appConfig = TestBed.inject(AppConfigService);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be created', () => {
|
it('should be created', () => {
|
||||||
@@ -189,60 +187,6 @@ describe('OidcAuthenticationService', () => {
|
|||||||
expect(service.isLoggedIn()).toBeFalse();
|
expect(service.isLoggedIn()).toBeFalse();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('isEcmLoggedIn', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
mockOAuthService.hasValidAccessToken.and.returnValue(true);
|
|
||||||
mockOAuthService.hasValidIdToken.and.returnValue(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true if is ECM provider', () => {
|
|
||||||
spyOn(appConfig, 'get').and.returnValue('ECM');
|
|
||||||
expect(service.isEcmLoggedIn()).toBeTrue();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true if is all provider', () => {
|
|
||||||
spyOn(appConfig, 'get').and.returnValue('ALL');
|
|
||||||
expect(service.isEcmLoggedIn()).toBeTrue();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false if is not ECM provider', () => {
|
|
||||||
spyOn(appConfig, 'get').and.returnValue('BPM');
|
|
||||||
expect(service.isEcmLoggedIn()).toBeFalse();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false if provider is not defined', () => {
|
|
||||||
spyOn(appConfig, 'get').and.returnValue(undefined);
|
|
||||||
expect(service.isEcmLoggedIn()).toBeFalse();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('isBpmLoggedIn', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
mockOAuthService.hasValidAccessToken.and.returnValue(true);
|
|
||||||
mockOAuthService.hasValidIdToken.and.returnValue(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true if is BPM provider', () => {
|
|
||||||
spyOn(appConfig, 'get').and.returnValue('BPM');
|
|
||||||
expect(service.isBpmLoggedIn()).toBeTrue();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true if is all provider', () => {
|
|
||||||
spyOn(appConfig, 'get').and.returnValue('ALL');
|
|
||||||
expect(service.isBpmLoggedIn()).toBeTrue();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false if is not BPM provider', () => {
|
|
||||||
spyOn(appConfig, 'get').and.returnValue('ECM');
|
|
||||||
expect(service.isBpmLoggedIn()).toBeFalse();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false if provider is not defined', () => {
|
|
||||||
spyOn(appConfig, 'get').and.returnValue(undefined);
|
|
||||||
expect(service.isBpmLoggedIn()).toBeFalse();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('OidcAuthenticationService shouldPerformSsoLogin', () => {
|
describe('OidcAuthenticationService shouldPerformSsoLogin', () => {
|
||||||
|
@@ -56,28 +56,6 @@ export class OidcAuthenticationService extends BaseAuthenticationService {
|
|||||||
map(([authenticated, isDiscoveryDocumentLoaded]) => !authenticated && isDiscoveryDocumentLoaded)
|
map(([authenticated, isDiscoveryDocumentLoaded]) => !authenticated && isDiscoveryDocumentLoaded)
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated use `isLoggedIn` instead
|
|
||||||
* @returns true if the ECM provider is logged in
|
|
||||||
*/
|
|
||||||
isEcmLoggedIn(): boolean {
|
|
||||||
if (this.isECMProvider() || this.isALLProvider()) {
|
|
||||||
return this.isLoggedIn();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated use `isLoggedIn` instead
|
|
||||||
* @returns true if the BPM provider is logged in
|
|
||||||
*/
|
|
||||||
isBpmLoggedIn(): boolean {
|
|
||||||
if (this.isBPMProvider() || this.isALLProvider()) {
|
|
||||||
return this.isLoggedIn();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
isLoggedIn(): boolean {
|
isLoggedIn(): boolean {
|
||||||
return this.oauthService.hasValidAccessToken() && this.oauthService.hasValidIdToken();
|
return this.oauthService.hasValidAccessToken() && this.oauthService.hasValidIdToken();
|
||||||
}
|
}
|
||||||
@@ -132,22 +110,6 @@ export class OidcAuthenticationService extends BaseAuthenticationService {
|
|||||||
return this.jwtHelperService.getValueFromLocalToken<string>(JwtHelperService.USER_PREFERRED_USERNAME);
|
return this.jwtHelperService.getValueFromLocalToken<string>(JwtHelperService.USER_PREFERRED_USERNAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated use `getUsername` instead
|
|
||||||
* @returns the logged username
|
|
||||||
*/
|
|
||||||
getEcmUsername(): string {
|
|
||||||
return this.getUsername();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated use `getUsername` instead
|
|
||||||
* @returns the logged username
|
|
||||||
*/
|
|
||||||
getBpmUsername(): string {
|
|
||||||
return this.getUsername();
|
|
||||||
}
|
|
||||||
|
|
||||||
ssoLogin(redirectUrl?: string) {
|
ssoLogin(redirectUrl?: string) {
|
||||||
this.auth.login(redirectUrl);
|
this.auth.login(redirectUrl);
|
||||||
}
|
}
|
||||||
|
@@ -140,7 +140,7 @@ describe('AuthenticationService', () => {
|
|||||||
spyOn(authService, 'isECMProvider').and.returnValue(true);
|
spyOn(authService, 'isECMProvider').and.returnValue(true);
|
||||||
spyOn(authService, 'isOauth').and.returnValue(false);
|
spyOn(authService, 'isOauth').and.returnValue(false);
|
||||||
|
|
||||||
expect(authService.isEcmLoggedIn()).toBeFalsy();
|
expect(authService.isLoggedIn()).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should require remember me set for ECM check', () => {
|
it('should require remember me set for ECM check', () => {
|
||||||
@@ -149,7 +149,7 @@ describe('AuthenticationService', () => {
|
|||||||
spyOn(authService, 'isECMProvider').and.returnValue(true);
|
spyOn(authService, 'isECMProvider').and.returnValue(true);
|
||||||
spyOn(authService, 'isOauth').and.returnValue(false);
|
spyOn(authService, 'isOauth').and.returnValue(false);
|
||||||
|
|
||||||
expect(authService.isEcmLoggedIn()).toBeFalsy();
|
expect(authService.isLoggedIn()).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('[ECM] should login in the ECM if no provider are defined calling the login', async () => {
|
it('[ECM] should login in the ECM if no provider are defined calling the login', async () => {
|
||||||
@@ -167,7 +167,6 @@ describe('AuthenticationService', () => {
|
|||||||
|
|
||||||
it('[ECM] should return false if the user is not logged in', () => {
|
it('[ECM] should return false if the user is not logged in', () => {
|
||||||
expect(authService.isLoggedIn()).toBe(false);
|
expect(authService.isLoggedIn()).toBe(false);
|
||||||
expect(authService.isEcmLoggedIn()).toBe(false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('[ECM] should set/get redirectUrl when provider is ECM', () => {
|
it('[ECM] should set/get redirectUrl when provider is ECM', () => {
|
||||||
@@ -199,10 +198,6 @@ describe('AuthenticationService', () => {
|
|||||||
it('[ECM] should return isALLProvider false', () => {
|
it('[ECM] should return isALLProvider false', () => {
|
||||||
expect(authService.isALLProvider()).toBe(false);
|
expect(authService.isALLProvider()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('[ECM] should return isBpmLoggedIn false', () => {
|
|
||||||
expect(authService.isBpmLoggedIn()).toBe(false);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when the setting is BPM', () => {
|
describe('when the setting is BPM', () => {
|
||||||
@@ -217,7 +212,7 @@ describe('AuthenticationService', () => {
|
|||||||
spyOn(authService, 'isBPMProvider').and.returnValue(true);
|
spyOn(authService, 'isBPMProvider').and.returnValue(true);
|
||||||
spyOn(authService, 'isOauth').and.returnValue(false);
|
spyOn(authService, 'isOauth').and.returnValue(false);
|
||||||
|
|
||||||
expect(authService.isBpmLoggedIn()).toBeFalsy();
|
expect(authService.isLoggedIn()).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not require cookie service enabled for BPM check', () => {
|
it('should not require cookie service enabled for BPM check', () => {
|
||||||
@@ -225,7 +220,7 @@ describe('AuthenticationService', () => {
|
|||||||
spyOn(basicAlfrescoAuthService, 'isRememberMeSet').and.returnValue(false);
|
spyOn(basicAlfrescoAuthService, 'isRememberMeSet').and.returnValue(false);
|
||||||
spyOn(authService, 'isBPMProvider').and.returnValue(true);
|
spyOn(authService, 'isBPMProvider').and.returnValue(true);
|
||||||
|
|
||||||
expect(authService.isBpmLoggedIn()).toBeFalsy();
|
expect(authService.isLoggedIn()).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('[BPM] should return an error when the logout return error', async () => {
|
it('[BPM] should return an error when the logout return error', async () => {
|
||||||
|
@@ -32,7 +32,10 @@ export class AuthenticationService implements AuthenticationServiceInterface, ee
|
|||||||
onLogout: Subject<any> = new Subject<any>();
|
onLogout: Subject<any> = new Subject<any>();
|
||||||
onTokenReceived: Subject<any> = new Subject<any>();
|
onTokenReceived: Subject<any> = new Subject<any>();
|
||||||
|
|
||||||
constructor(private injector: Injector, private redirectAuthService: RedirectAuthService) {
|
constructor(
|
||||||
|
private readonly injector: Injector,
|
||||||
|
private readonly redirectAuthService: RedirectAuthService
|
||||||
|
) {
|
||||||
this.redirectAuthService.onLogin.subscribe((value) => this.onLogin.next(value));
|
this.redirectAuthService.onLogin.subscribe((value) => this.onLogin.next(value));
|
||||||
|
|
||||||
this.redirectAuthService.onTokenReceived.subscribe((value) => this.onTokenReceived.next(value));
|
this.redirectAuthService.onTokenReceived.subscribe((value) => this.onTokenReceived.next(value));
|
||||||
@@ -116,30 +119,6 @@ export class AuthenticationService implements AuthenticationServiceInterface, ee
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated use `isLoggedIn` instead
|
|
||||||
* @returns true if the ECM provider is logged in
|
|
||||||
*/
|
|
||||||
isEcmLoggedIn(): boolean {
|
|
||||||
if (this.isOauth()) {
|
|
||||||
return this.oidcAuthenticationService.isLoggedIn();
|
|
||||||
} else {
|
|
||||||
return this.basicAlfrescoAuthService.isEcmLoggedIn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated use `isLoggedIn` instead
|
|
||||||
* @returns true if the BPM provider is logged in
|
|
||||||
*/
|
|
||||||
isBpmLoggedIn(): boolean {
|
|
||||||
if (this.isOauth()) {
|
|
||||||
return this.oidcAuthenticationService.isLoggedIn();
|
|
||||||
} else {
|
|
||||||
return this.basicAlfrescoAuthService.isBpmLoggedIn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
reset(): void {
|
reset(): void {
|
||||||
if (this.isOauth()) {
|
if (this.isOauth()) {
|
||||||
return this.oidcAuthenticationService.reset();
|
return this.oidcAuthenticationService.reset();
|
||||||
@@ -169,22 +148,6 @@ export class AuthenticationService implements AuthenticationServiceInterface, ee
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated use `getUsername` instead
|
|
||||||
* @returns the logged username
|
|
||||||
*/
|
|
||||||
getEcmUsername(): string {
|
|
||||||
return this.getUsername();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated use `getUsername` instead
|
|
||||||
* @returns the logged username
|
|
||||||
*/
|
|
||||||
getBpmUsername(): string {
|
|
||||||
return this.getUsername();
|
|
||||||
}
|
|
||||||
|
|
||||||
getAuthHeaders(requestUrl: string, headers: HttpHeaders): HttpHeaders {
|
getAuthHeaders(requestUrl: string, headers: HttpHeaders): HttpHeaders {
|
||||||
if (this.isOauth()) {
|
if (this.isOauth()) {
|
||||||
return this.oidcAuthenticationService.getAuthHeaders(requestUrl, headers);
|
return this.oidcAuthenticationService.getAuthHeaders(requestUrl, headers);
|
||||||
|
@@ -35,7 +35,10 @@ export abstract class BaseAuthenticationService implements AuthenticationService
|
|||||||
onLogin = new ReplaySubject<any>(1);
|
onLogin = new ReplaySubject<any>(1);
|
||||||
onLogout = new ReplaySubject<any>(1);
|
onLogout = new ReplaySubject<any>(1);
|
||||||
|
|
||||||
protected constructor(protected appConfig: AppConfigService, protected cookie: CookieService) {
|
protected constructor(
|
||||||
|
protected appConfig: AppConfigService,
|
||||||
|
protected cookie: CookieService
|
||||||
|
) {
|
||||||
ee(this);
|
ee(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,22 +46,9 @@ export abstract class BaseAuthenticationService implements AuthenticationService
|
|||||||
abstract getToken(): string;
|
abstract getToken(): string;
|
||||||
abstract isLoggedIn(): boolean;
|
abstract isLoggedIn(): boolean;
|
||||||
abstract logout(): any;
|
abstract logout(): any;
|
||||||
|
|
||||||
/** @deprecated use `isLoggedIn` instead */
|
|
||||||
abstract isEcmLoggedIn(): boolean;
|
|
||||||
|
|
||||||
/** @deprecated use `isLoggedIn` instead */
|
|
||||||
abstract isBpmLoggedIn(): boolean;
|
|
||||||
|
|
||||||
abstract reset(): void;
|
abstract reset(): void;
|
||||||
abstract getUsername(): string;
|
abstract getUsername(): string;
|
||||||
|
|
||||||
/** @deprecated use `getUsername` instead */
|
|
||||||
abstract getEcmUsername(): string;
|
|
||||||
|
|
||||||
/** @deprecated use `getUsername` instead */
|
|
||||||
abstract getBpmUsername(): string;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the auth token to an HTTP header using the 'bearer' scheme.
|
* Adds the auth token to an HTTP header using the 'bearer' scheme.
|
||||||
*
|
*
|
||||||
|
@@ -36,7 +36,7 @@ describe('AppListCloudComponent', () => {
|
|||||||
oauth2Auth: {
|
oauth2Auth: {
|
||||||
callCustomApi: () => Promise.resolve(fakeApplicationInstance)
|
callCustomApi: () => Promise.resolve(fakeApplicationInstance)
|
||||||
},
|
},
|
||||||
isEcmLoggedIn: () => false,
|
isLoggedIn: () => false,
|
||||||
reply: jasmine.createSpy('reply')
|
reply: jasmine.createSpy('reply')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -69,7 +69,7 @@ const mockOauth2Auth: any = {
|
|||||||
oauth2Auth: {
|
oauth2Auth: {
|
||||||
callCustomApi: () => Promise.resolve()
|
callCustomApi: () => Promise.resolve()
|
||||||
},
|
},
|
||||||
isEcmLoggedIn: jasmine.createSpy('isEcmLoggedIn'),
|
isLoggedIn: jasmine.createSpy('isLoggedIn'),
|
||||||
reply: jasmine.createSpy('reply')
|
reply: jasmine.createSpy('reply')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -83,7 +83,7 @@ describe('EditProcessFilterCloudComponent', () => {
|
|||||||
oauth2Auth: {
|
oauth2Auth: {
|
||||||
callCustomApi: () => Promise.resolve(fakeApplicationInstance)
|
callCustomApi: () => Promise.resolve(fakeApplicationInstance)
|
||||||
},
|
},
|
||||||
isEcmLoggedIn: () => false,
|
isLoggedIn: () => false,
|
||||||
reply: jasmine.createSpy('reply')
|
reply: jasmine.createSpy('reply')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -23,7 +23,7 @@ export const mockAlfrescoApi: any = {
|
|||||||
oauth2Auth: {
|
oauth2Auth: {
|
||||||
callCustomApi: () => Promise.resolve(fakeApplicationInstance)
|
callCustomApi: () => Promise.resolve(fakeApplicationInstance)
|
||||||
},
|
},
|
||||||
isEcmLoggedIn: () => false,
|
isLoggedIn: () => false,
|
||||||
reply: jasmine.createSpy('reply')
|
reply: jasmine.createSpy('reply')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -53,7 +53,7 @@ describe('TaskHeaderCloudComponent', () => {
|
|||||||
oauth2Auth: {
|
oauth2Auth: {
|
||||||
callCustomApi: () => Promise.resolve({})
|
callCustomApi: () => Promise.resolve({})
|
||||||
},
|
},
|
||||||
isEcmLoggedIn: () => false,
|
isLoggedIn: () => false,
|
||||||
reply: jasmine.createSpy('reply')
|
reply: jasmine.createSpy('reply')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user