try { Serializable id = null; myCache.evictFromCache(id); fail("It should have thrown IllegalArgumentException"); myCache.evictFromCache(obj); fail("It should have thrown IllegalArgumentException"); myCache.getFromCache(id); fail("It should have thrown IllegalArgumentException"); myCache.getFromCache(obj); fail("It should have thrown IllegalArgumentException"); myCache.putInCache(acl); fail("It should have thrown IllegalArgumentException");
public MutableAcl getFromCache(ObjectIdentity objectIdentity) { Assert.notNull(objectIdentity, "ObjectIdentity required"); Element element = null; try { element = cache.get(objectIdentity); } catch (CacheException ignored) { } if (element == null) { return null; } return initializeTransientFields((MutableAcl) element.getValue()); }
@Test public void clearCache() throws Exception { myCache.clearCache(); verify(cache).removeAll(); }
@Test public void getFromCacheSerializablePopulatesTransient() throws Exception { when(cache.get(acl.getId())).thenReturn(new Element(acl.getId(), acl)); myCache.putInCache(acl); ReflectionTestUtils.setField(acl, "permissionGrantingStrategy", null); ReflectionTestUtils.setField(acl, "aclAuthorizationStrategy", null); MutableAcl fromCache = myCache.getFromCache(acl.getId()); assertThat(ReflectionTestUtils.getField(fromCache, "aclAuthorizationStrategy")) .isNotNull(); assertThat(ReflectionTestUtils.getField(fromCache, "permissionGrantingStrategy")) .isNotNull(); }
public void evictFromCache(Serializable pk) { Assert.notNull(pk, "Primary key (identifier) required"); MutableAcl acl = getFromCache(pk); if (acl != null) { cache.remove(acl.getId()); cache.remove(acl.getObjectIdentity()); } }
@Test public void putInCache() throws Exception { myCache.putInCache(acl); verify(cache, times(2)).put(element.capture()); assertThat(element.getValue().getKey()).isEqualTo(acl.getId()); assertThat(element.getValue().getObjectValue()).isEqualTo(acl); assertThat(element.getAllValues().get(0).getKey()).isEqualTo( acl.getObjectIdentity()); assertThat(element.getAllValues().get(0).getObjectValue()).isEqualTo(acl); }
@Before public void setup() { myCache = new EhCacheBasedAclCache(cache, new DefaultPermissionGrantingStrategy( new ConsoleAuditLogger()), new AclAuthorizationStrategyImpl( new SimpleGrantedAuthority("ROLE_USER"))); ObjectIdentity identity = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(100)); AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl( new SimpleGrantedAuthority("ROLE_OWNERSHIP"), new SimpleGrantedAuthority( "ROLE_AUDITING"), new SimpleGrantedAuthority("ROLE_GENERAL")); acl = new AclImpl(identity, Long.valueOf(1), aclAuthorizationStrategy, new ConsoleAuditLogger()); }
@Test public void evictCacheObjectIdentity() throws Exception { when(cache.get(acl.getId())).thenReturn(new Element(acl.getId(), acl)); myCache.evictFromCache(acl.getId()); verify(cache).remove(acl.getId()); verify(cache).remove(acl.getObjectIdentity()); } }
@Test public void getFromCacheObjectIdentityPopulatesTransient() throws Exception { when(cache.get(acl.getObjectIdentity())) .thenReturn(new Element(acl.getId(), acl)); myCache.putInCache(acl); ReflectionTestUtils.setField(acl, "permissionGrantingStrategy", null); ReflectionTestUtils.setField(acl, "aclAuthorizationStrategy", null); MutableAcl fromCache = myCache.getFromCache(acl.getObjectIdentity()); assertThat(ReflectionTestUtils.getField(fromCache, "aclAuthorizationStrategy")) .isNotNull(); assertThat(ReflectionTestUtils.getField(fromCache, "permissionGrantingStrategy")) .isNotNull(); }
public void evictFromCache(ObjectIdentity objectIdentity) { Assert.notNull(objectIdentity, "ObjectIdentity required"); MutableAcl acl = getFromCache(objectIdentity); if (acl != null) { cache.remove(acl.getId()); cache.remove(acl.getObjectIdentity()); } }
public void putInCache(MutableAcl acl) { Assert.notNull(acl, "Acl required"); Assert.notNull(acl.getObjectIdentity(), "ObjectIdentity required"); Assert.notNull(acl.getId(), "ID required"); if (this.aclAuthorizationStrategy == null) { if (acl instanceof AclImpl) { this.aclAuthorizationStrategy = (AclAuthorizationStrategy) FieldUtils .getProtectedFieldValue("aclAuthorizationStrategy", acl); this.permissionGrantingStrategy = (PermissionGrantingStrategy) FieldUtils .getProtectedFieldValue("permissionGrantingStrategy", acl); } } if ((acl.getParentAcl() != null) && (acl.getParentAcl() instanceof MutableAcl)) { putInCache((MutableAcl) acl.getParentAcl()); } cache.put(new Element(acl.getObjectIdentity(), acl)); cache.put(new Element(acl.getId(), acl)); }
protected EhCacheBasedAclCache aclCache() { return new EhCacheBasedAclCache(getCache(), new DefaultPermissionGrantingStrategy(new ConsoleAuditLogger()), new AclAuthorizationStrategyImpl(new SimpleGrantedAuthority("ROLE_USER"))); }
@Test public void evictCacheSerializable() throws Exception { when(cache.get(acl.getObjectIdentity())) .thenReturn(new Element(acl.getId(), acl)); myCache.evictFromCache(acl.getObjectIdentity()); verify(cache).remove(acl.getId()); verify(cache).remove(acl.getObjectIdentity()); }
@Test public void getFromCacheSerializable() throws Exception { when(cache.get(acl.getId())).thenReturn(new Element(acl.getId(), acl)); assertThat(myCache.getFromCache(acl.getId())).isEqualTo(acl); }
@Test public void putInCacheAclWithParent() throws Exception { Authentication auth = new TestingAuthenticationToken("user", "password", "ROLE_GENERAL"); auth.setAuthenticated(true); SecurityContextHolder.getContext().setAuthentication(auth); ObjectIdentity identityParent = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(2)); AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl( new SimpleGrantedAuthority("ROLE_OWNERSHIP"), new SimpleGrantedAuthority( "ROLE_AUDITING"), new SimpleGrantedAuthority("ROLE_GENERAL")); MutableAcl parentAcl = new AclImpl(identityParent, Long.valueOf(2), aclAuthorizationStrategy, new ConsoleAuditLogger()); acl.setParent(parentAcl); myCache.putInCache(acl); verify(cache, times(4)).put(element.capture()); List<Element> allValues = element.getAllValues(); assertThat(allValues.get(0).getKey()).isEqualTo(parentAcl.getObjectIdentity()); assertThat(allValues.get(0).getObjectValue()).isEqualTo(parentAcl); assertThat(allValues.get(1).getKey()).isEqualTo(parentAcl.getId()); assertThat(allValues.get(1).getObjectValue()).isEqualTo(parentAcl); assertThat(allValues.get(2).getKey()).isEqualTo(acl.getObjectIdentity()); assertThat(allValues.get(2).getObjectValue()).isEqualTo(acl); assertThat(allValues.get(3).getKey()).isEqualTo(acl.getId()); assertThat(allValues.get(3).getObjectValue()).isEqualTo(acl); }
public MutableAcl getFromCache(Serializable pk) { Assert.notNull(pk, "Primary key (identifier) required"); Element element = null; try { element = cache.get(pk); } catch (CacheException ignored) { } if (element == null) { return null; } return initializeTransientFields((MutableAcl) element.getValue()); }
@Test(expected = IllegalArgumentException.class) public void constructorRejectsNullParameters() throws Exception { new EhCacheBasedAclCache(null, new DefaultPermissionGrantingStrategy( new ConsoleAuditLogger()), new AclAuthorizationStrategyImpl( new SimpleGrantedAuthority("ROLE_USER"))); }
@Test public void getFromCacheObjectIdentity() throws Exception { when(cache.get(acl.getId())).thenReturn(new Element(acl.getId(), acl)); assertThat(myCache.getFromCache(acl.getId())).isEqualTo(acl); }
public void putInCache(MutableAcl acl) { Assert.notNull(acl, "Acl required"); Assert.notNull(acl.getObjectIdentity(), "ObjectIdentity required"); Assert.notNull(acl.getId(), "ID required"); if (this.aclAuthorizationStrategy == null) { if (acl instanceof AclImpl) { this.aclAuthorizationStrategy = (AclAuthorizationStrategy) FieldUtils .getProtectedFieldValue("aclAuthorizationStrategy", acl); this.permissionGrantingStrategy = (PermissionGrantingStrategy) FieldUtils .getProtectedFieldValue("permissionGrantingStrategy", acl); } } if ((acl.getParentAcl() != null) && (acl.getParentAcl() instanceof MutableAcl)) { putInCache((MutableAcl) acl.getParentAcl()); } cache.put(new Element(acl.getObjectIdentity(), acl)); cache.put(new Element(acl.getId(), acl)); }
private MutableAcl initializeTransientFields(MutableAcl value) { if (value instanceof AclImpl) { FieldUtils.setProtectedFieldValue("aclAuthorizationStrategy", value, this.aclAuthorizationStrategy); FieldUtils.setProtectedFieldValue("permissionGrantingStrategy", value, this.permissionGrantingStrategy); } if (value.getParentAcl() != null) { initializeTransientFields((MutableAcl) value.getParentAcl()); } return value; }