Search in sources :

Example 11 with MutableAcl

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

the class EhCacheBasedAclCache method evictFromCache.

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

Example 12 with MutableAcl

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

the class SpringCacheBasedAclCache method evictFromCache.

// ~ Methods
// ========================================================================================================
public void evictFromCache(Serializable pk) {
    Assert.notNull(pk, "Primary key (identifier) required");
    MutableAcl acl = getFromCache(pk);
    if (acl != null) {
        cache.evict(acl.getId());
        cache.evict(acl.getObjectIdentity());
    }
}
Also used : MutableAcl(org.springframework.security.acls.model.MutableAcl)

Example 13 with MutableAcl

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

the class JdbcMutableAclService method createAcl.

// ~ Methods
// ========================================================================================================
public MutableAcl createAcl(ObjectIdentity objectIdentity) throws AlreadyExistsException {
    Assert.notNull(objectIdentity, "Object Identity required");
    // Check this object identity hasn't already been persisted
    if (retrieveObjectIdentityPrimaryKey(objectIdentity) != null) {
        throw new AlreadyExistsException("Object identity '" + objectIdentity + "' already exists");
    }
    // Need to retrieve the current principal, in order to know who "owns" this ACL
    // (can be changed later on)
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    PrincipalSid sid = new PrincipalSid(auth);
    // Create the acl_object_identity row
    createObjectIdentity(objectIdentity, sid);
    // Retrieve the ACL via superclass (ensures cache registration, proper retrieval
    // etc)
    Acl acl = readAclById(objectIdentity);
    Assert.isInstanceOf(MutableAcl.class, acl, "MutableAcl should be been returned");
    return (MutableAcl) acl;
}
Also used : AlreadyExistsException(org.springframework.security.acls.model.AlreadyExistsException) Authentication(org.springframework.security.core.Authentication) MutableAcl(org.springframework.security.acls.model.MutableAcl) Acl(org.springframework.security.acls.model.Acl) MutableAcl(org.springframework.security.acls.model.MutableAcl) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid)

Example 14 with MutableAcl

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

the class JdbcMutableAclServiceTests method deleteAclWithChildrenThrowsException.

@Test
@Transactional
public void deleteAclWithChildrenThrowsException() throws Exception {
    SecurityContextHolder.getContext().setAuthentication(auth);
    MutableAcl parent = jdbcMutableAclService.createAcl(topParentOid);
    MutableAcl child = jdbcMutableAclService.createAcl(middleParentOid);
    // Specify the inheritance hierarchy
    child.setParent(parent);
    jdbcMutableAclService.updateAcl(child);
    try {
        // switch on FK
        jdbcMutableAclService.setForeignKeysInDatabase(false);
        // checking in the
        // class, not database
        jdbcMutableAclService.deleteAcl(topParentOid, false);
        fail("It should have thrown ChildrenExistException");
    } catch (ChildrenExistException expected) {
    } finally {
        // restore to the
        jdbcMutableAclService.setForeignKeysInDatabase(true);
    // default
    }
}
Also used : ChildrenExistException(org.springframework.security.acls.model.ChildrenExistException) MutableAcl(org.springframework.security.acls.model.MutableAcl) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with MutableAcl

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

the class JdbcMutableAclServiceTests method deleteAclAlsoDeletesChildren.

/**
	 * Test method that demonstrates eviction failure from cache - SEC-676
	 */
@Test
@Transactional
public void deleteAclAlsoDeletesChildren() throws Exception {
    SecurityContextHolder.getContext().setAuthentication(auth);
    jdbcMutableAclService.createAcl(topParentOid);
    MutableAcl middleParent = jdbcMutableAclService.createAcl(middleParentOid);
    MutableAcl child = jdbcMutableAclService.createAcl(childOid);
    child.setParent(middleParent);
    jdbcMutableAclService.updateAcl(middleParent);
    jdbcMutableAclService.updateAcl(child);
    // Check the childOid really is a child of middleParentOid
    Acl childAcl = jdbcMutableAclService.readAclById(childOid);
    assertThat(childAcl.getParentAcl().getObjectIdentity()).isEqualTo(middleParentOid);
    // Delete the mid-parent and test if the child was deleted, as well
    jdbcMutableAclService.deleteAcl(middleParentOid, true);
    try {
        jdbcMutableAclService.readAclById(middleParentOid);
        fail("It should have thrown NotFoundException");
    } catch (NotFoundException expected) {
    }
    try {
        jdbcMutableAclService.readAclById(childOid);
        fail("It should have thrown NotFoundException");
    } catch (NotFoundException expected) {
    }
    Acl acl = jdbcMutableAclService.readAclById(topParentOid);
    assertThat(acl).isNotNull();
    assertThat(topParentOid).isEqualTo(((MutableAcl) acl).getObjectIdentity());
}
Also used : NotFoundException(org.springframework.security.acls.model.NotFoundException) MutableAcl(org.springframework.security.acls.model.MutableAcl) MutableAcl(org.springframework.security.acls.model.MutableAcl) Acl(org.springframework.security.acls.model.Acl) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

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