Search in sources :

Example 1 with NotFoundException

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

the class ContactManagerBackend method addPermission.

public void addPermission(Contact contact, Sid recipient, Permission permission) {
    MutableAcl acl;
    ObjectIdentity oid = new ObjectIdentityImpl(Contact.class, contact.getId());
    try {
        acl = (MutableAcl) mutableAclService.readAclById(oid);
    } catch (NotFoundException nfe) {
        acl = mutableAclService.createAcl(oid);
    }
    acl.insertAce(acl.getEntries().size(), permission, recipient, true);
    mutableAclService.updateAcl(acl);
    logger.debug("Added permission " + permission + " for Sid " + recipient + " contact " + contact);
}
Also used : ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) ObjectIdentityImpl(org.springframework.security.acls.domain.ObjectIdentityImpl) NotFoundException(org.springframework.security.acls.model.NotFoundException) MutableAcl(org.springframework.security.acls.model.MutableAcl)

Example 2 with NotFoundException

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

the class BasicLookupStrategyTests method testReadAllObjectIdentitiesWhenLastElementIsAlreadyCached.

/**
	 * Test created from SEC-590.
	 */
@Test
public void testReadAllObjectIdentitiesWhenLastElementIsAlreadyCached() throws Exception {
    String query = "INSERT INTO acl_object_identity(ID,OBJECT_ID_CLASS,OBJECT_ID_IDENTITY,PARENT_OBJECT,OWNER_SID,ENTRIES_INHERITING) VALUES (4,2,104,null,1,1);" + "INSERT INTO acl_object_identity(ID,OBJECT_ID_CLASS,OBJECT_ID_IDENTITY,PARENT_OBJECT,OWNER_SID,ENTRIES_INHERITING) VALUES (5,2,105,4,1,1);" + "INSERT INTO acl_object_identity(ID,OBJECT_ID_CLASS,OBJECT_ID_IDENTITY,PARENT_OBJECT,OWNER_SID,ENTRIES_INHERITING) VALUES (6,2,106,4,1,1);" + "INSERT INTO acl_object_identity(ID,OBJECT_ID_CLASS,OBJECT_ID_IDENTITY,PARENT_OBJECT,OWNER_SID,ENTRIES_INHERITING) VALUES (7,2,107,5,1,1);" + "INSERT INTO acl_entry(ID,ACL_OBJECT_IDENTITY,ACE_ORDER,SID,MASK,GRANTING,AUDIT_SUCCESS,AUDIT_FAILURE) VALUES (5,4,0,1,1,1,0,0)";
    jdbcTemplate.execute(query);
    ObjectIdentity grandParentOid = new ObjectIdentityImpl(TARGET_CLASS, new Long(104));
    ObjectIdentity parent1Oid = new ObjectIdentityImpl(TARGET_CLASS, new Long(105));
    ObjectIdentity parent2Oid = new ObjectIdentityImpl(TARGET_CLASS, Integer.valueOf(106));
    ObjectIdentity childOid = new ObjectIdentityImpl(TARGET_CLASS, Integer.valueOf(107));
    // First lookup only child, thus populating the cache with grandParent,
    // parent1
    // and child
    List<Permission> checkPermission = Arrays.asList(BasePermission.READ);
    List<Sid> sids = Arrays.asList(BEN_SID);
    List<ObjectIdentity> childOids = Arrays.asList(childOid);
    strategy.setBatchSize(6);
    Map<ObjectIdentity, Acl> foundAcls = strategy.readAclsById(childOids, sids);
    Acl foundChildAcl = foundAcls.get(childOid);
    assertThat(foundChildAcl).isNotNull();
    assertThat(foundChildAcl.isGranted(checkPermission, sids, false)).isTrue();
    // Search for object identities has to be done in the following order:
    // last
    // element have to be one which
    // is already in cache and the element before it must not be stored in
    // cache
    List<ObjectIdentity> allOids = Arrays.asList(grandParentOid, parent1Oid, parent2Oid, childOid);
    try {
        foundAcls = strategy.readAclsById(allOids, sids);
    } catch (NotFoundException notExpected) {
        fail("It shouldn't have thrown NotFoundException");
    }
    Acl foundParent2Acl = foundAcls.get(parent2Oid);
    assertThat(foundParent2Acl).isNotNull();
    assertThat(foundParent2Acl.isGranted(checkPermission, sids, false)).isTrue();
}
Also used : ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) Permission(org.springframework.security.acls.model.Permission) NotFoundException(org.springframework.security.acls.model.NotFoundException) Acl(org.springframework.security.acls.model.Acl) MutableAcl(org.springframework.security.acls.model.MutableAcl) Sid(org.springframework.security.acls.model.Sid)

Example 3 with NotFoundException

use of org.springframework.security.acls.model.NotFoundException in project Gemma by PavlidisLab.

the class AclTestUtils method checkDeletedAcl.

/**
 * Make sure object f has no ACLs
 *
 * @param f f
 */
public void checkDeletedAcl(Object f) {
    try {
        Acl acl = this.getAcl(f);
        fail("Failed to  remove ACL for " + f + ", got " + acl);
    } catch (NotFoundException okaye) {
        // okay
        if (AclTestUtils.log.isDebugEnabled())
            AclTestUtils.log.debug("As expected, there was no acl for " + f.getClass().getSimpleName());
    }
}
Also used : NotFoundException(org.springframework.security.acls.model.NotFoundException) Acl(org.springframework.security.acls.model.Acl) MutableAcl(org.springframework.security.acls.model.MutableAcl)

Example 4 with NotFoundException

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

the class AclEntryVoter method vote.

@Override
public int vote(Authentication authentication, MethodInvocation object, Collection<ConfigAttribute> attributes) {
    for (ConfigAttribute attr : attributes) {
        if (!supports(attr)) {
            continue;
        }
        // Need to make an access decision on this invocation
        // Attempt to locate the domain object instance to process
        Object domainObject = getDomainObjectInstance(object);
        // If domain object is null, vote to abstain
        if (domainObject == null) {
            logger.debug("Voting to abstain - domainObject is null");
            return ACCESS_ABSTAIN;
        }
        // Evaluate if we are required to use an inner domain object
        if (StringUtils.hasText(this.internalMethod)) {
            domainObject = invokeInternalMethod(domainObject);
        }
        // Obtain the OID applicable to the domain object
        ObjectIdentity objectIdentity = this.objectIdentityRetrievalStrategy.getObjectIdentity(domainObject);
        // Obtain the SIDs applicable to the principal
        List<Sid> sids = this.sidRetrievalStrategy.getSids(authentication);
        Acl acl;
        try {
            // Lookup only ACLs for SIDs we're interested in
            acl = this.aclService.readAclById(objectIdentity, sids);
        } catch (NotFoundException ex) {
            logger.debug("Voting to deny access - no ACLs apply for this principal");
            return ACCESS_DENIED;
        }
        try {
            if (acl.isGranted(this.requirePermission, sids, false)) {
                logger.debug("Voting to grant access");
                return ACCESS_GRANTED;
            }
            logger.debug("Voting to deny access - ACLs returned, but insufficient permissions for this principal");
            return ACCESS_DENIED;
        } catch (NotFoundException ex) {
            logger.debug("Voting to deny access - no ACLs apply for this principal");
            return ACCESS_DENIED;
        }
    }
    // No configuration attribute matched, so abstain
    return ACCESS_ABSTAIN;
}
Also used : ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) ConfigAttribute(org.springframework.security.access.ConfigAttribute) NotFoundException(org.springframework.security.acls.model.NotFoundException) Acl(org.springframework.security.acls.model.Acl) Sid(org.springframework.security.acls.model.Sid)

Example 5 with NotFoundException

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

the class AclPermissionEvaluator method checkPermission.

private boolean checkPermission(Authentication authentication, ObjectIdentity oid, Object permission) {
    // Obtain the SIDs applicable to the principal
    List<Sid> sids = this.sidRetrievalStrategy.getSids(authentication);
    List<Permission> requiredPermission = resolvePermission(permission);
    this.logger.debug(LogMessage.of(() -> "Checking permission '" + permission + "' for object '" + oid + "'"));
    try {
        // Lookup only ACLs for SIDs we're interested in
        Acl acl = this.aclService.readAclById(oid, sids);
        if (acl.isGranted(requiredPermission, sids, false)) {
            this.logger.debug("Access is granted");
            return true;
        }
        this.logger.debug("Returning false - ACLs returned, but insufficient permissions for this principal");
    } catch (NotFoundException nfe) {
        this.logger.debug("Returning false - no ACLs apply for this principal");
    }
    return false;
}
Also used : Permission(org.springframework.security.acls.model.Permission) NotFoundException(org.springframework.security.acls.model.NotFoundException) Acl(org.springframework.security.acls.model.Acl) Sid(org.springframework.security.acls.model.Sid)

Aggregations

NotFoundException (org.springframework.security.acls.model.NotFoundException)13 Sid (org.springframework.security.acls.model.Sid)7 Acl (org.springframework.security.acls.model.Acl)6 ObjectIdentity (org.springframework.security.acls.model.ObjectIdentity)5 Permission (org.springframework.security.acls.model.Permission)5 MutableAcl (org.springframework.security.acls.model.MutableAcl)4 ObjectIdentityImpl (org.springframework.security.acls.domain.ObjectIdentityImpl)3 AclObjectIdentity (gemma.gsec.acl.domain.AclObjectIdentity)2 AccessControlEntry (org.springframework.security.acls.model.AccessControlEntry)2 List (java.util.List)1 Test (org.junit.jupiter.api.Test)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1 ConfigAttribute (org.springframework.security.access.ConfigAttribute)1 BasePermission (org.springframework.security.acls.domain.BasePermission)1 GrantedAuthoritySid (org.springframework.security.acls.domain.GrantedAuthoritySid)1 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)1 AclService (org.springframework.security.acls.model.AclService)1 ObjectIdentityRetrievalStrategy (org.springframework.security.acls.model.ObjectIdentityRetrievalStrategy)1 SidRetrievalStrategy (org.springframework.security.acls.model.SidRetrievalStrategy)1 SpringSecurityMessageSource (org.springframework.security.core.SpringSecurityMessageSource)1