Search in sources :

Example 46 with MutableAcl

use of org.springframework.security.acls.model.MutableAcl in project molgenis by molgenis.

the class RowLevelSecurityRepositoryDecoratorTest method testAddStream.

@WithMockUser(username = USERNAME)
@Test
public void testAddStream() {
    Entity entity = getEntityMock();
    MutableAcl acl = mock(MutableAcl.class);
    when(mutableAclService.createAcl(new EntityIdentity(entity))).thenReturn(acl);
    rowLevelSecurityRepositoryDecorator.add(Stream.of(entity));
    @SuppressWarnings("unchecked") ArgumentCaptor<Stream<Entity>> entityStreamCaptor = ArgumentCaptor.forClass(Stream.class);
    verify(delegateRepository).add(entityStreamCaptor.capture());
    assertEquals(entityStreamCaptor.getValue().collect(toList()), singletonList(entity));
    verify(acl).insertAce(0, new CumulativePermission().set(WRITE).set(READ).set(COUNT), new PrincipalSid(USERNAME), true);
}
Also used : EntityIdentity(org.molgenis.data.security.EntityIdentity) CumulativePermission(org.springframework.security.acls.domain.CumulativePermission) MutableAcl(org.springframework.security.acls.model.MutableAcl) Stream(java.util.stream.Stream) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 47 with MutableAcl

use of org.springframework.security.acls.model.MutableAcl in project molgenis by molgenis.

the class PermissionSystemServiceImplTest method giveUserEntityPermissions.

@Test
@WithMockUser(username = "user")
public void giveUserEntityPermissions() {
    String entityTypeId = "entityTypeId";
    EntityType entityType = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock();
    MutableAcl acl = mock(MutableAcl.class);
    when(mutableAclService.readAclById(new EntityTypeIdentity(entityTypeId))).thenReturn(acl);
    permissionSystemServiceImpl.giveUserWriteMetaPermissions(entityType);
    verify(mutableAclService).updateAcl(acl);
    verify(acl).insertAce(0, new CumulativePermission().set(EntityTypePermission.WRITEMETA).set(EntityTypePermission.WRITE).set(EntityTypePermission.READ).set(EntityTypePermission.COUNT), new PrincipalSid("user"), true);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) CumulativePermission(org.springframework.security.acls.domain.CumulativePermission) MutableAcl(org.springframework.security.acls.model.MutableAcl) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 48 with MutableAcl

use of org.springframework.security.acls.model.MutableAcl in project molgenis by molgenis.

the class PermissionSystemServiceImpl method giveUserWriteMetaPermissions.

@Override
public void giveUserWriteMetaPermissions(Collection<EntityType> entityTypes) {
    Sid sid = SidUtils.createSid(getCurrentUsername());
    runAsSystem(() -> {
        CumulativePermission permission = getCumulativePermission(EntityTypePermission.WRITEMETA);
        entityTypes.forEach(entityType -> {
            MutableAcl acl = (MutableAcl) mutableAclService.readAclById(new EntityTypeIdentity(entityType));
            acl.insertAce(acl.getEntries().size(), permission, sid, true);
            mutableAclService.updateAcl(acl);
        });
    });
}
Also used : EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) CumulativePermission(org.springframework.security.acls.domain.CumulativePermission) EntityTypePermissionUtils.getCumulativePermission(org.molgenis.data.security.EntityTypePermissionUtils.getCumulativePermission) MutableAcl(org.springframework.security.acls.model.MutableAcl) Sid(org.springframework.security.acls.model.Sid)

Example 49 with MutableAcl

use of org.springframework.security.acls.model.MutableAcl in project molgenis by molgenis.

the class RowLevelSecurityRepositoryDecorator method createAcl.

@Override
public void createAcl(Entity entity) {
    MutableAcl acl = mutableAclService.createAcl(new EntityIdentity(entity));
    Sid sid = new PrincipalSid(SecurityUtils.getCurrentUsername());
    acl.insertAce(acl.getEntries().size(), EntityPermissionUtils.getCumulativePermission(WRITE), sid, true);
    mutableAclService.updateAcl(acl);
}
Also used : EntityIdentity(org.molgenis.data.security.EntityIdentity) MutableAcl(org.springframework.security.acls.model.MutableAcl) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Sid(org.springframework.security.acls.model.Sid) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid)

Example 50 with MutableAcl

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

the class SpringCacheBasedAclCache method evictFromCache.

@Override
public void evictFromCache(ObjectIdentity objectIdentity) {
    Assert.notNull(objectIdentity, "ObjectIdentity required");
    MutableAcl acl = getFromCache(objectIdentity);
    if (acl != null) {
        this.cache.evict(acl.getId());
        this.cache.evict(acl.getObjectIdentity());
    }
}
Also used : MutableAcl(org.springframework.security.acls.model.MutableAcl)

Aggregations

MutableAcl (org.springframework.security.acls.model.MutableAcl)58 Test (org.junit.jupiter.api.Test)23 ObjectIdentity (org.springframework.security.acls.model.ObjectIdentity)20 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)17 Sid (org.springframework.security.acls.model.Sid)14 Authentication (org.springframework.security.core.Authentication)12 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)11 NotFoundException (org.springframework.security.acls.model.NotFoundException)10 ObjectIdentityImpl (org.springframework.security.acls.domain.ObjectIdentityImpl)9 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)8 Transactional (org.springframework.transaction.annotation.Transactional)8 Test (org.testng.annotations.Test)8 Test (org.junit.Test)7 PackageIdentity (org.molgenis.data.security.PackageIdentity)6 CumulativePermission (org.springframework.security.acls.domain.CumulativePermission)6 WithMockUser (org.springframework.security.test.context.support.WithMockUser)6 Package (org.molgenis.data.meta.model.Package)5 Acl (org.springframework.security.acls.model.Acl)5 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)5 File (java.io.File)4