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 () {
|
||||
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() {
|
||||
location.reload();
|
||||
}
|
||||
|
||||
keycloakAuth.init({ onLoad: 'login-required' }).success(function () {
|
||||
auth.authz = keycloakAuth;
|
||||
|
||||
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();
|
||||
});
|
||||
}).error(function () {
|
||||
window.location.reload();
|
||||
});
|
||||
|
|
|
@ -1,31 +1,9 @@
|
|||
module.controller('GlobalCtrl', function($scope, $http, Auth, WhoAmI, Current, $location, Notifications, ServerInfo) {
|
||||
$scope.addMessage = function() {
|
||||
Notifications.success("test");
|
||||
};
|
||||
|
||||
module.controller('GlobalCtrl', function($scope, $http, Auth, Current, $location, Notifications, ServerInfo) {
|
||||
$scope.authUrl = authUrl;
|
||||
$scope.resourceUrl = resourceUrl;
|
||||
$scope.auth = Auth;
|
||||
$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) {
|
||||
if (!Current.realm) {
|
||||
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');
|
||||
|
||||
Current.realm = null;
|
||||
|
@ -193,22 +171,17 @@ module.controller('RealmCreateCtrl', function($scope, Current, Realm, $upload, $
|
|||
}, true);
|
||||
|
||||
$scope.$watch('realm.realm', function() {
|
||||
if (create) {
|
||||
$scope.realm.id = $scope.realm.realm;
|
||||
}
|
||||
}, true);
|
||||
|
||||
$scope.save = function() {
|
||||
var realmCopy = angular.copy($scope.realm);
|
||||
Realm.create(realmCopy, function() {
|
||||
Realm.query(function(data) {
|
||||
Current.realms = data;
|
||||
|
||||
WhoAmI.get(function(user) {
|
||||
Auth.user = user;
|
||||
|
||||
$location.url("/realms/" + realmCopy.realm);
|
||||
Notifications.success("The realm has been created.");
|
||||
|
||||
Auth.refreshPermissions(function() {
|
||||
$scope.$apply(function() {
|
||||
$location.url("/realms/" + realmCopy.realm);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -227,7 +200,7 @@ module.controller('ObjectModalCtrl', function($scope, 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.serverInfo = serverInfo;
|
||||
|
||||
|
@ -272,11 +245,13 @@ module.controller('RealmDetailCtrl', function($scope, Current, Realm, realm, ser
|
|||
});
|
||||
|
||||
if (nameChanged) {
|
||||
WhoAmI.get(function(user) {
|
||||
Auth.user = user;
|
||||
|
||||
$location.url("/realms/" + realmCopy.realm);
|
||||
Auth.refreshPermissions(function() {
|
||||
Auth.refreshPermissions(function() {
|
||||
Notifications.success("Your changes have been saved to the realm.");
|
||||
$scope.$apply(function() {
|
||||
$location.url("/realms/" + realmCopy.realm);
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
$location.url("/realms/" + realmCopy.realm);
|
||||
|
|
|
@ -184,10 +184,6 @@ module.factory('Notifications', function($rootScope, $timeout) {
|
|||
return notifications;
|
||||
});
|
||||
|
||||
module.factory('WhoAmI', function($resource) {
|
||||
return $resource(consoleBaseUrl + '/whoami');
|
||||
});
|
||||
|
||||
module.factory('Realm', function($resource) {
|
||||
return $resource(authUrl + '/admin/realms/:id', {
|
||||
id : '@realm'
|
||||
|
|
Loading…
Reference in a new issue