Skip to content

Commit

Permalink
[ACS-6748] BasicAlfrescoAuthService.requireAlfTicket should not be in…
Browse files Browse the repository at this point in the history
… adf/core
  • Loading branch information
dominikiwanekhyland committed Mar 1, 2024
1 parent f7d8319 commit 2770884
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*!
* @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 { ContentAuthLoaderService } from './content-auth-loader.service';

// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
/**
* Create a content auth factory
*
* @param authLoaderService service dependency
* @returns factory function
*/
export function contentAuthLoaderFactory(authLoaderService: ContentAuthLoaderService) {
return () => authLoaderService.init();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*!
* @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 { Injectable } from '@angular/core';
import { AuthenticationService, BasicAlfrescoAuthService } from '@alfresco/adf-core';

@Injectable()
export class ContentAuthLoaderService {

constructor(
private readonly basicAlfrescoAuthService: BasicAlfrescoAuthService,
private readonly authService: AuthenticationService,
) {
}
init(): void {
this.authService.onLogin.subscribe(async () => {
if (this.authService.isOauth() && (this.authService.isALLProvider() || this.authService.isECMProvider())) {
await this.basicAlfrescoAuthService.requireAlfTicket();
}
});
}
}
11 changes: 10 additions & 1 deletion lib/content-services/src/lib/content.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ import { AlfrescoViewerModule } from './viewer/alfresco-viewer.module';
import { ContentUserInfoModule } from './content-user-info/content-user-info.module';
import { SecurityControlsServiceModule } from './security/services/security-controls-service.module';
import { CategoriesModule } from './category/category.module';
import { contentAuthLoaderFactory } from './auth-loader/content-auth-loader-factory';
import { ContentAuthLoaderService } from './auth-loader/content-auth-loader.service';

@NgModule({
imports: [
Expand Down Expand Up @@ -128,13 +130,20 @@ export class ContentModule {
ngModule: ContentModule,
providers: [
provideTranslations('adf-content-services', 'assets/adf-content-services'),
ContentAuthLoaderService,
{
provide: APP_INITIALIZER,
useFactory: versionCompatibilityFactory,
deps: [VersionCompatibilityService],
multi: true
},
{
provide: APP_INITIALIZER,
useFactory: contentAuthLoaderFactory,
deps: [ContentAuthLoaderService],
multi: true
}
]
]
};
}

Expand Down
10 changes: 0 additions & 10 deletions lib/core/src/lib/api-factories/alfresco-api-v2-loader.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { Injectable } from '@angular/core';
import { AppConfigService, AppConfigValues } from '../app-config/app-config.service';
import { AlfrescoApiService } from '../services/alfresco-api.service';
import { StorageService } from '../common/services/storage.service';
import { AuthenticationService, BasicAlfrescoAuthService } from '../auth';

/**
* Create a factory to resolve an api service instance
Expand All @@ -38,20 +37,11 @@ export function createAlfrescoApiInstance(angularAlfrescoApiService: AlfrescoApi
export class AlfrescoApiLoaderService {
constructor(private readonly appConfig: AppConfigService,
private readonly apiService: AlfrescoApiService,
private readonly basicAlfrescoAuthService: BasicAlfrescoAuthService,
private readonly authService: AuthenticationService,
private storageService: StorageService) {
}

async init(): Promise<any> {
await this.appConfig.load();

this.authService.onLogin.subscribe(async () => {
if (this.authService.isOauth() && (this.authService.isALLProvider() || this.authService.isECMProvider())) {
await this.basicAlfrescoAuthService.requireAlfTicket();
}
});

return this.initAngularAlfrescoApi();
}

Expand Down

0 comments on commit 2770884

Please sign in to comment.