diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index f1598ca89..33684c335 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -69,6 +69,7 @@ import { AppCurrentUserModule } from './components/current-user/current-user.mod
import { AppSearchInputModule } from './components/search/search-input.module';
import { AppSearchResultsModule } from './components/search/search-results.module';
import { AppLoginModule } from './components/login/login.module';
+import { AppAuthGuard } from './guards/auth.guard';
@NgModule({
imports: [
@@ -119,6 +120,7 @@ import { AppLoginModule } from './components/login/login.module';
source: 'assets'
}
},
+ AppAuthGuard,
ContentManagementService,
NodeActionsService,
NodePermissionService,
diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts
index f4e15dfdb..5542ae1a3 100644
--- a/src/app/app.routes.ts
+++ b/src/app/app.routes.ts
@@ -24,7 +24,6 @@
*/
import { Routes } from '@angular/router';
-import { AuthGuardEcm } from '@alfresco/adf-core';
import { LayoutComponent } from './components/layout/layout.component';
import { FilesComponent } from './components/files/files.component';
import { LibrariesComponent } from './components/libraries/libraries.component';
@@ -32,6 +31,7 @@ import { GenericErrorComponent } from './components/common/generic-error/generic
import { SearchResultsComponent } from './components/search/search-results/search-results.component';
import { ProfileResolver } from './services/profile.resolver';
import { LoginComponent } from './components/login/login.component';
+import { AppAuthGuard } from './guards/auth.guard';
export const APP_ROUTES: Routes = [
{
@@ -235,7 +235,7 @@ export const APP_ROUTES: Routes = [
component: GenericErrorComponent
}
],
- canActivateChild: [AuthGuardEcm],
- canActivate: [AuthGuardEcm]
+ canActivateChild: [AppAuthGuard],
+ canActivate: [AppAuthGuard]
}
];
diff --git a/src/app/components/login/login.component.ts b/src/app/components/login/login.component.ts
index 20900da2e..54a589b55 100644
--- a/src/app/components/login/login.component.ts
+++ b/src/app/components/login/login.component.ts
@@ -26,6 +26,7 @@
import { Component, OnInit } from '@angular/core';
import { Location } from '@angular/common';
import { AuthenticationService } from '@alfresco/adf-core';
+import { ActivatedRoute, Params } from '@angular/router';
@Component({
templateUrl: './login.component.html'
@@ -33,12 +34,18 @@ import { AuthenticationService } from '@alfresco/adf-core';
export class LoginComponent implements OnInit {
constructor(
private location: Location,
- private auth: AuthenticationService
+ private auth: AuthenticationService,
+ private route: ActivatedRoute
) {}
ngOnInit() {
if (this.auth.isEcmLoggedIn()) {
this.location.forward();
+ } else {
+ this.route.queryParams.subscribe((params: Params) => {
+ const redirectUrl = params['redirectUrl'];
+ this.auth.setRedirect({ provider: 'ECM', url: redirectUrl });
+ });
}
}
}
diff --git a/src/app/extensions/core.extensions.module.ts b/src/app/extensions/core.extensions.module.ts
index e7ba94c45..a9711cb77 100644
--- a/src/app/extensions/core.extensions.module.ts
+++ b/src/app/extensions/core.extensions.module.ts
@@ -23,7 +23,7 @@
* along with Alfresco. If not, see .
*/
-import { AuthGuardEcm, CoreModule } from '@alfresco/adf-core';
+import { CoreModule } from '@alfresco/adf-core';
import { CommonModule } from '@angular/common';
import { APP_INITIALIZER, ModuleWithProviders, NgModule } from '@angular/core';
import { LayoutComponent } from '../components/layout/layout.component';
@@ -36,6 +36,7 @@ import { MetadataTabComponent } from '../components/info-drawer/metadata-tab/met
import { CommentsTabComponent } from '../components/info-drawer/comments-tab/comments-tab.component';
import { VersionsTabComponent } from '../components/info-drawer/versions-tab/versions-tab.component';
import { ExtensionsModule, ExtensionService } from '@alfresco/adf-extensions';
+import { AppAuthGuard } from '../guards/auth.guard';
export function setupExtensions(service: AppExtensionService): Function {
return () => service.load();
@@ -77,7 +78,7 @@ export class CoreExtensionsModule {
});
extensions.setAuthGuards({
- 'app.auth': AuthGuardEcm
+ 'app.auth': AppAuthGuard
});
extensions.setEvaluators({
diff --git a/src/app/guards/auth.guard.ts b/src/app/guards/auth.guard.ts
new file mode 100644
index 000000000..3581f6cb3
--- /dev/null
+++ b/src/app/guards/auth.guard.ts
@@ -0,0 +1,56 @@
+/*!
+ * @license
+ * Alfresco Example Content Application
+ *
+ * Copyright (C) 2005 - 2018 Alfresco Software Limited
+ *
+ * This file is part of the Alfresco Example Content Application.
+ * If the software was purchased under a paid Alfresco license, the terms of
+ * the paid license agreement will prevail. Otherwise, the software is
+ * provided under the following open source license terms:
+ *
+ * The Alfresco Example Content Application is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * The Alfresco Example Content Application is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ */
+
+import { Injectable } from '@angular/core';
+import { Router } from '@angular/router';
+import {
+ AuthenticationService,
+ AppConfigService,
+ AuthGuardEcm
+} from '@alfresco/adf-core';
+
+@Injectable()
+export class AppAuthGuard extends AuthGuardEcm {
+ constructor(
+ private _auth: AuthenticationService,
+ private _router: Router,
+ config: AppConfigService
+ ) {
+ super(_auth, _router, config);
+ }
+
+ checkLogin(redirectUrl: string): boolean {
+ if (this._auth.isEcmLoggedIn()) {
+ return true;
+ }
+
+ if (!this._auth.isOauth() || this.isOAuthWithoutSilentLogin()) {
+ this._auth.setRedirect({ provider: 'ECM', url: redirectUrl });
+ this._router.navigateByUrl('/login?redirectUrl=' + redirectUrl);
+ }
+
+ return false;
+ }
+}