KEYCLOAK-1876 Some admin console pages don't load properly when accessed via URL
This commit is contained in:
parent
fc0a3c3e73
commit
d4060cce92
3 changed files with 57 additions and 45 deletions
|
@ -14,16 +14,57 @@ var loadingTimer = -1;
|
||||||
angular.element(document).ready(function () {
|
angular.element(document).ready(function () {
|
||||||
var keycloakAuth = new Keycloak(configUrl);
|
var keycloakAuth = new Keycloak(configUrl);
|
||||||
|
|
||||||
|
function whoAmI(success, error) {
|
||||||
|
var req = new XMLHttpRequest();
|
||||||
|
req.open('GET', consoleBaseUrl + "/whoami", true);
|
||||||
|
req.setRequestHeader('Accept', 'application/json');
|
||||||
|
req.setRequestHeader('Authorization', 'bearer ' + keycloakAuth.token);
|
||||||
|
|
||||||
|
req.onreadystatechange = function () {
|
||||||
|
if (req.readyState == 4) {
|
||||||
|
if (req.status == 200) {
|
||||||
|
var data = JSON.parse(req.responseText);
|
||||||
|
success(data);
|
||||||
|
} else {
|
||||||
|
error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
req.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasAnyAccess(user) {
|
||||||
|
return user && user['realm_access'];
|
||||||
|
}
|
||||||
|
|
||||||
keycloakAuth.onAuthLogout = function() {
|
keycloakAuth.onAuthLogout = function() {
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
keycloakAuth.init({ onLoad: 'login-required' }).success(function () {
|
keycloakAuth.init({ onLoad: 'login-required' }).success(function () {
|
||||||
auth.authz = keycloakAuth;
|
auth.authz = keycloakAuth;
|
||||||
module.factory('Auth', function() {
|
|
||||||
return auth;
|
auth.refreshPermissions = function(success, error) {
|
||||||
|
whoAmI(function(data) {
|
||||||
|
auth.user = data;
|
||||||
|
auth.loggedIn = true;
|
||||||
|
auth.hasAnyAccess = hasAnyAccess(data);
|
||||||
|
|
||||||
|
success();
|
||||||
|
}, function() {
|
||||||
|
error();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
auth.refreshPermissions(function() {
|
||||||
|
module.factory('Auth', function() {
|
||||||
|
return auth;
|
||||||
|
});
|
||||||
|
angular.bootstrap(document, ["keycloak"]);
|
||||||
|
}, function() {
|
||||||
|
window.location.reload();
|
||||||
});
|
});
|
||||||
angular.bootstrap(document, ["keycloak"]);
|
|
||||||
}).error(function () {
|
}).error(function () {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,31 +1,9 @@
|
||||||
module.controller('GlobalCtrl', function($scope, $http, Auth, WhoAmI, Current, $location, Notifications, ServerInfo) {
|
module.controller('GlobalCtrl', function($scope, $http, Auth, Current, $location, Notifications, ServerInfo) {
|
||||||
$scope.addMessage = function() {
|
|
||||||
Notifications.success("test");
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.authUrl = authUrl;
|
$scope.authUrl = authUrl;
|
||||||
$scope.resourceUrl = resourceUrl;
|
$scope.resourceUrl = resourceUrl;
|
||||||
$scope.auth = Auth;
|
$scope.auth = Auth;
|
||||||
$scope.serverInfo = ServerInfo.get();
|
$scope.serverInfo = ServerInfo.get();
|
||||||
|
|
||||||
function hasAnyAccess() {
|
|
||||||
var realmAccess = Auth.user && Auth.user['realm_access'];
|
|
||||||
if (realmAccess) {
|
|
||||||
for (var p in realmAccess){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
WhoAmI.get(function (data) {
|
|
||||||
Auth.user = data;
|
|
||||||
Auth.loggedIn = true;
|
|
||||||
Auth.hasAnyAccess = hasAnyAccess();
|
|
||||||
});
|
|
||||||
|
|
||||||
function getAccess(role) {
|
function getAccess(role) {
|
||||||
if (!Current.realm) {
|
if (!Current.realm) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -155,7 +133,7 @@ module.controller('RealmDropdownCtrl', function($scope, Realm, Current, Auth, $l
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.controller('RealmCreateCtrl', function($scope, Current, Realm, $upload, $http, WhoAmI, $location, $route, Dialog, Notifications, Auth, $modal) {
|
module.controller('RealmCreateCtrl', function($scope, Current, Realm, $upload, $http, $location, $route, Dialog, Notifications, Auth, $modal) {
|
||||||
console.log('RealmCreateCtrl');
|
console.log('RealmCreateCtrl');
|
||||||
|
|
||||||
Current.realm = null;
|
Current.realm = null;
|
||||||
|
@ -193,22 +171,17 @@ module.controller('RealmCreateCtrl', function($scope, Current, Realm, $upload, $
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
$scope.$watch('realm.realm', function() {
|
$scope.$watch('realm.realm', function() {
|
||||||
if (create) {
|
|
||||||
$scope.realm.id = $scope.realm.realm;
|
$scope.realm.id = $scope.realm.realm;
|
||||||
}
|
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
$scope.save = function() {
|
$scope.save = function() {
|
||||||
var realmCopy = angular.copy($scope.realm);
|
var realmCopy = angular.copy($scope.realm);
|
||||||
Realm.create(realmCopy, function() {
|
Realm.create(realmCopy, function() {
|
||||||
Realm.query(function(data) {
|
Notifications.success("The realm has been created.");
|
||||||
Current.realms = data;
|
|
||||||
|
|
||||||
WhoAmI.get(function(user) {
|
|
||||||
Auth.user = user;
|
|
||||||
|
|
||||||
|
Auth.refreshPermissions(function() {
|
||||||
|
$scope.$apply(function() {
|
||||||
$location.url("/realms/" + realmCopy.realm);
|
$location.url("/realms/" + realmCopy.realm);
|
||||||
Notifications.success("The realm has been created.");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -227,7 +200,7 @@ module.controller('ObjectModalCtrl', function($scope, object) {
|
||||||
$scope.object = object;
|
$scope.object = object;
|
||||||
});
|
});
|
||||||
|
|
||||||
module.controller('RealmDetailCtrl', function($scope, Current, Realm, realm, serverInfo, $http, $location, Dialog, Notifications, WhoAmI, Auth) {
|
module.controller('RealmDetailCtrl', function($scope, Current, Realm, realm, serverInfo, $http, $location, Dialog, Notifications, Auth) {
|
||||||
$scope.createRealm = !realm.realm;
|
$scope.createRealm = !realm.realm;
|
||||||
$scope.serverInfo = serverInfo;
|
$scope.serverInfo = serverInfo;
|
||||||
|
|
||||||
|
@ -272,11 +245,13 @@ module.controller('RealmDetailCtrl', function($scope, Current, Realm, realm, ser
|
||||||
});
|
});
|
||||||
|
|
||||||
if (nameChanged) {
|
if (nameChanged) {
|
||||||
WhoAmI.get(function(user) {
|
Auth.refreshPermissions(function() {
|
||||||
Auth.user = user;
|
Auth.refreshPermissions(function() {
|
||||||
|
Notifications.success("Your changes have been saved to the realm.");
|
||||||
$location.url("/realms/" + realmCopy.realm);
|
$scope.$apply(function() {
|
||||||
Notifications.success("Your changes have been saved to the realm.");
|
$location.url("/realms/" + realmCopy.realm);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$location.url("/realms/" + realmCopy.realm);
|
$location.url("/realms/" + realmCopy.realm);
|
||||||
|
|
|
@ -184,10 +184,6 @@ module.factory('Notifications', function($rootScope, $timeout) {
|
||||||
return notifications;
|
return notifications;
|
||||||
});
|
});
|
||||||
|
|
||||||
module.factory('WhoAmI', function($resource) {
|
|
||||||
return $resource(consoleBaseUrl + '/whoami');
|
|
||||||
});
|
|
||||||
|
|
||||||
module.factory('Realm', function($resource) {
|
module.factory('Realm', function($resource) {
|
||||||
return $resource(authUrl + '/admin/realms/:id', {
|
return $resource(authUrl + '/admin/realms/:id', {
|
||||||
id : '@realm'
|
id : '@realm'
|
||||||
|
|
Loading…
Reference in a new issue