[Library | Trunk]: Loginguard check userinfo, not token
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@58028 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
b510d104d2
commit
659fab0b1b
|
@ -1,39 +1,27 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {
|
||||
Router,
|
||||
CanActivate,
|
||||
ActivatedRouteSnapshot,
|
||||
RouterStateSnapshot,
|
||||
CanLoad,
|
||||
Route,
|
||||
UrlSegment
|
||||
} from '@angular/router';
|
||||
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {Observable} from 'rxjs';
|
||||
import {Session} from './utils/helper.class';
|
||||
import {LoginErrorCodes} from './utils/guardHelper.class';
|
||||
import {UserManagementService} from "../services/user-management.service";
|
||||
import {EnvironmentSpecificService} from "../utils/properties/environment-specific.service";
|
||||
import {filter, map, mergeMap} from "rxjs/operators";
|
||||
import {filter, map} from "rxjs/operators";
|
||||
|
||||
@Injectable()
|
||||
export class AdminLoginGuard implements CanActivate{
|
||||
|
||||
export class AdminLoginGuard implements CanActivate {
|
||||
|
||||
constructor(private router: Router,
|
||||
private userManagementService: UserManagementService,
|
||||
private propertiesService: EnvironmentSpecificService) {
|
||||
private userManagementService: UserManagementService) {
|
||||
}
|
||||
|
||||
check(path: string): Observable<boolean> {
|
||||
|
||||
check(path: string): Observable<boolean> {
|
||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => {
|
||||
return this.userManagementService.getUserInfo(false).pipe(map(user => {
|
||||
if(user) {
|
||||
errorCode = LoginErrorCodes.NOT_ADMIN;
|
||||
}
|
||||
return Session.isPortalAdministrator(user);
|
||||
}));
|
||||
const obs = this.userManagementService.getUserInfo(false).pipe(map(user => {
|
||||
if (user) {
|
||||
errorCode = LoginErrorCodes.NOT_ADMIN;
|
||||
}
|
||||
return Session.isPortalAdministrator(user);
|
||||
}));
|
||||
obs.pipe(filter( isAdmin => !isAdmin)).subscribe( () => {
|
||||
obs.pipe(filter(isAdmin => !isAdmin)).subscribe(() => {
|
||||
this.router.navigate(['/user-info'], {
|
||||
queryParams: {
|
||||
'errorCode': errorCode,
|
||||
|
@ -43,31 +31,9 @@ export class AdminLoginGuard implements CanActivate{
|
|||
});
|
||||
return obs;
|
||||
}
|
||||
|
||||
/* check(path: string): boolean {
|
||||
let loggedIn = false;
|
||||
let isAdmin = false;
|
||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
if (Session.isLoggedIn()) {
|
||||
loggedIn = true;
|
||||
isAdmin = Session.isPortalAdministrator();
|
||||
if (!isAdmin) {
|
||||
errorCode = LoginErrorCodes.NOT_ADMIN;
|
||||
}
|
||||
}
|
||||
if (!loggedIn || !isAdmin) {
|
||||
this.router.navigate(['/user-info'], {
|
||||
queryParams: {
|
||||
'errorCode': errorCode,
|
||||
'redirectUrl': path
|
||||
}
|
||||
});
|
||||
}
|
||||
return loggedIn && isAdmin;
|
||||
}*/
|
||||
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
return this.check(state.url);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,39 +1,27 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {
|
||||
Router,
|
||||
CanActivate,
|
||||
ActivatedRouteSnapshot,
|
||||
RouterStateSnapshot,
|
||||
CanLoad,
|
||||
Route,
|
||||
UrlSegment
|
||||
} from '@angular/router';
|
||||
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {Observable} from 'rxjs';
|
||||
import {Session} from './utils/helper.class';
|
||||
import {LoginErrorCodes} from './utils/guardHelper.class';
|
||||
import {filter, map, mergeMap} from "rxjs/operators";
|
||||
import {EnvironmentSpecificService} from "../utils/properties/environment-specific.service";
|
||||
import {filter, map} from "rxjs/operators";
|
||||
import {UserManagementService} from "../services/user-management.service";
|
||||
|
||||
@Injectable()
|
||||
export class ClaimsCuratorGuard implements CanActivate {
|
||||
|
||||
|
||||
constructor(private router: Router,
|
||||
private userManagementService: UserManagementService,
|
||||
private propertiesService: EnvironmentSpecificService) {
|
||||
private userManagementService: UserManagementService) {
|
||||
}
|
||||
|
||||
check(path: string): Observable<boolean> |boolean {
|
||||
|
||||
check(path: string): Observable<boolean> | boolean {
|
||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => {
|
||||
return this.userManagementService.getUserInfo(false).pipe(map(user => {
|
||||
if(user) {
|
||||
errorCode = LoginErrorCodes.NOT_ADMIN;
|
||||
}
|
||||
return Session.isClaimsCurator(user) || Session.isPortalAdministrator(user);
|
||||
}));
|
||||
const obs = this.userManagementService.getUserInfo(false).pipe(map(user => {
|
||||
if (user) {
|
||||
errorCode = LoginErrorCodes.NOT_ADMIN;
|
||||
}
|
||||
return Session.isClaimsCurator(user) || Session.isPortalAdministrator(user);
|
||||
}));
|
||||
obs.pipe(filter( isAdmin => !isAdmin)).subscribe( () => {
|
||||
obs.pipe(filter(isAdmin => !isAdmin)).subscribe(() => {
|
||||
this.router.navigate(['/user-info'], {
|
||||
queryParams: {
|
||||
'errorCode': errorCode,
|
||||
|
@ -43,9 +31,9 @@ export class ClaimsCuratorGuard implements CanActivate {
|
|||
});
|
||||
return obs;
|
||||
}
|
||||
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
return this.check(state.url);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -3,28 +3,35 @@ import {ActivatedRouteSnapshot, CanActivate, CanLoad, Route, Router, RouterState
|
|||
import {Observable} from 'rxjs/Observable';
|
||||
import {Session} from './utils/helper.class';
|
||||
import {LoginErrorCodes} from './utils/guardHelper.class';
|
||||
import {filter, map} from "rxjs/operators";
|
||||
import {UserManagementService} from "../services/user-management.service";
|
||||
|
||||
@Injectable()
|
||||
export class LoginGuard implements CanActivate, CanLoad {
|
||||
|
||||
constructor(private router: Router) {
|
||||
|
||||
constructor(private router: Router,
|
||||
private userManagementService: UserManagementService) {
|
||||
}
|
||||
|
||||
check(path: string): boolean {
|
||||
let loggedIn = false;
|
||||
|
||||
check(path: string): Observable<boolean> | boolean {
|
||||
if (Session.isLoggedIn()) {
|
||||
loggedIn = true;
|
||||
}
|
||||
if (!loggedIn) {
|
||||
const obs = this.userManagementService.getUserInfo(false).pipe(map(user => {
|
||||
return user !== null;
|
||||
}));
|
||||
obs.pipe(filter(isLoggedIn => !isLoggedIn)).subscribe(() => {
|
||||
this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_LOGIN, path}});
|
||||
});
|
||||
return obs;
|
||||
} else {
|
||||
this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_LOGIN, path}});
|
||||
return false;
|
||||
}
|
||||
return loggedIn;
|
||||
}
|
||||
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
return this.check(state.url);
|
||||
}
|
||||
|
||||
|
||||
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
||||
return this.check('/' + route.path);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue