Skip to content

Commit af4100a

Browse files
committed
Stripped keycloak stuff from dashboard
Fixes #2686
1 parent 477ae67 commit af4100a

4 files changed

Lines changed: 33 additions & 297 deletions

File tree

restcomm/restcomm.ui/src/main/webapp/resources/js/controllers.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,3 @@ angular.module('rcApp.controllers').controller('RestcommCtrl', function ($scope,
1212
$scope.loggedAccount = AuthService.getAccount();
1313
$scope.sid = AuthService.getAccountSid();
1414
});
15-
16-
angular.module('rcApp.controllers').controller('IdentityRegistrationCtrl', function ($scope, RCommIdentityInstances) {
17-
$scope.info = {
18-
InitialAccessToken: "",
19-
RedirectUrl: "",
20-
KeycloakBaseUrl: ""
21-
};
22-
$scope.accountInfo = {
23-
username: "",
24-
password: ""
25-
};
26-
27-
$scope.registerInstance = function(info, accountInfo) {
28-
var authHeader = "Basic " + btoa(accountInfo.username + ":" + accountInfo.password);
29-
RCommIdentityInstances.register(info, authHeader).success(function (data, status) {
30-
console.log("successfully registered instance");
31-
}).error(function (data, status) {
32-
console.log("error registering instance");
33-
});
34-
35-
}
36-
37-
});

restcomm/restcomm.ui/src/main/webapp/resources/js/controllers/events.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,6 @@ angular.module('rcApp').controller('EventsCtrl', function ($rootScope, $state, N
1818
urlStateTracker.remember($location);
1919
$state.go("public.login");
2020
} else
21-
if (error == "KEYCLOAK_INSTANCE_NOT_REGISTERED") {
22-
console.log("Identity Instance not registered.");
23-
$state.go("public.identity-registration");
24-
} else
25-
if (error == "KEYCLOAK_INSTANCE_ALREADY_REGISTERED") {
26-
console.log("Identity Instance is already registered.");
27-
$state.go("restcomm.dashboard");
28-
} else
29-
if (error == "IDENTITY_REGISTRATION_NOT_AVAILABLE") { // we are trying to access restcomm registration view while in restcomm-authentication mode
30-
$state.go("restcomm.dashboard");
31-
} else
3221
if (error == 'RESTCOMM_ACCOUNT_NOT_INITIALIZED') {
3322
$state.go('public.uninitialized');
3423
} else

restcomm/restcomm.ui/src/main/webapp/resources/js/restcomm.js

Lines changed: 6 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
240191
angular.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

341199
rcMod.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
381239
rcMod.
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

Comments
 (0)