Search in sources :

Example 1 with Acl

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

the class AdminPermissionController method displayAdminPage.

/**
	 * Displays the permission admin page for a particular contact.
	 */
@RequestMapping(value = "/secure/adminPermission.htm", method = RequestMethod.GET)
public ModelAndView displayAdminPage(@RequestParam("contactId") int contactId) {
    Contact contact = contactManager.getById(Long.valueOf(contactId));
    Acl acl = aclService.readAclById(new ObjectIdentityImpl(contact));
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("contact", contact);
    model.put("acl", acl);
    return new ModelAndView("adminPermission", "model", model);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ObjectIdentityImpl(org.springframework.security.acls.domain.ObjectIdentityImpl) ModelAndView(org.springframework.web.servlet.ModelAndView) Acl(org.springframework.security.acls.model.Acl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Acl

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

the class BasicLookupStrategyTests method testAclsRetrievalWithDefaultBatchSize.

@Test
public void testAclsRetrievalWithDefaultBatchSize() throws Exception {
    ObjectIdentity topParentOid = new ObjectIdentityImpl(TARGET_CLASS, new Long(100));
    ObjectIdentity middleParentOid = new ObjectIdentityImpl(TARGET_CLASS, new Long(101));
    // Deliberately use an integer for the child, to reproduce bug report in
    // SEC-819
    ObjectIdentity childOid = new ObjectIdentityImpl(TARGET_CLASS, Integer.valueOf(102));
    Map<ObjectIdentity, Acl> map = this.strategy.readAclsById(Arrays.asList(topParentOid, middleParentOid, childOid), null);
    checkEntries(topParentOid, middleParentOid, childOid, map);
}
Also used : ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) Acl(org.springframework.security.acls.model.Acl) MutableAcl(org.springframework.security.acls.model.MutableAcl)

Example 3 with Acl

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

the class BasicLookupStrategyTests method testAclsRetrievalFromCacheOnly.

@Test
public void testAclsRetrievalFromCacheOnly() throws Exception {
    ObjectIdentity topParentOid = new ObjectIdentityImpl(TARGET_CLASS, Integer.valueOf(100));
    ObjectIdentity middleParentOid = new ObjectIdentityImpl(TARGET_CLASS, new Long(101));
    ObjectIdentity childOid = new ObjectIdentityImpl(TARGET_CLASS, new Long(102));
    // Objects were put in cache
    strategy.readAclsById(Arrays.asList(topParentOid, middleParentOid, childOid), null);
    // Let's empty the database to force acls retrieval from cache
    emptyDatabase();
    Map<ObjectIdentity, Acl> map = this.strategy.readAclsById(Arrays.asList(topParentOid, middleParentOid, childOid), null);
    checkEntries(topParentOid, middleParentOid, childOid, map);
}
Also used : ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) Acl(org.springframework.security.acls.model.Acl) MutableAcl(org.springframework.security.acls.model.MutableAcl)

Example 4 with Acl

use of org.springframework.security.acls.model.Acl 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 5 with Acl

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

the class BasicLookupStrategyTests method testAllParentsAreRetrievedWhenChildIsLoaded.

@Test
public void testAllParentsAreRetrievedWhenChildIsLoaded() 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,103,1,1,1);";
    jdbcTemplate.execute(query);
    ObjectIdentity topParentOid = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(100));
    ObjectIdentity middleParentOid = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(101));
    ObjectIdentity childOid = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(102));
    ObjectIdentity middleParent2Oid = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(103));
    // Retrieve the child
    Map<ObjectIdentity, Acl> map = this.strategy.readAclsById(Arrays.asList(childOid), null);
    // Check that the child and all its parents were retrieved
    assertThat(map.get(childOid)).isNotNull();
    assertThat(map.get(childOid).getObjectIdentity()).isEqualTo(childOid);
    assertThat(map.get(middleParentOid)).isNotNull();
    assertThat(map.get(middleParentOid).getObjectIdentity()).isEqualTo(middleParentOid);
    assertThat(map.get(topParentOid)).isNotNull();
    assertThat(map.get(topParentOid).getObjectIdentity()).isEqualTo(topParentOid);
    // The second parent shouldn't have been retrieved
    assertThat(map.get(middleParent2Oid)).isNull();
}
Also used : ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) Acl(org.springframework.security.acls.model.Acl) MutableAcl(org.springframework.security.acls.model.MutableAcl)

Aggregations

Acl (org.springframework.security.acls.model.Acl)40 ObjectIdentity (org.springframework.security.acls.model.ObjectIdentity)26 MutableAcl (org.springframework.security.acls.model.MutableAcl)25 Test (org.junit.jupiter.api.Test)19 NotFoundException (org.springframework.security.acls.model.NotFoundException)11 ObjectIdentityImpl (org.springframework.security.acls.domain.ObjectIdentityImpl)9 Sid (org.springframework.security.acls.model.Sid)9 Authentication (org.springframework.security.core.Authentication)6 AclService (org.springframework.security.acls.model.AclService)5 ObjectIdentityRetrievalStrategy (org.springframework.security.acls.model.ObjectIdentityRetrievalStrategy)5 SidRetrievalStrategy (org.springframework.security.acls.model.SidRetrievalStrategy)5 HashMap (java.util.HashMap)4 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)4 Permission (org.springframework.security.acls.model.Permission)4 PackageIdentity (org.molgenis.data.security.PackageIdentity)3 AccessControlEntry (org.springframework.security.acls.model.AccessControlEntry)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AclImpl (org.springframework.security.acls.domain.AclImpl)2 BasePermission (org.springframework.security.acls.domain.BasePermission)2