[AAE-12501] Align JS API (#8344)

* [AAE-12501] Provide an AlfrescoApiService implementation that disable the AlfrescoApi oauth initialization when we use new oidc implementation

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

* [AAE-12501] Replace sitesService with authentication service since sitesService get the username from oauth2Auth

* [AAE-12501] Call implicitLogin by authentication service

* [AAE-12501] Replace Oauth2Auth with AlfrescoApi and call the custom api without using authentication

* [AAE-12501] Replace oauth2Auth with authentication service to get the token

* [AAE-12501] Replace oauth2Auth with alfrescoApi

* remove unneeded JS-API dep
move auth in the right place

* [AAE-10501] Rename alfresco-api.http-client to adf-http-client

* [AAE-10501] Remove config from a CoreModule, a different service is provided in AuthModule to use angular http client instead of super agent

* [AAE-10501] Disable AlfrescoApi oauth initialization while using new adf oidc authentication

* [AAE-12501] Replace alfresco api client with AdfHttpClient

* [AAE-12501] Restore get username methods

* [AAE-12501] Get username with authentication service

* [AAE-12501] removee unused method

* [AAE-12501] Trigger on login when token is received

* [AAE-12501] Fix content-services unit test

* [AAE-12501] Fix import

* [AAE-12501] Fix core unit tests

* [AAE-12501] Fix process-services-cloud unit tests

* [AAE-12501] Create a request options interface with the needed props, remove the import from js-api, return the body from request

* [AAE-12501] Fix process-services-cloud unit tests without Expectation

* [AAE-12501] Fix Core secondary entrypoints unit tests are not executed: move test.ts one level up in order to find all the spec files into the secondary entrypoints folders and update path

* [AAE-12501] Fix Core unit tests that weren't executed because of the previous test.ts wrong location

* [AAE-12501] Fix authentication token_issued subscription

* add emitters

* [AAE-12501] Replace Math.random() to fix hospot security issue, fix lint issues

* [AAE-12501] Install event-emitter dependency

* [AAE-12501] Comment temporary setCsrfToken because is not possible to import app config service from core due to circular dependencies

* [AAE-12501] Get disableCsrf from app config serviice when app configuration is loaded

* [AAE-12501] Fix license-header lint issue

* [AAE-14221] Regenerate lock file

* [AAE-14221] Fix sonarcloud issues

* [AAE-12501] Remove wrong character

* [AAE-12501] Regenerate lock file

* [AAE-12501] Fix BC: update alfresco api response error

---------

Co-authored-by: eromano <eugenioromano16@gmail.com>
This commit is contained in:
Amedeo Lepore
2023-06-27 17:22:30 +02:00
committed by GitHub
parent 037dce0ae7
commit 7abebf0652
53 changed files with 5474 additions and 10457 deletions

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { AlfrescoApiHttpClient } from '@alfresco/adf-core/api';
import { AdfHttpClient } from '@alfresco/adf-core/api';
import { StorageService } from '../common/services/storage.service';
import { AlfrescoApi, AlfrescoApiConfig } from '@alfresco/js-api';
import { Injectable } from '@angular/core';
@@ -23,16 +23,19 @@ import { AppConfigService } from '../app-config';
import { AlfrescoApiService } from '../services/alfresco-api.service';
@Injectable()
export class AlfrescoApiServiceWithAngularBasedHttpClient extends AlfrescoApiService {
export class AlfrescoApiNoAuthService extends AlfrescoApiService {
constructor(
storage: StorageService,
appConfig: AppConfigService,
private readonly alfrescoApiHttpClient: AlfrescoApiHttpClient
private readonly adfHttpClient: AdfHttpClient
) {
super(appConfig, storage);
}
override createInstance(config: AlfrescoApiConfig) {
return new AlfrescoApi(config, this.alfrescoApiHttpClient);
return new AlfrescoApi({
...config,
oauthInit: false
}, this.adfHttpClient);
}
}

View File

@@ -17,9 +17,11 @@
import { AppConfigService, AppConfigValues } from './app-config.service';
import { StorageService } from '../common/services/storage.service';
import { AdfHttpClient } from '@alfresco/adf-core/api';
export function loadAppConfig(appConfigService: AppConfigService, storageService: StorageService) {
export function loadAppConfig(appConfigService: AppConfigService, storageService: StorageService, adfHttpClient: AdfHttpClient) {
return () => appConfigService.load().then(() => {
adfHttpClient.disableCsrf = appConfigService.get<boolean>(AppConfigValues.DISABLECSRF);
storageService.prefix = appConfigService.get<string>(AppConfigValues.STORAGE_PREFIX, '');
});
}

View File

@@ -17,7 +17,7 @@
import { APP_INITIALIZER, ModuleWithProviders, NgModule } from '@angular/core';
import { AuthConfig, AUTH_CONFIG, OAuthModule, OAuthService, OAuthStorage } from 'angular-oauth2-oidc';
import { AlfrescoApiServiceWithAngularBasedHttpClient } from '../../api-factories/alfresco-api-service-with-angular-based-http-client';
import { AlfrescoApiNoAuthService } from '../../api-factories/alfresco-api-no-auth.service';
import { AlfrescoApiService } from '../../services/alfresco-api.service';
import { AuthGuardBpm } from '../guard/auth-guard-bpm.service';
import { AuthGuardEcm } from '../guard/auth-guard-ecm.service';
@@ -47,7 +47,7 @@ export function loginFactory(oAuthService: OAuthService, storage: OAuthStorage,
{ provide: AuthGuardEcm, useClass: OidcAuthGuard },
{ provide: AuthGuardBpm, useClass: OidcAuthGuard },
{ provide: AuthenticationService, useClass: OIDCAuthenticationService },
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceWithAngularBasedHttpClient },
{ provide: AlfrescoApiService, useClass: AlfrescoApiNoAuthService },
{
provide: AUTH_CONFIG,
useFactory: authConfigFactory,

View File

@@ -16,11 +16,11 @@
*/
import { Injectable, inject } 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 { AppConfigValues } from '../../app-config/app-config.service';
import { BaseAuthenticationService } from '../../services/base-authentication.service';
import { BaseAuthenticationService } from '../services/base-authentication.service';
import { JwtHelperService } from '../services/jwt-helper.service';
import { AuthConfigService } from '../oidc/auth-config.service';
import { AuthService } from './auth.service';
@@ -39,7 +39,9 @@ export class OIDCAuthenticationService extends BaseAuthenticationService {
constructor() {
super();
this.alfrescoApi.alfrescoApiInitialized.subscribe(() => {
this.alfrescoApi.getInstance().reply('logged-in', () => {
this.oauthService.events.pipe(
filter((event)=> event.type === 'token_received')
).subscribe(()=>{
this.onLogin.next();
});
});
@@ -87,6 +89,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();
}
@@ -117,4 +127,8 @@ export class OIDCAuthenticationService extends BaseAuthenticationService {
this.auth.login();
}
}
once(event: string): Observable<OAuthEvent> {
return this.oauthService.events.pipe(filter(_event => _event.type === event));
}
}

View File

@@ -21,7 +21,7 @@ import { AppConfigValues } from '../../app-config/app-config.service';
import { map, catchError, tap } from 'rxjs/operators';
import { JwtHelperService } from './jwt-helper.service';
import { StorageService } from '../../common/services/storage.service';
import { BaseAuthenticationService } from '../../services/base-authentication.service';
import { BaseAuthenticationService } from './base-authentication.service';
@Injectable({
providedIn: 'root'
@@ -152,6 +152,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 {
return !!this.appConfig.oauth2?.implicitFlow;
}
@@ -169,5 +187,12 @@ export class AuthenticationService extends BaseAuthenticationService {
return this.storageService.getItem(JwtHelperService.USER_ACCESS_TOKEN);
}
reset() {}
reset() { }
once(event: string): Observable<any> {
const alfrescoApiEvent = event === 'token_received' ? 'token_issued' : event;
return new Observable((subscriber) => {
this.alfrescoApi.getInstance().oauth2Auth.once(alfrescoApiEvent, () => subscriber.next());
});
}
}

View File

@@ -15,14 +15,14 @@
* limitations under the License.
*/
import { PeopleApi, UserProfileApi, UserRepresentation } from '@alfresco/js-api';
import { PeopleApi, UserProfileApi } from '@alfresco/js-api';
import { HttpHeaders } from '@angular/common/http';
import { RedirectionModel } from '../auth/models/redirection.model';
import { from, Observable, Observer, ReplaySubject, throwError } from 'rxjs';
import { AppConfigService, AppConfigValues } from '../app-config/app-config.service';
import { AlfrescoApiService } from './alfresco-api.service';
import { CookieService } from '../common/services/cookie.service';
import { LogService } from '../common/services/log.service';
import { RedirectionModel } from '../models/redirection.model';
import { Observable, Observer, ReplaySubject, throwError } from 'rxjs';
import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service';
import { AlfrescoApiService } from '../../services/alfresco-api.service';
import { CookieService } from '../../common/services/cookie.service';
import { LogService } from '../../common/services/log.service';
import { inject } from '@angular/core';
const REMEMBER_ME_COOKIE_KEY = 'ALFRESCO_REMEMBER_ME';
@@ -57,14 +57,15 @@ export abstract class BaseAuthenticationService {
abstract isLoggedIn(): boolean;
abstract isLoggedInWith(provider: string): boolean;
abstract isOauth(): boolean;
abstract isImplicitFlow(): boolean;
abstract isAuthCodeFlow(): boolean;
abstract login(username: string, password: string, rememberMe?: boolean): Observable<{ type: string; ticket: any }>;
abstract ssoImplicitLogin(): void;
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;
@@ -126,24 +127,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();
}
@@ -206,15 +189,6 @@ export abstract class BaseAuthenticationService {
return null;
}
/**
* Gets information about the user currently logged into APS.
*
* @returns User information
*/
getBpmLoggedUser(): Observable<UserRepresentation> {
return from(this.profileApi.getProfile());
}
/**
* Prints an error message in the console browser
*

View File

@@ -17,7 +17,6 @@
import { fakeAsync, TestBed } from '@angular/core/testing';
import { setupTestBed } from '../../testing/setup-test-bed';
import { AlfrescoApiService } from './../../services/alfresco-api.service';
import { IdentityGroupService } from './identity-group.service';
import { HttpErrorResponse } from '@angular/common/http';
import { throwError, of } from 'rxjs';
@@ -25,23 +24,18 @@ import {
mockIdentityRoles,
clientRoles,
mockIdentityGroup1,
mockIdentityGroupsCount
mockIdentityGroupsCount,
mockIdentityGroups,
roleMappingMock
} from '../mock/identity-group.mock';
import { CoreTestingModule } from '../../testing/core.testing.module';
import { TranslateModule } from '@ngx-translate/core';
import {
applicationDetailsMockApi,
createGroupMappingApi,
deleteGroupMappingApi,
groupsMockApi,
noRoleMappingApi,
roleMappingApi,
updateGroupMappingApi
} from '../mock/oauth2.service.mock';
import { AdfHttpClient } from '../../../../api/src';
describe('IdentityGroupService', () => {
let service: IdentityGroupService;
let apiService: AlfrescoApiService;
let adfHttpClient: AdfHttpClient;
let requestSpy: jasmine.Spy;
setupTestBed({
imports: [
@@ -52,11 +46,12 @@ describe('IdentityGroupService', () => {
beforeEach(fakeAsync(() => {
service = TestBed.inject(IdentityGroupService);
apiService = TestBed.inject(AlfrescoApiService);
adfHttpClient = TestBed.inject(AdfHttpClient);
requestSpy = spyOn(adfHttpClient, 'request');
}));
it('should be able to fetch groups based on group name', (done) => {
spyOn(apiService, 'getInstance').and.returnValue(groupsMockApi);
requestSpy.and.returnValue(Promise.resolve(mockIdentityGroups));
service.findGroupsByName({name: 'mock'}).subscribe((res) => {
expect(res).toBeDefined();
expect(res).not.toBeNull();
@@ -72,7 +67,7 @@ describe('IdentityGroupService', () => {
});
it('should return true if group has client role mapping', (done) => {
spyOn(apiService, 'getInstance').and.returnValue(roleMappingApi);
requestSpy.and.returnValue(Promise.resolve(roleMappingMock));
service.checkGroupHasClientApp('mock-group-id', 'mock-app-id').subscribe((hasRole) => {
expect(hasRole).toBeDefined();
expect(hasRole).toBe(true);
@@ -81,7 +76,7 @@ describe('IdentityGroupService', () => {
});
it('should return false if group does not have client role mapping', (done) => {
spyOn(apiService, 'getInstance').and.returnValue(noRoleMappingApi);
requestSpy.and.returnValue(Promise.resolve([]));
service.checkGroupHasClientApp('mock-group-id', 'mock-app-id').subscribe((hasRole) => {
expect(hasRole).toBeDefined();
expect(hasRole).toBe(false);
@@ -226,7 +221,7 @@ describe('IdentityGroupService', () => {
});
it('should be able to fetch the client id', (done) => {
spyOn(apiService, 'getInstance').and.returnValue(applicationDetailsMockApi);
requestSpy.and.returnValue(Promise.resolve([{id: 'mock-app-id', name: 'mock-app-name'}]));
service.getClientIdByApplicationName('mock-app-name').subscribe((clientId) => {
expect(clientId).toBeDefined();
expect(clientId).not.toBeNull();
@@ -236,7 +231,7 @@ describe('IdentityGroupService', () => {
});
it('should be able to all fetch groups', (done) => {
spyOn(apiService, 'getInstance').and.returnValue(groupsMockApi);
requestSpy.and.returnValue(Promise.resolve(mockIdentityGroups));
service.getGroups().subscribe((res) => {
expect(res.length).toBe(5);
expect(res[0].id).toBe('mock-group-id-1');
@@ -273,7 +268,7 @@ describe('IdentityGroupService', () => {
it('should be able to query groups based on first & max params', (done) => {
spyOn(service, 'getTotalGroupsCount').and.returnValue(of(mockIdentityGroupsCount));
spyOn(apiService, 'getInstance').and.returnValue(groupsMockApi);
requestSpy.and.returnValue(Promise.resolve(mockIdentityGroups));
service.queryGroups({first: 0, max: 5}).subscribe((res) => {
expect(res).toBeDefined();
expect(res).not.toBeNull();
@@ -314,7 +309,7 @@ describe('IdentityGroupService', () => {
});
it('should be able to create group', (done) => {
const createCustomApiSpy = spyOn(apiService, 'getInstance').and.returnValue(createGroupMappingApi);
const createCustomApiSpy = requestSpy.and.returnValue(Promise.resolve());
service.createGroup(mockIdentityGroup1).subscribe(() => {
expect(createCustomApiSpy).toHaveBeenCalled();
done();
@@ -344,7 +339,7 @@ describe('IdentityGroupService', () => {
});
it('should be able to update group', (done) => {
const updateCustomApiSpy = spyOn(apiService, 'getInstance').and.returnValue(updateGroupMappingApi);
const updateCustomApiSpy = requestSpy.and.returnValue(Promise.resolve());
service.updateGroup('mock-group-id', mockIdentityGroup1).subscribe(() => {
expect(updateCustomApiSpy).toHaveBeenCalled();
done();
@@ -374,7 +369,7 @@ describe('IdentityGroupService', () => {
});
it('should be able to delete group', (done) => {
const deleteCustomApiSpy = spyOn(apiService, 'getInstance').and.returnValue(deleteGroupMappingApi);
const deleteCustomApiSpy = requestSpy.and.returnValue(Promise.resolve());
service.deleteGroup('mock-group-id').subscribe(() => {
expect(deleteCustomApiSpy).toHaveBeenCalled();
done();

View File

@@ -22,31 +22,20 @@ import {
mockIdentityUser1,
mockIdentityUser2,
mockIdentityRole,
mockIdentityUsers
mockIdentityUsers,
mockAssignedRoles,
mockAvailableRoles,
mockEffectiveRoles
} from '../mock/identity-user.mock';
import { mockJoinGroupRequest } from '../mock/identity-group.mock';
import { mockGroups, mockJoinGroupRequest } from '../mock/identity-group.mock';
import { IdentityUserService } from './identity-user.service';
import { JwtHelperService } from './jwt-helper.service';
import { setupTestBed } from '../../testing/setup-test-bed';
import { AlfrescoApiService } from '../../services/alfresco-api.service';
import { mockToken } from '../mock/jwt-helper.service.spec';
import { IdentityRoleModel } from '../models/identity-role.model';
import { CoreTestingModule } from '../../testing/core.testing.module';
import { TranslateModule } from '@ngx-translate/core';
import {
assignRolesMockApi,
createUserMockApi,
deleteUserMockApi,
getAssignedRolesMockApi,
getAvailableRolesMockApi,
getEffectiveRolesMockApi,
getInvolvedGroupsMockApi,
joinGroupMockApi,
leaveGroupMockApi,
queryUsersMockApi,
removeRolesMockApi,
updateUserMockApi
} from '../mock/oauth2.service.mock';
import { AdfHttpClient } from '../../../../api/src';
describe('IdentityUserService', () => {
@@ -59,7 +48,8 @@ describe('IdentityUserService', () => {
];
let service: IdentityUserService;
let alfrescoApiService: AlfrescoApiService;
let adfHttpClient: AdfHttpClient;
let requestSpy: jasmine.Spy;
setupTestBed({
imports: [
@@ -70,7 +60,8 @@ describe('IdentityUserService', () => {
beforeEach(() => {
service = TestBed.inject(IdentityUserService);
alfrescoApiService = TestBed.inject(AlfrescoApiService);
adfHttpClient = TestBed.inject(AdfHttpClient);
requestSpy = spyOn(adfHttpClient, 'request');
});
beforeEach(() => {
@@ -297,7 +288,7 @@ describe('IdentityUserService', () => {
});
it('should be able to query users based on query params (first & max params)', (done) => {
spyOn(alfrescoApiService, 'getInstance').and.returnValue(queryUsersMockApi);
requestSpy.and.returnValue(Promise.resolve(mockIdentityUsers));
service.queryUsers({first: 0, max: 5}).subscribe((res) => {
expect(res).toBeDefined();
expect(res).not.toBeNull();
@@ -335,7 +326,7 @@ describe('IdentityUserService', () => {
});
it('should be able to create user', (done) => {
const createCustomApiSpy = spyOn(alfrescoApiService, 'getInstance').and.returnValue(createUserMockApi);
const createCustomApiSpy = requestSpy.and.returnValue(Promise.resolve());
service.createUser(mockIdentityUser1).subscribe(() => {
expect(createCustomApiSpy).toHaveBeenCalled();
done();
@@ -365,7 +356,7 @@ describe('IdentityUserService', () => {
});
it('should be able to update user', (done) => {
const updateCustomApiSpy = spyOn(alfrescoApiService, 'getInstance').and.returnValue(updateUserMockApi);
const updateCustomApiSpy = requestSpy.and.returnValue(Promise.resolve());
service.updateUser('mock-id-2', mockIdentityUser2).subscribe(() => {
expect(updateCustomApiSpy).toHaveBeenCalled();
done();
@@ -395,7 +386,7 @@ describe('IdentityUserService', () => {
});
it('should be able to delete group', (done) => {
const deleteCustomApiSpy = spyOn(alfrescoApiService, 'getInstance').and.returnValue(deleteUserMockApi);
const deleteCustomApiSpy = requestSpy.and.returnValue(Promise.resolve());
service.deleteUser('mock-user-id').subscribe(() => {
expect(deleteCustomApiSpy).toHaveBeenCalled();
done();
@@ -425,7 +416,7 @@ describe('IdentityUserService', () => {
});
it('should be able to fetch involved groups based on user id', (done) => {
spyOn(alfrescoApiService, 'getInstance').and.returnValue(getInvolvedGroupsMockApi);
requestSpy.and.returnValue(Promise.resolve(mockGroups));
service.getInvolvedGroups('mock-user-id').subscribe((res) => {
expect(res).toBeDefined();
expect(res).not.toBeNull();
@@ -461,7 +452,7 @@ describe('IdentityUserService', () => {
});
it('should be able to join the group', (done) => {
const joinGroupCustomApiSpy = spyOn(alfrescoApiService, 'getInstance').and.returnValue(joinGroupMockApi);
const joinGroupCustomApiSpy = requestSpy.and.returnValue(Promise.resolve());
service.joinGroup(mockJoinGroupRequest).subscribe(() => {
expect(joinGroupCustomApiSpy).toHaveBeenCalled();
done();
@@ -491,7 +482,7 @@ describe('IdentityUserService', () => {
});
it('should be able to leave the group', (done) => {
const leaveGroupCustomApiSpy = spyOn(alfrescoApiService, 'getInstance').and.returnValue(leaveGroupMockApi);
const leaveGroupCustomApiSpy = requestSpy.and.returnValue(Promise.resolve());
service.leaveGroup('mock-user-id', 'mock-group-id').subscribe(() => {
expect(leaveGroupCustomApiSpy).toHaveBeenCalled();
done();
@@ -521,7 +512,7 @@ describe('IdentityUserService', () => {
});
it('should be able to fetch available roles based on user id', (done) => {
spyOn(alfrescoApiService, 'getInstance').and.returnValue(getAvailableRolesMockApi);
requestSpy.and.returnValue(Promise.resolve(mockAvailableRoles));
service.getAvailableRoles('mock-user-id').subscribe((res) => {
expect(res).toBeDefined();
expect(res).not.toBeNull();
@@ -559,7 +550,7 @@ describe('IdentityUserService', () => {
});
it('should be able to fetch assigned roles based on user id', (done) => {
spyOn(alfrescoApiService, 'getInstance').and.returnValue(getAssignedRolesMockApi);
requestSpy.and.returnValue(Promise.resolve(mockAssignedRoles));
service.getAssignedRoles('mock-user-id').subscribe((res) => {
expect(res).toBeDefined();
expect(res).not.toBeNull();
@@ -597,7 +588,7 @@ describe('IdentityUserService', () => {
});
it('should be able to fetch effective roles based on user id', (done) => {
spyOn(alfrescoApiService, 'getInstance').and.returnValue(getEffectiveRolesMockApi);
requestSpy.and.returnValue(Promise.resolve(mockEffectiveRoles));
service.getEffectiveRoles('mock-user-id').subscribe((res) => {
expect(res).toBeDefined();
expect(res).not.toBeNull();
@@ -635,7 +626,7 @@ describe('IdentityUserService', () => {
});
it('should be able to assign roles to the user', (done) => {
const assignRolesCustomApiSpy = spyOn(alfrescoApiService, 'getInstance').and.returnValue(assignRolesMockApi);
const assignRolesCustomApiSpy = requestSpy.and.returnValue(Promise.resolve());
service.assignRoles('mock-user-id', [mockIdentityRole]).subscribe(() => {
expect(assignRolesCustomApiSpy).toHaveBeenCalled();
done();
@@ -665,7 +656,7 @@ describe('IdentityUserService', () => {
});
it('should be able to remove roles', (done) => {
const removeRolesCustomApiSpy = spyOn(alfrescoApiService, 'getInstance').and.returnValue(removeRolesMockApi);
const removeRolesCustomApiSpy = requestSpy.and.returnValue(Promise.resolve());
service.removeRoles('mock-user-id', [mockIdentityRole]).subscribe(() => {
expect(removeRolesCustomApiSpy).toHaveBeenCalled();
done();

View File

@@ -16,9 +16,8 @@
*/
import { Injectable } from '@angular/core';
import { AlfrescoApiService } from '../../services/alfresco-api.service';
import { Observable, from } from 'rxjs';
import { Oauth2Auth } from '@alfresco/js-api';
import { AdfHttpClient } from '@alfresco/adf-core/api';
export const JSON_TYPE = ['application/json'];
@@ -32,25 +31,21 @@ export interface OAuth2RequestParams {
@Injectable({ providedIn: 'root' })
export class OAuth2Service {
constructor(private alfrescoApiService: AlfrescoApiService) {}
get apiClient(): Oauth2Auth {
return this.alfrescoApiService.getInstance().oauth2Auth;
}
constructor(private adfHttpClient: AdfHttpClient) {}
request<T>(opts: OAuth2RequestParams): Observable<T> {
const { httpMethod, url, bodyParam, queryParams } = opts;
return from(
this.apiClient.callCustomApi(
opts.url,
opts.httpMethod,
opts.pathParams,
opts.queryParams,
{},
{},
opts.bodyParam,
JSON_TYPE,
JSON_TYPE,
Object
this.adfHttpClient.request(
url,
{
httpMethod,
queryParams,
headerParams: {},
formParams: {},
bodyParam,
returnType: Object
}
)
);
}

View File

@@ -45,7 +45,6 @@ import { BlankPageModule } from './blank-page/blank-page.module';
import { DirectiveModule } from './directives/directive.module';
import { PipeModule } from './pipes/pipe.module';
import { AlfrescoApiService } from './services/alfresco-api.service';
import { TranslationService } from './translation/translation.service';
import { SortingPickerModule } from './sorting-picker/sorting-picker.module';
import { IconModule } from './icon/icon.module';
@@ -54,7 +53,7 @@ import { ExtensionsModule } from '@alfresco/adf-extensions';
import { directionalityConfigFactory } from './common/services/directionality-config-factory';
import { DirectionalityConfigService } from './common/services/directionality-config.service';
import { SearchTextModule } from './search-text/search-text-input.module';
import { AlfrescoJsClientsModule } from '@alfresco/adf-core/api';
import { AdfHttpClient, AlfrescoJsClientsModule } from '@alfresco/adf-core/api';
import { AuthenticationInterceptor, Authentication } from '@alfresco/adf-core/auth';
import { LegacyApiClientModule } from './api-factories/legacy-api-client.module';
import { HttpClientModule, HttpClientXsrfModule, HTTP_INTERCEPTORS } from '@angular/common/http';
@@ -65,13 +64,6 @@ import { loadAppConfig } from './app-config/app-config.loader';
import { AppConfigService } from './app-config/app-config.service';
import { StorageService } from './common/services/storage.service';
import { AlfrescoApiLoaderService, createAlfrescoApiInstance } from './api-factories/alfresco-api-v2-loader.service';
import { AlfrescoApiServiceWithAngularBasedHttpClient } from './api-factories/alfresco-api-service-with-angular-based-http-client';
interface Config {
readonly useAngularBasedHttpClientInAlfrescoJs: boolean;
}
const defaultConfig: Config = { useAngularBasedHttpClientInAlfrescoJs: false };
@NgModule({
imports: [
@@ -149,7 +141,7 @@ const defaultConfig: Config = { useAngularBasedHttpClientInAlfrescoJs: false };
]
})
export class CoreModule {
static forRoot(config: Config = defaultConfig): ModuleWithProviders<CoreModule> {
static forRoot(): ModuleWithProviders<CoreModule> {
return {
ngModule: CoreModule,
providers: [
@@ -159,7 +151,7 @@ export class CoreModule {
{
provide: APP_INITIALIZER,
useFactory: loadAppConfig,
deps: [ AppConfigService, StorageService ], multi: true
deps: [ AppConfigService, StorageService, AdfHttpClient ], multi: true
},
{
provide: APP_INITIALIZER,
@@ -180,11 +172,7 @@ export class CoreModule {
useFactory: createAlfrescoApiInstance,
deps: [ AlfrescoApiLoaderService ],
multi: true
},
...(config.useAngularBasedHttpClientInAlfrescoJs
? [{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceWithAngularBasedHttpClient }]
: []
)
}
]
};
}

View File

@@ -24,7 +24,6 @@ import { Router, ActivatedRoute, Params } from '@angular/router';
import { AuthenticationService } from '../../auth/services/authentication.service';
import { TranslationService } from '../../translation/translation.service';
import { UserPreferencesService } from '../../common/services/user-preferences.service';
import { AlfrescoApiService } from '../../services/alfresco-api.service';
import { LoginErrorEvent } from '../models/login-error.event';
import { LoginSubmitEvent } from '../models/login-submit.event';
@@ -136,8 +135,7 @@ export class LoginComponent implements OnInit, OnDestroy {
private appConfig: AppConfigService,
private userPreferences: UserPreferencesService,
private route: ActivatedRoute,
private sanitizer: DomSanitizer,
private alfrescoApiService: AlfrescoApiService
private sanitizer: DomSanitizer
) {
}
@@ -188,7 +186,7 @@ export class LoginComponent implements OnInit, OnDestroy {
}
redirectToImplicitLogin() {
this.alfrescoApiService.getInstance().oauth2Auth.implicitLogin();
this.authService.ssoImplicitLogin();
}
/**

View File

@@ -1,39 +0,0 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import 'zone.js';
import 'zone.js/testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
declare const require: any;
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting(), {
teardown: { destroyAfterEach: false }
}
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);