1 import { Injectable } from '@angular/core';
3 ActivatedRouteSnapshot,
8 } from '@angular/router';
10 import { AuthStorageService } from './auth-storage.service';
13 * This service guard checks if a user must be redirected to a special
14 * page at '/login-change-password' to set a new password.
19 export class ChangePasswordGuardService implements CanActivate, CanActivateChild {
20 constructor(private router: Router, private authStorageService: AuthStorageService) {}
22 canActivate(_route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
23 // Redirect to '/login-change-password' when the following constraints
25 // - The user must be logged in.
26 // - SSO must be disabled.
27 // - The flag 'User must change password at next logon' must be set.
29 this.authStorageService.isLoggedIn() &&
30 !this.authStorageService.isSSO() &&
31 this.authStorageService.getPwdUpdateRequired()
33 this.router.navigate(['/login-change-password'], { queryParams: { returnUrl: state.url } });
39 canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
40 return this.canActivate(childRoute, state);