public void cachePermissionsFor(Authentication authentication, Collection<?> objects) { if (objects.isEmpty()) { return; } List<ObjectIdentity> oidsToCache = new ArrayList<>(objects.size()); for (Object domainObject : objects) { if (domainObject == null) { continue; } ObjectIdentity oid = oidRetrievalStrategy.getObjectIdentity(domainObject); oidsToCache.add(oid); } List<Sid> sids = sidRetrievalStrategy.getSids(authentication); if (logger.isDebugEnabled()) { logger.debug("Eagerly loading Acls for " + oidsToCache.size() + " objects"); } aclService.readAclsById(oidsToCache, sids); }
@Test public void eagerlyLoadsRequiredAcls() throws Exception { AclService service = mock(AclService.class); AclPermissionCacheOptimizer pco = new AclPermissionCacheOptimizer(service); ObjectIdentityRetrievalStrategy oidStrat = mock(ObjectIdentityRetrievalStrategy.class); SidRetrievalStrategy sidStrat = mock(SidRetrievalStrategy.class); pco.setObjectIdentityRetrievalStrategy(oidStrat); pco.setSidRetrievalStrategy(sidStrat); Object[] dos = { new Object(), null, new Object() }; ObjectIdentity[] oids = { new ObjectIdentityImpl("A", "1"), new ObjectIdentityImpl("A", "2") }; when(oidStrat.getObjectIdentity(dos[0])).thenReturn(oids[0]); when(oidStrat.getObjectIdentity(dos[2])).thenReturn(oids[1]); pco.cachePermissionsFor(mock(Authentication.class), Arrays.asList(dos)); // AclService should be invoked with the list of required Oids verify(service).readAclsById(eq(Arrays.asList(oids)), any(List.class)); }
public void cachePermissionsFor(Authentication authentication, Collection<?> objects) { if (objects.isEmpty()) { return; } List<ObjectIdentity> oidsToCache = new ArrayList<>(objects.size()); for (Object domainObject : objects) { if (domainObject == null) { continue; } ObjectIdentity oid = oidRetrievalStrategy.getObjectIdentity(domainObject); oidsToCache.add(oid); } List<Sid> sids = sidRetrievalStrategy.getSids(authentication); if (logger.isDebugEnabled()) { logger.debug("Eagerly loading Acls for " + oidsToCache.size() + " objects"); } aclService.readAclsById(oidsToCache, sids); }