@@ -24,21 +24,13 @@ rcMod.config(['$stateProvider','$urlRouterProvider', function($stateProvider, $u
2424 $stateProvider . state ( 'public.login' , {
2525 url :"/login" ,
2626 templateUrl :'modules/login.html' ,
27- controller :'LoginCtrl' ,
28- resolve : {
29- identity : function ( IdentityConfig ) {
30- return IdentityConfig . getIdentity ( ) ;
31- }
32- }
27+ controller :'LoginCtrl'
3328 } ) ;
3429 $stateProvider . state ( 'public.uninitialized' , {
3530 url :"/uninitialized" ,
3631 templateUrl : 'modules/uninitialized.html' ,
3732 controller :'UninitializedCtrl' ,
3833 resolve : {
39- identity : function ( IdentityConfig ) {
40- return IdentityConfig . getIdentity ( ) ;
41- } ,
4234 uninitialized : function ( AuthService , $q ) {
4335 try {
4436 return $q . when ( AuthService . checkAccess ( ) ) . then ( function ( ) {
@@ -53,35 +45,6 @@ rcMod.config(['$stateProvider','$urlRouterProvider', function($stateProvider, $u
5345 }
5446 }
5547 } ) ;
56- $stateProvider . state ( 'public.identity-registration' , {
57- url :"/identity-registration" ,
58- templateUrl :'modules/identity-registration.html' ,
59- controller :'IdentityRegistrationCtrl' ,
60- resolve : {
61- identity : function ( IdentityConfig , $state , Notifications , $q ) {
62- var deferred = $q . defer ( ) ;
63- var valueOrPromise = IdentityConfig . getIdentity ( ) ;
64- if ( valueOrPromise === null ) // identity notion is not applicable - keycloak is not used
65- deferred . reject ( 'IDENTITY_REGISTRATION_NOT_AVAILABLE' ) ;
66- else {
67- valueOrPromise . then ( function ( registeredInstance ) {
68- deferred . reject ( "KEYCLOAK_INSTANCE_ALREADY_REGISTERED" ) ;
69- } , function ( value ) {
70- if ( value == "KEYCLOAK_INSTANCE_NOT_REGISTERED" ) {
71- deferred . resolve ( null ) ; // no instance registered - that's prefectly fine for this view
72- } else {
73- // we shouldn't be here
74- Notifications . error ( 'Invalid state error' ) ;
75- deferred . reject ( value ) ;
76- }
77- } ) ;
78- }
79- return deferred . promise ;
80- }
81- }
82- } ) ;
83- $stateProvider . state ( 'public.registerinstance' , {
84- } ) ;
8548 // 'restcomm' state assumes (requires) an authorized restcomm Account to have been determined. Child states can take that for granted.
8649 $stateProvider . state ( 'restcomm' , {
8750 templateUrl :'templates/restcomm-state.html' ,
@@ -90,9 +53,6 @@ rcMod.config(['$stateProvider','$urlRouterProvider', function($stateProvider, $u
9053 authorize : function ( AuthService ) {
9154 return AuthService . checkAccess ( ) ;
9255 } ,
93- identity : function ( IdentityConfig ) {
94- return IdentityConfig . getIdentity ( ) ;
95- } ,
9656 dashboardConfig : function ( PublicConfig ) {
9757
9858 }
@@ -228,115 +188,13 @@ rcMod.config(['$stateProvider','$urlRouterProvider', function($stateProvider, $u
228188
229189} ] ) ;
230190
231- // Keycloak configuration ***
232-
233- var keycloakAuth = { } ;
234- var keycloakLogout = function ( ) {
235- keycloakAuth . loggedIn = false ;
236- keycloakAuth . authz = null ;
237- window . location = keycloakAuth . logoutUrl ;
238- } ;
239-
240191angular . element ( document ) . ready ( [ '$http' , function ( $http ) {
241192 // manually inject $q since it's not available
242193 var initInjector = angular . injector ( [ "ng" ] ) ;
243194 var $q = initInjector . get ( "$q" ) ;
244-
245- // try to retrieve Identity server configuration
246- var serverPromise = $q . defer ( ) ;
247- // disable until organizations/keycloak in place
248- /*
249- $http.get("/restcomm/2012-04-24/Identity/Server").success(function (serverConfig) {
250- console.log(serverConfig);
251- serverPromise.resolve(serverConfig);
252- }).error( function (response) {
253- if (response.status == 404)
254- serverPromise.resolve(null);
255- else
256- serverPromise.reject();
257- });
258- */
259- serverPromise . resolve ( null ) ;
260-
261- // try to retrieve IdentityInstance
262- var instancePromise = $q . defer ( ) ;
263- // disable until organizations/keycloak in place
264- /*
265- $http.get("/restcomm/2012-04-24/Identity/Instances/current").success(function (instance) {
266- instancePromise.resolve(instance);
267- }).error(function (response) {
268- if (response.status == 404)
269- instancePromise.resolve(null);
270- else
271- instancePromise.reject();
272- });*/
273- instancePromise . resolve ( null ) ;
274-
275- // when both responses are received do sth...
276- $q . all ( [ serverPromise . promise , instancePromise . promise ] ) . then ( function ( responses ) {
277- //console.log("SUCCESS");
278- // create a constant with keycloak server and instance identity configuration
279- var identityConfig = new IdentityConfig ( responses [ 0 ] , responses [ 1 ] , $q ) ;
280- angular . module ( 'rcApp' ) . constant ( 'IdentityConfig' , identityConfig ) ;
281- angular . module ( 'rcApp' ) . factory ( 'KeycloakAuth' , function ( ) {
282- return keycloakAuth ;
283- } ) ;
284- if ( identityConfig . securedByKeycloak ( ) ) {
285- // if the instance is already secured by keycloak
286- var keycloak = new Keycloak ( { url : identityConfig . server . authServerUrl , realm : identityConfig . server . realm , clientId : identityConfig . instance . name + "-restcomm-ui" } ) ;
287- keycloakAuth . loggedIn = false ;
288- keycloak . init ( { onLoad : 'login-required' } ) . success ( function ( ) {
289- keycloakAuth . loggedIn = true ;
290- keycloakAuth . authz = keycloak ;
291- keycloakAuth . logoutUrl = identityConfig . server . authServerUrl + "/realms/" + identityConfig . server . realm + "/protocol/openid-connect/logout?redirect_uri=" + window . location . origin ;
292- angular . bootstrap ( document , [ "rcApp" ] ) ;
293- } ) . error ( function ( a , b ) {
294- window . location . reload ( ) ;
295- } ) ;
296- } else
297- if ( identityConfig . identityServerConfigured ( ) && ! identityConfig . securedByKeycloak ( ) ) {
298- // keycloak is already configured but no identity instance yet
299- angular . bootstrap ( document , [ "rcApp" ] ) ;
300- } else {
301- // no identity configuration. We should run in compatibility authorization mode
302- angular . bootstrap ( document , [ "rcApp" ] ) ;
303- }
304-
305- } , function ( ) {
306- console . log ( "Internal server error" ) ;
307- } ) ;
308- } ] ) ;
309-
310-
311- // Authorization interceptor. It's effective when restcomm is secured by Keycloak.
312- angular . module ( 'rcApp' ) . factory ( 'authInterceptor' , function ( $q ) {
313- return {
314- request : function ( config ) {
315- if ( ! keycloakAuth . authz )
316- return config ;
317- var deferred = $q . defer ( ) ;
318- if ( keycloakAuth . authz . token ) {
319- keycloakAuth . authz . updateToken ( 5 ) . success ( function ( ) {
320- config . headers = config . headers || { } ;
321- config . headers . Authorization = 'Bearer ' + keycloakAuth . authz . token ;
322- deferred . resolve ( config ) ;
323- } ) . error ( function ( ) {
324- deferred . reject ( 'Failed to refresh token' ) ;
325- } ) ;
326- }
327- return deferred . promise ;
328- }
329- } ;
330- } ) . config ( [ '$httpProvider' , 'IdentityConfig' , function ( $httpProvider , IdentityConfig ) {
331- if ( IdentityConfig . securedByKeycloak ( ) ) {
332- $httpProvider . interceptors . push ( 'authInterceptor' ) ;
333- }
195+ angular . bootstrap ( document , [ "rcApp" ] ) ;
334196} ] ) ;
335197
336- // End-of Keycloak configuration ***
337-
338-
339-
340198
341199rcMod . directive ( 'equals' , function ( ) {
342200 return {
@@ -379,7 +237,7 @@ rcMod.run(function($rootScope, $location, $anchorScroll, AuthService) {
379237// There is a circular dependency issue when directly injecting AuthService in the function. A workaround using $injector has
380238// been used - http://stackoverflow.com/questions/20647483/angularjs-injecting-service-into-a-http-interceptor-circular-dependency
381239rcMod .
382- factory ( 'authHttpResponseInterceptor' , [ '$q' , '$location' , '$injector' , 'IdentityConfig' , ' Notifications', function ( $q , $location , $injector , IdentityConfig , Notifications ) {
240+ factory ( 'authHttpResponseInterceptor' , [ '$q' , '$location' , '$injector' , 'Notifications' , function ( $q , $location , $injector , Notifications ) {
383241 return {
384242 request : function ( config ) {
385243 var restcomm_prefix = "/restcomm/"
@@ -419,11 +277,9 @@ rcMod.
419277 }
420278 }
421279 } ] )
422- . config ( [ '$httpProvider' , 'IdentityConfig' , function ( $httpProvider , IdentityConfig ) {
423- if ( IdentityConfig . securedByRestcomm ( ) ) {
424- // http Intercpetor to check auth failures for xhr requests
425- $httpProvider . interceptors . push ( 'authHttpResponseInterceptor' ) ;
426- }
280+ . config ( [ '$httpProvider' , function ( $httpProvider ) {
281+ // http Intercpetor to check auth failures for xhr requests
282+ $httpProvider . interceptors . push ( 'authHttpResponseInterceptor' ) ;
427283 } ] ) ;
428284
429285/*
0 commit comments