module Sfx { export class AuthenticationService { public isApplicationBootstrapped : boolean = false ; private adalAuthenticationService : IAdalAuthenticationService ; constructor ( $injector , private $rootScope , private clusterTree , private refreshSvc , private authenticationData ) { if ( this . needAadAuthentication ) { this . adalAuthenticationService = $injector . get < IAdalAuthenticationService > ( "adalAuthenticationService" ) ; } if ( this . needAadAuthentication && ! this . isAadAuthenticated ) { $rootScope . $on ( "adal:loginSuccess" , ( ) => { console . log ( "adal:loginSuccess" ) ; this . bootstrapApplication ( ) ; } ) ; $rootScope . $on ( "adal:acquireTokenSuccess" , ( ) => { console . log ( "adal:acquireTokenSuccess" ) ; this . bootstrapApplication ( ) ; } ) ; $rootScope . $on ( "adal:loginFailure" , ( ) => { console . log ( "adal:loginFailure" ) ; } ) ; $rootScope . $on ( "adal:notAuthorized" , ( ) => { console . log ( "adal:notAuthorized" ) ; } ) ; } else { this . bootstrapApplication ( ) ; } } public get needAadAuthentication ( ) : boolean { return this . authenticationData && this . authenticationData . isAadAuthType ; } public get isAadAuthenticated ( ) : boolean { return this . $rootScope . userInfo && this . $rootScope . userInfo . isAuthenticated ; } public logOut ( ) { if ( this . adalAuthenticationService ) { this . adalAuthenticationService . logOut ( ) ; } } public bootstrapApplication ( ) { this . clusterTree . init ( ) ; this . refreshSvc . init ( ) ; this . isApplicationBootstrapped = true ; this . refreshSvc . refreshAll ( ) ; } } ( function ( ) { let module = angular . module ( "authenticationService" , [ ] ) ; module . factory ( "auth" , [ "$injector" , "$rootScope" , "clusterTree" , "refresh" , "authenticationData" , ( $injector , $rootScope , clusterTree , refresh , authenticationData ) => new AuthenticationService ( $injector , $rootScope , clusterTree , refresh , authenticationData ) ] ) ; } ) ( ) ; }