-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* login/logout workflow * login-workflow fix * auth * comments fix
- Loading branch information
Showing
26 changed files
with
22,421 additions
and
21,497 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Created by cshampur on 11/7/16. | ||
*/ | ||
|
||
import {Directive, ElementRef, Renderer, Input, OnInit, TemplateRef, ViewContainerRef} from "@angular/core"; | ||
import {AuthService} from "../utils/authservice"; | ||
|
||
@Directive({ | ||
selector: '[auth]' | ||
}) | ||
|
||
export class AuthDirective implements OnInit{ | ||
|
||
@Input('auth') auth: string; | ||
constructor(private authService: AuthService, | ||
private templateRef: TemplateRef<any>, | ||
private viewContainer: ViewContainerRef){ | ||
this.auth = ''; | ||
} | ||
|
||
ngOnInit(){ | ||
if (this.auth == this.authService.authTokenPayload['role']){ | ||
this.viewContainer.createEmbeddedView(this.templateRef); | ||
} | ||
else{ | ||
this.viewContainer.clear(); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Created by cshampur on 11/4/16. | ||
*/ | ||
|
||
export const AuthMatrix = { | ||
'dashboard': {'DevOps':'y', 'SysAdmin':'y'}, | ||
'networkpolicies/list': {'DevOps':'y', 'SysAdmin':'y'}, | ||
'networkpolicies/isolation/create': {'DevOps':'n', 'SysAdmin':'y'}, | ||
'networkpolicies/isolation/details': {'DevOps':'y', 'SysAdmin':'y'}, | ||
'networkpolicies/isolation/edit': {'DevOps':'n', 'SysAdmin':'y'}, | ||
'networkpolicies/bandwidth/create': {'DevOps':'y', 'SysAdmin':'y'}, | ||
'networkpolicies/bandwidth/details': {'DevOps':'y', 'SysAdmin':'y'}, | ||
'networkpolicies/bandwidth/edit': {'DevOps':'n', 'SysAdmin':'y'}, | ||
'applicationgroups/list': {'DevOps':'y', 'SysAdmin':'y'}, | ||
'applicationgroups/create': {'DevOps':'n', 'SysAdmin':'y'}, | ||
'applicationgroups/details': {'DevOps':'y', 'SysAdmin':'y'}, | ||
'applicationgroups/edit': {'DevOps':'n', 'SysAdmin':'y'}, | ||
'settings/cluster': {'DevOps':'n', 'SysAdmin':'y'}, | ||
'settings/networks': {'DevOps':'n', 'SysAdmin':'y'}, | ||
'organizations/list': {'DevOps':'y', 'SysAdmin':'y'}, | ||
'organizations/create': {'DevOps':'n', 'SysAdmin':'y'}, | ||
'organizations/details': {'DevOps':'y', 'SysAdmin':'y'}, | ||
'networks/list': {'DevOps':'y', 'SysAdmin':'y'}, | ||
'networks/create': {'DevOps':'n', 'SysAdmin':'y'}, | ||
'networks/details': {'DevOps':'y', 'SysAdmin':'y'}, | ||
'servicelbs/list': {'DevOps':'y', 'SysAdmin':'y'}, | ||
'servicelbs/create': {'DevOps':'n', 'SysAdmin':'y'}, | ||
'servicelbs/details': {'DevOps':'y', 'SysAdmin':'y'} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* Created by cshampur on 11/4/16. | ||
*/ | ||
import { Injectable } from '@angular/core'; | ||
import {CanActivate, Router, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateChild} from '@angular/router'; | ||
import {AuthService} from "./authservice"; | ||
import {AuthMatrix} from "./authMatrix"; | ||
import {isNull} from "util"; | ||
|
||
@Injectable() | ||
export class AuthGuard implements CanActivate, CanActivateChild { | ||
|
||
accessMatrix:any; | ||
unguardedUrls: string[]; | ||
|
||
constructor(private authService: AuthService, private router: Router) { | ||
this.accessMatrix = AuthMatrix; | ||
this.unguardedUrls = ['/unauthorized', '/login', '/logout']; | ||
} | ||
|
||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { | ||
let url: string = state.url; | ||
if (this.unguardedUrls.indexOf(url) > -1) | ||
return true; | ||
return this.checkLogin(url); | ||
} | ||
|
||
canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { | ||
return this.canActivate(route, state); | ||
} | ||
|
||
checkLogin(url: string): boolean { | ||
|
||
if (this.authService.isLoggedIn) { | ||
if (this.checkAccess(url)) | ||
if (this.authService.validateExpiry()) | ||
return true; | ||
else{ | ||
this.loadLogin(url); | ||
return false; | ||
} | ||
else{ | ||
this.router.navigate(['/unauthorized']); | ||
return false; | ||
} | ||
|
||
} | ||
// Validate Token Expiration | ||
if (!isNull(localStorage.getItem("authToken"))){ | ||
this.authService.extractBody(); | ||
if(this.authService.validateExpiry()){ | ||
this.authService.isLoggedIn = true; | ||
if(this.checkAccess(url)) | ||
return true; | ||
else{ | ||
this.router.navigate(['/unauthorized']); | ||
} | ||
} | ||
} | ||
|
||
this.loadLogin(url); | ||
return false; | ||
} | ||
|
||
loadLogin(url: string): void{ | ||
// Clean the local storage | ||
this.authService.cleanuplocalstorage(); | ||
// Store the attempted URL for redirecting | ||
this.authService.redirectUrl = url; | ||
// Navigate to the login page | ||
this.router.navigate(['/login']); | ||
} | ||
|
||
checkAccess(url:string): boolean{ | ||
return this.authService.checkAccess(url); | ||
} | ||
|
||
|
||
|
||
} |
Oops, something went wrong.