[ADF-3181] Auth Guard - redirect by string url (#3474)

* redirect by string url

* auth guard tests fix

* revise
This commit is contained in:
Cilibiu Bogdan
2018-06-14 12:19:34 +03:00
committed by Eugenio Romano
parent 0cf2a35983
commit c0de0d5087
12 changed files with 55 additions and 111 deletions

View File

@@ -18,7 +18,7 @@
import { Injectable } from '@angular/core';
import {
ActivatedRouteSnapshot, CanActivate, CanActivateChild, RouterStateSnapshot,
Router, PRIMARY_OUTLET, UrlTree, UrlSegmentGroup, UrlSegment
Router
} from '@angular/router';
import { AppConfigService } from '../app-config/app-config.service';
import { AuthenticationService } from './authentication.service';
@@ -45,9 +45,7 @@ export class AuthGuardBpm implements CanActivate, CanActivateChild {
}
if (!this.authService.isOauth() || this.isOAuthWithoutSilentLogin() ) {
const navigation = this.getNavigationCommands(redirectUrl);
this.authService.setRedirect({ provider: 'BPM', navigation });
this.authService.setRedirect({ provider: 'BPM', url: redirectUrl });
const pathToLogin = this.getRouteDestinationForLogin();
this.router.navigate(['/' + pathToLogin]);
}
@@ -64,20 +62,4 @@ export class AuthGuardBpm implements CanActivate, CanActivateChild {
this.appConfig.get<string>('loginRoute') ?
this.appConfig.get<string>('loginRoute') : 'login';
}
private getNavigationCommands(redirectUrl: string): any[] {
const urlTree: UrlTree = this.router.parseUrl(redirectUrl);
const urlSegmentGroup: UrlSegmentGroup = urlTree.root.children[PRIMARY_OUTLET];
if (!urlSegmentGroup) {
return [redirectUrl];
}
const urlSegments: UrlSegment[] = urlSegmentGroup.segments;
return urlSegments.reduce(function(acc, item) {
acc.push(item.path, item.parameters);
return acc;
}, []);
}
}