Search in sources :

Example 1 with Sid

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

the class AdminPermissionController method deletePermission.

/**
	 * Deletes a permission
	 */
@RequestMapping(value = "/secure/deletePermission.htm")
public ModelAndView deletePermission(@RequestParam("contactId") int contactId, @RequestParam("sid") String sid, @RequestParam("permission") int mask) {
    Contact contact = contactManager.getById(new Long(contactId));
    Sid sidObject = new PrincipalSid(sid);
    Permission permission = permissionFactory.buildFromMask(mask);
    contactManager.deletePermission(contact, sidObject, permission);
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("contact", contact);
    model.put("sid", sidObject);
    model.put("permission", permission);
    return new ModelAndView("deletePermission", "model", model);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Permission(org.springframework.security.acls.model.Permission) BasePermission(org.springframework.security.acls.domain.BasePermission) ModelAndView(org.springframework.web.servlet.ModelAndView) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Sid(org.springframework.security.acls.model.Sid) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Sid

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

the class BasicLookupStrategyTests method testCreateGrantedAuthority.

@Test
public void testCreateGrantedAuthority() {
    Sid result = strategy.createSid(false, "sid");
    assertThat(result.getClass()).isEqualTo(GrantedAuthoritySid.class);
    assertThat(((GrantedAuthoritySid) result).getGrantedAuthority()).isEqualTo("sid");
}
Also used : Sid(org.springframework.security.acls.model.Sid)

Example 3 with Sid

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

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

the class AclAdviceTest method testArrayDesignAclsUser.

@Test
public void testArrayDesignAclsUser() {
    String userName = "testuser" + RandomStringUtils.randomAlphabetic(3);
    this.makeUser(userName);
    this.runAsUser(userName);
    ArrayDesign ad = this.getTestPersistentArrayDesign(2, true, false, false);
    aclTestUtils.checkHasAcl(ad);
    aclTestUtils.checkHasAces(ad);
    Sid owner = securityService.getOwner(ad);
    assertEquals(userName, ((AclPrincipalSid) owner).getPrincipal());
    arrayDesignService.update(ad);
    assertEquals(userName, ((AclPrincipalSid) owner).getPrincipal());
    arrayDesignService.remove(ad);
    aclTestUtils.checkDeletedAcl(ad);
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) AclPrincipalSid(gemma.gsec.acl.domain.AclPrincipalSid) Sid(org.springframework.security.acls.model.Sid) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest) Test(org.junit.Test)

Example 5 with Sid

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

the class AclAdviceTest method testArrayDesignAcls.

/*
     * Create Array design, check ACLs are put on correctly and removed when the design is removed. Array Designs are
     * _simple_ compared to EEs!
     */
@Test
public void testArrayDesignAcls() {
    // need to modify
    ArrayDesign ad = this.getTestPersistentArrayDesign(2, true, false, false);
    aclTestUtils.checkHasAcl(ad);
    aclTestUtils.checkHasAces(ad);
    Sid owner = securityService.getOwner(ad);
    assertEquals("administrator", ((AclPrincipalSid) owner).getPrincipal());
    arrayDesignService.remove(ad);
    aclTestUtils.checkDeletedAcl(ad);
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) AclPrincipalSid(gemma.gsec.acl.domain.AclPrincipalSid) Sid(org.springframework.security.acls.model.Sid) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest) Test(org.junit.Test)

Aggregations

Sid (org.springframework.security.acls.model.Sid)52 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)22 Test (org.junit.jupiter.api.Test)20 MutableAcl (org.springframework.security.acls.model.MutableAcl)16 GrantedAuthoritySid (org.springframework.security.acls.domain.GrantedAuthoritySid)15 ObjectIdentity (org.springframework.security.acls.model.ObjectIdentity)15 Permission (org.springframework.security.acls.model.Permission)13 NotFoundException (org.springframework.security.acls.model.NotFoundException)11 Acl (org.springframework.security.acls.model.Acl)9 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)6 AccessControlEntry (org.springframework.security.acls.model.AccessControlEntry)6 Authentication (org.springframework.security.core.Authentication)6 Test (org.testng.annotations.Test)6 AclPrincipalSid (gemma.gsec.acl.domain.AclPrincipalSid)5 EntityTypePermission (org.molgenis.data.security.EntityTypePermission)5 User (org.molgenis.data.security.auth.User)5 BasePermission (org.springframework.security.acls.domain.BasePermission)5 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)5 GrantedAuthority (org.springframework.security.core.GrantedAuthority)5 Test (org.junit.Test)4