Merge pull request #4574 from patriot1burke/master

KEYCLOAK-5701
This commit is contained in:
Bill Burke 2017-10-19 10:33:10 -04:00 committed by GitHub
commit 0371a562d9
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.entities.Revisioned;
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.InClientPredicate;
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) {
invalidations.add(RealmCacheSession.getGroupsQueryCacheKey(realmId));
invalidations.add(RealmCacheSession.getTopGroupsQueryCacheKey(realmId)); // Just easier to always invalidate top-level too. It's not big performance penalty
addInvalidations(GroupListPredicate.create().realm(realmId), 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 : {
realm : function(RealmLoader) {
return RealmLoader();
},
groups : function(GroupListLoader) {
return GroupListLoader();
},
groupsCount : function(GroupCountLoader) {
return GroupCountLoader();
}
},
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.groupList = [
{
"id" : "realm",
"name": "Groups",
"subGroups" : groups
"subGroups" : []
}
];
$scope.searchTerms = '';
$scope.currentPage = 1;
$scope.currentPageInput = $scope.currentPage;
$scope.pageSize = groups.length;
$scope.numberOfPages = Math.ceil(groupsCount.count/$scope.pageSize);
$scope.pageSize = 20;
$scope.tree = [];
var refreshGroups = function (search) {
console.log('refreshGroups');
var first = ($scope.currentPage * $scope.pageSize) - $scope.pageSize;
console.log('first:' + first);
var queryParams = {
realm : realm.id,
first : ($scope.currentPage * $scope.pageSize) - $scope.pageSize,
first : first,
max : $scope.pageSize
};
var countParams = {
@ -38,8 +41,9 @@ module.controller('GroupListCtrl', function($scope, $route, $q, realm, groups, g
}, function() {
promiseGetGroups.reject('Unable to fetch ' + queryParams);
});
var promiseGetGroupsChain = promiseGetGroups.promise.then(function(entry) {
groups = entry;
var promiseGetGroupsChain = promiseGetGroups.promise.then(function(groups) {
console.log('*** group call groups size: ' + groups.length);
console.log('*** group call groups size: ' + groups.length);
$scope.groupList = [
{
"id" : "realm",
@ -55,11 +59,11 @@ module.controller('GroupListCtrl', function($scope, $route, $q, realm, groups, g
}, function() {
promiseCount.reject('Unable to fetch ' + countParams);
});
var promiseCountChain = promiseCount.promise.then(function(entry) {
groupsCount = entry;
var promiseCountChain = promiseCount.promise.then(function(groupsCount) {
$scope.numberOfPages = Math.ceil(groupsCount.count/$scope.pageSize);
});
});
};
refreshGroups();
$scope.$watch('currentPage', function(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) {
return Loader.query(Groups, function() {
return {
realm : $route.current.params.realm,
first : 0,
max : 20
realm : $route.current.params.realm
}
});
});