KEYCLOAK-5701

This commit is contained in:
Bill Burke 2017-10-18 18:20:50 -04:00
parent 0fb99a0098
commit 8faa6f1f4d
5 changed files with 54 additions and 22 deletions

View file

@ -22,6 +22,7 @@ import org.jboss.logging.Logger;
import org.keycloak.models.cache.infinispan.events.InvalidationEvent; import org.keycloak.models.cache.infinispan.events.InvalidationEvent;
import org.keycloak.models.cache.infinispan.entities.Revisioned; import org.keycloak.models.cache.infinispan.entities.Revisioned;
import org.keycloak.models.cache.infinispan.events.RealmCacheInvalidationEvent; import org.keycloak.models.cache.infinispan.events.RealmCacheInvalidationEvent;
import org.keycloak.models.cache.infinispan.stream.GroupListPredicate;
import org.keycloak.models.cache.infinispan.stream.HasRolePredicate; import org.keycloak.models.cache.infinispan.stream.HasRolePredicate;
import org.keycloak.models.cache.infinispan.stream.InClientPredicate; import org.keycloak.models.cache.infinispan.stream.InClientPredicate;
import org.keycloak.models.cache.infinispan.stream.InRealmPredicate; import org.keycloak.models.cache.infinispan.stream.InRealmPredicate;
@ -72,8 +73,7 @@ public class RealmCacheManager extends CacheManager {
} }
public void groupQueriesInvalidations(String realmId, Set<String> invalidations) { public void groupQueriesInvalidations(String realmId, Set<String> invalidations) {
invalidations.add(RealmCacheSession.getGroupsQueryCacheKey(realmId)); addInvalidations(GroupListPredicate.create().realm(realmId), invalidations);
invalidations.add(RealmCacheSession.getTopGroupsQueryCacheKey(realmId)); // Just easier to always invalidate top-level too. It's not big performance penalty
} }
public void clientAdded(String realmId, String clientUUID, String clientId, Set<String> invalidations) { public void clientAdded(String realmId, String clientUUID, String clientId, Set<String> invalidations) {

View file

@ -0,0 +1,36 @@
package org.keycloak.models.cache.infinispan.stream;
import org.keycloak.models.cache.infinispan.entities.GroupListQuery;
import org.keycloak.models.cache.infinispan.entities.Revisioned;
import java.io.Serializable;
import java.util.Map;
import java.util.function.Predicate;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public class GroupListPredicate implements Predicate<Map.Entry<String, Revisioned>>, Serializable {
private String realm;
public static GroupListPredicate create() {
return new GroupListPredicate();
}
public GroupListPredicate realm(String realm) {
this.realm = realm;
return this;
}
@Override
public boolean test(Map.Entry<String, Revisioned> entry) {
Object value = entry.getValue();
if (value == null) return false;
if (value instanceof GroupListQuery) {
GroupListQuery groupList = (GroupListQuery)value;
if (groupList.getRealm().equals(realm)) return true;
}
return false;
}
}

View file

@ -799,12 +799,6 @@ module.config([ '$routeProvider', function($routeProvider) {
resolve : { resolve : {
realm : function(RealmLoader) { realm : function(RealmLoader) {
return RealmLoader(); return RealmLoader();
},
groups : function(GroupListLoader) {
return GroupListLoader();
},
groupsCount : function(GroupCountLoader) {
return GroupCountLoader();
} }
}, },
controller : 'GroupListCtrl' controller : 'GroupListCtrl'

View file

@ -1,25 +1,28 @@
module.controller('GroupListCtrl', function($scope, $route, $q, realm, groups, groupsCount, Groups, GroupsCount, Group, GroupChildren, Notifications, $location, Dialog) { module.controller('GroupListCtrl', function($scope, $route, $q, realm, Groups, GroupsCount, Group, GroupChildren, Notifications, $location, Dialog) {
$scope.realm = realm; $scope.realm = realm;
$scope.groupList = [ $scope.groupList = [
{ {
"id" : "realm", "id" : "realm",
"name": "Groups", "name": "Groups",
"subGroups" : groups "subGroups" : []
} }
]; ];
$scope.searchTerms = ''; $scope.searchTerms = '';
$scope.currentPage = 1; $scope.currentPage = 1;
$scope.currentPageInput = $scope.currentPage; $scope.currentPageInput = $scope.currentPage;
$scope.pageSize = groups.length; $scope.pageSize = 20;
$scope.numberOfPages = Math.ceil(groupsCount.count/$scope.pageSize);
$scope.tree = []; $scope.tree = [];
var refreshGroups = function (search) { var refreshGroups = function (search) {
console.log('refreshGroups');
var first = ($scope.currentPage * $scope.pageSize) - $scope.pageSize;
console.log('first:' + first);
var queryParams = { var queryParams = {
realm : realm.id, realm : realm.id,
first : ($scope.currentPage * $scope.pageSize) - $scope.pageSize, first : first,
max : $scope.pageSize max : $scope.pageSize
}; };
var countParams = { var countParams = {
@ -38,8 +41,9 @@ module.controller('GroupListCtrl', function($scope, $route, $q, realm, groups, g
}, function() { }, function() {
promiseGetGroups.reject('Unable to fetch ' + queryParams); promiseGetGroups.reject('Unable to fetch ' + queryParams);
}); });
var promiseGetGroupsChain = promiseGetGroups.promise.then(function(entry) { var promiseGetGroupsChain = promiseGetGroups.promise.then(function(groups) {
groups = entry; console.log('*** group call groups size: ' + groups.length);
console.log('*** group call groups size: ' + groups.length);
$scope.groupList = [ $scope.groupList = [
{ {
"id" : "realm", "id" : "realm",
@ -55,11 +59,11 @@ module.controller('GroupListCtrl', function($scope, $route, $q, realm, groups, g
}, function() { }, function() {
promiseCount.reject('Unable to fetch ' + countParams); promiseCount.reject('Unable to fetch ' + countParams);
}); });
var promiseCountChain = promiseCount.promise.then(function(entry) { var promiseCountChain = promiseCount.promise.then(function(groupsCount) {
groupsCount = entry;
$scope.numberOfPages = Math.ceil(groupsCount.count/$scope.pageSize); $scope.numberOfPages = Math.ceil(groupsCount.count/$scope.pageSize);
}); });
}; };
refreshGroups();
$scope.$watch('currentPage', function(newValue, oldValue) { $scope.$watch('currentPage', function(newValue, oldValue) {
if(newValue !== oldValue) { if(newValue !== oldValue) {

View file

@ -490,9 +490,7 @@ module.factory('AuthenticationConfigLoader', function(Loader, AuthenticationConf
module.factory('GroupListLoader', function(Loader, Groups, $route, $q) { module.factory('GroupListLoader', function(Loader, Groups, $route, $q) {
return Loader.query(Groups, function() { return Loader.query(Groups, function() {
return { return {
realm : $route.current.params.realm, realm : $route.current.params.realm
first : 0,
max : 20
} }
}); });
}); });