Search in sources :

Example 6 with MutableAcl

use of org.springframework.security.acls.model.MutableAcl in project spring-security by spring-projects.

the class EhCacheBasedAclCacheTests method getFromCacheObjectIdentityPopulatesTransient.

@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();
}
Also used : Element(net.sf.ehcache.Element) MutableAcl(org.springframework.security.acls.model.MutableAcl) Test(org.junit.Test)

Example 7 with MutableAcl

use of org.springframework.security.acls.model.MutableAcl in project spring-security by spring-projects.

the class EhCacheBasedAclCacheTests method methodsRejectNullParameters.

@Test
public void methodsRejectNullParameters() throws Exception {
    try {
        Serializable id = null;
        myCache.evictFromCache(id);
        fail("It should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
    try {
        ObjectIdentity obj = null;
        myCache.evictFromCache(obj);
        fail("It should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
    try {
        Serializable id = null;
        myCache.getFromCache(id);
        fail("It should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
    try {
        ObjectIdentity obj = null;
        myCache.getFromCache(obj);
        fail("It should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
    try {
        MutableAcl acl = null;
        myCache.putInCache(acl);
        fail("It should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
}
Also used : Serializable(java.io.Serializable) ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) MutableAcl(org.springframework.security.acls.model.MutableAcl) Test(org.junit.Test)

Example 8 with MutableAcl

use of org.springframework.security.acls.model.MutableAcl in project spring-security by spring-projects.

the class JdbcMutableAclServiceTests method deleteAclRemovesRowsFromDatabase.

@Test
@Transactional
public void deleteAclRemovesRowsFromDatabase() throws Exception {
    SecurityContextHolder.getContext().setAuthentication(auth);
    MutableAcl child = jdbcMutableAclService.createAcl(childOid);
    child.insertAce(0, BasePermission.DELETE, new PrincipalSid(auth), false);
    jdbcMutableAclService.updateAcl(child);
    // Remove the child and check all related database rows were removed accordingly
    jdbcMutableAclService.deleteAcl(childOid, false);
    assertThat(jdbcTemplate.queryForList(SELECT_ALL_CLASSES, new Object[] { TARGET_CLASS })).hasSize(1);
    assertThat(jdbcTemplate.queryForList("select * from acl_object_identity")).isEmpty();
    assertThat(jdbcTemplate.queryForList("select * from acl_entry")).isEmpty();
    // Check the cache
    assertThat(aclCache.getFromCache(childOid)).isNull();
    assertThat(aclCache.getFromCache(Long.valueOf(102))).isNull();
}
Also used : MutableAcl(org.springframework.security.acls.model.MutableAcl) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with MutableAcl

use of org.springframework.security.acls.model.MutableAcl in project spring-security by spring-projects.

the class EhCacheBasedAclCache method evictFromCache.

// ~ Methods
// ========================================================================================================
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());
    }
}
Also used : MutableAcl(org.springframework.security.acls.model.MutableAcl)

Example 10 with MutableAcl

use of org.springframework.security.acls.model.MutableAcl in project spring-security by spring-projects.

the class EhCacheBasedAclCache method putInCache.

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));
}
Also used : Element(net.sf.ehcache.Element) MutableAcl(org.springframework.security.acls.model.MutableAcl)

Aggregations

MutableAcl (org.springframework.security.acls.model.MutableAcl)27 Test (org.junit.Test)14 ObjectIdentity (org.springframework.security.acls.model.ObjectIdentity)13 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)8 Authentication (org.springframework.security.core.Authentication)8 ObjectIdentityImpl (org.springframework.security.acls.domain.ObjectIdentityImpl)7 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)7 Transactional (org.springframework.transaction.annotation.Transactional)7 NotFoundException (org.springframework.security.acls.model.NotFoundException)6 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)5 Element (net.sf.ehcache.Element)4 GrantedAuthoritySid (org.springframework.security.acls.domain.GrantedAuthoritySid)4 BasePermission (org.springframework.security.acls.domain.BasePermission)3 Acl (org.springframework.security.acls.model.Acl)3 Permission (org.springframework.security.acls.model.Permission)3 Sid (org.springframework.security.acls.model.Sid)3 Map (java.util.Map)2 Cache (org.springframework.cache.Cache)2 CumulativePermission (org.springframework.security.acls.domain.CumulativePermission)2 AccessControlEntry (org.springframework.security.acls.model.AccessControlEntry)2