KEYCLOAK-482

Cannot read property 'realm' of undefined
This commit is contained in:
Stian Thorgersen 2014-05-23 09:35:20 +01:00
parent 07d2bf988a
commit 37327be521
4 changed files with 61 additions and 64 deletions

View file

@ -38,7 +38,7 @@
</style>
</head>
<body class="admin-console" data-ng-controller="GlobalCtrl" data-ng-cloak>
<body class="admin-console" data-ng-controller="GlobalCtrl" data-ng-cloak data-ng-show="auth.user">
<div id="idletimeout">
You will be logged off in <strong><span></span> seconds</strong> due to inactivity.

View file

@ -1,6 +1,5 @@
'use strict';
var indexUrl = window.location.href;
var consoleBaseUrl = window.location.href;
consoleBaseUrl = consoleBaseUrl.substring(0, consoleBaseUrl.indexOf("/console"));
consoleBaseUrl = consoleBaseUrl + "/console";
@ -23,14 +22,12 @@ var loadingTimer = -1;
angular.element(document).ready(function ($http) {
var keycloakAuth = new Keycloak(configUrl);
auth.loggedIn = false;
keycloakAuth.onAuthLogout = function() {
location.reload();
}
keycloakAuth.init({ onLoad: 'login-required' }).success(function () {
auth.loggedIn = true;
auth.authz = keycloakAuth;
module.factory('Auth', function() {
return auth;

View file

@ -7,69 +7,69 @@ module.controller('GlobalCtrl', function($scope, $http, Auth, WhoAmI, Current, $
$scope.logout = logout;
$scope.auth = Auth;
WhoAmI.get(function(data) {
Auth.user = data;
Auth.loggedIn = true;
function getAccess(role) {
if (!Current.realm) {
return false;
}
WhoAmI.get(function(user) {
Auth.user = user;
});
var realmAccess = Auth.user['realm_access'];
if (realmAccess) {
realmAccess = realmAccess[Current.realm.realm];
if (realmAccess) {
return realmAccess.indexOf(role) >= 0;
}
}
function getAccess(role) {
if (!Current.realm) {
return false;
}
$scope.access = {
createRealm: data.createRealm,
get viewRealm() {
return getAccess('view-realm') || this.manageRealm;
},
get viewApplications() {
return getAccess('view-applications') || this.manageApplications;
},
get viewClients() {
return getAccess('view-clients') || this.manageClients;
},
get viewUsers() {
return getAccess('view-users') || this.manageClients;
},
get viewAudit() {
return getAccess('view-audit') || this.manageClients;
},
get manageRealm() {
return getAccess('manage-realm');
},
get manageApplications() {
return getAccess('manage-applications');
},
get manageClients() {
return getAccess('manage-clients');
},
get manageUsers() {
return getAccess('manage-users');
},
get manageAudit() {
return getAccess('manage-audit');
var realmAccess = Auth.user && Auth.user['realm_access'];
if (realmAccess) {
realmAccess = realmAccess[Current.realm.realm];
if (realmAccess) {
return realmAccess.indexOf(role) >= 0;
}
}
});
return false;
}
$scope.access = {
createRealm: Auth.user && Auth.user.createRealm,
get viewRealm() {
return getAccess('view-realm') || this.manageRealm;
},
get viewApplications() {
return getAccess('view-applications') || this.manageApplications;
},
get viewClients() {
return getAccess('view-clients') || this.manageClients;
},
get viewUsers() {
return getAccess('view-users') || this.manageClients;
},
get viewAudit() {
return getAccess('view-audit') || this.manageClients;
},
get manageRealm() {
return getAccess('manage-realm');
},
get manageApplications() {
return getAccess('manage-applications');
},
get manageClients() {
return getAccess('manage-clients');
},
get manageUsers() {
return getAccess('manage-users');
},
get manageAudit() {
return getAccess('manage-audit');
}
}
$scope.$watch(function() {
return $location.path();
@ -114,7 +114,7 @@ module.controller('RealmDropdownCtrl', function($scope, Realm, Current, Auth, $l
$scope.showNav = function() {
var show = Current.realms.length > 0;
return Auth.loggedIn && show;
return Auth.user && show;
}
$scope.refresh = function() {
Current.refresh();

View file

@ -12,7 +12,7 @@
</div>
<div class="collapse navbar-collapse navbar-collapse-1">
<div class="container">
<ul class="nav navbar-nav navbar-utility" data-ng-show="auth.loggedIn">
<ul class="nav navbar-nav navbar-utility" data-ng-show="auth.user">
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
<span class="pficon pficon-user"></span>
@ -36,9 +36,9 @@
</li>
</ul>
</li>
<li class="active pull-right" data-ng-show="auth.loggedIn && access.createRealm">
<li class="active pull-right" data-ng-show="auth.user && access.createRealm">
<a class="button primary" href="#/create/realm" data-ng-class="path[0] == 'create' && path[1] == 'realm' && 'active'"
data-ng-show="auth.loggedIn">Add Realm</a>
data-ng-show="auth.user">Add Realm</a>
</li>
</ul>
</div>