Search in sources :

Example 1 with AclService

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

the class AclPermissionCacheOptimizerTests method eagerlyLoadsRequiredAcls.

@Test
public void eagerlyLoadsRequiredAcls() throws Exception {
    AclService service = mock(AclService.class);
    AclPermissionCacheOptimizer pco = new AclPermissionCacheOptimizer(service);
    ObjectIdentityRetrievalStrategy oidStrat = mock(ObjectIdentityRetrievalStrategy.class);
    SidRetrievalStrategy sidStrat = mock(SidRetrievalStrategy.class);
    pco.setObjectIdentityRetrievalStrategy(oidStrat);
    pco.setSidRetrievalStrategy(sidStrat);
    Object[] dos = { new Object(), null, new Object() };
    ObjectIdentity[] oids = { new ObjectIdentityImpl("A", "1"), new ObjectIdentityImpl("A", "2") };
    when(oidStrat.getObjectIdentity(dos[0])).thenReturn(oids[0]);
    when(oidStrat.getObjectIdentity(dos[2])).thenReturn(oids[1]);
    pco.cachePermissionsFor(mock(Authentication.class), Arrays.asList(dos));
    // AclService should be invoked with the list of required Oids
    verify(service).readAclsById(eq(Arrays.asList(oids)), any(List.class));
}
Also used : ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) Authentication(org.springframework.security.core.Authentication) ObjectIdentityImpl(org.springframework.security.acls.domain.ObjectIdentityImpl) List(java.util.List) ObjectIdentityRetrievalStrategy(org.springframework.security.acls.model.ObjectIdentityRetrievalStrategy) AclService(org.springframework.security.acls.model.AclService) SidRetrievalStrategy(org.springframework.security.acls.model.SidRetrievalStrategy) Test(org.junit.Test)

Example 2 with AclService

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

the class AclPermissionCacheOptimizerTests method ignoresEmptyCollection.

@Test
public void ignoresEmptyCollection() {
    AclService service = mock(AclService.class);
    AclPermissionCacheOptimizer pco = new AclPermissionCacheOptimizer(service);
    ObjectIdentityRetrievalStrategy oids = mock(ObjectIdentityRetrievalStrategy.class);
    SidRetrievalStrategy sids = mock(SidRetrievalStrategy.class);
    pco.setObjectIdentityRetrievalStrategy(oids);
    pco.setSidRetrievalStrategy(sids);
    pco.cachePermissionsFor(mock(Authentication.class), Collections.emptyList());
    verifyZeroInteractions(service, sids, oids);
}
Also used : Authentication(org.springframework.security.core.Authentication) ObjectIdentityRetrievalStrategy(org.springframework.security.acls.model.ObjectIdentityRetrievalStrategy) AclService(org.springframework.security.acls.model.AclService) SidRetrievalStrategy(org.springframework.security.acls.model.SidRetrievalStrategy) Test(org.junit.Test)

Example 3 with AclService

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

the class AclPermissionEvaluatorTests method hasPermissionReturnsTrueIfAclGrantsPermission.

@Test
public void hasPermissionReturnsTrueIfAclGrantsPermission() throws Exception {
    AclService service = mock(AclService.class);
    AclPermissionEvaluator pe = new AclPermissionEvaluator(service);
    ObjectIdentity oid = mock(ObjectIdentity.class);
    ObjectIdentityRetrievalStrategy oidStrategy = mock(ObjectIdentityRetrievalStrategy.class);
    when(oidStrategy.getObjectIdentity(anyObject())).thenReturn(oid);
    pe.setObjectIdentityRetrievalStrategy(oidStrategy);
    pe.setSidRetrievalStrategy(mock(SidRetrievalStrategy.class));
    Acl acl = mock(Acl.class);
    when(service.readAclById(any(ObjectIdentity.class), anyListOf(Sid.class))).thenReturn(acl);
    when(acl.isGranted(anyListOf(Permission.class), anyListOf(Sid.class), eq(false))).thenReturn(true);
    assertThat(pe.hasPermission(mock(Authentication.class), new Object(), "READ")).isTrue();
}
Also used : ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) Authentication(org.springframework.security.core.Authentication) Permission(org.springframework.security.acls.model.Permission) ObjectIdentityRetrievalStrategy(org.springframework.security.acls.model.ObjectIdentityRetrievalStrategy) Acl(org.springframework.security.acls.model.Acl) AclService(org.springframework.security.acls.model.AclService) SidRetrievalStrategy(org.springframework.security.acls.model.SidRetrievalStrategy) Sid(org.springframework.security.acls.model.Sid) Test(org.junit.Test)

Example 4 with AclService

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

the class AclPermissionEvaluatorTests method resolvePermissionNonEnglishLocale.

@Test
public void resolvePermissionNonEnglishLocale() {
    Locale systemLocale = Locale.getDefault();
    Locale.setDefault(new Locale("tr"));
    AclService service = mock(AclService.class);
    AclPermissionEvaluator pe = new AclPermissionEvaluator(service);
    ObjectIdentity oid = mock(ObjectIdentity.class);
    ObjectIdentityRetrievalStrategy oidStrategy = mock(ObjectIdentityRetrievalStrategy.class);
    when(oidStrategy.getObjectIdentity(anyObject())).thenReturn(oid);
    pe.setObjectIdentityRetrievalStrategy(oidStrategy);
    pe.setSidRetrievalStrategy(mock(SidRetrievalStrategy.class));
    Acl acl = mock(Acl.class);
    when(service.readAclById(any(ObjectIdentity.class), anyListOf(Sid.class))).thenReturn(acl);
    when(acl.isGranted(anyListOf(Permission.class), anyListOf(Sid.class), eq(false))).thenReturn(true);
    assertThat(pe.hasPermission(mock(Authentication.class), new Object(), "write")).isTrue();
    Locale.setDefault(systemLocale);
}
Also used : Locale(java.util.Locale) ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) Authentication(org.springframework.security.core.Authentication) Permission(org.springframework.security.acls.model.Permission) ObjectIdentityRetrievalStrategy(org.springframework.security.acls.model.ObjectIdentityRetrievalStrategy) Acl(org.springframework.security.acls.model.Acl) AclService(org.springframework.security.acls.model.AclService) SidRetrievalStrategy(org.springframework.security.acls.model.SidRetrievalStrategy) Sid(org.springframework.security.acls.model.Sid) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 AclService (org.springframework.security.acls.model.AclService)4 ObjectIdentityRetrievalStrategy (org.springframework.security.acls.model.ObjectIdentityRetrievalStrategy)4 SidRetrievalStrategy (org.springframework.security.acls.model.SidRetrievalStrategy)4 Authentication (org.springframework.security.core.Authentication)4 ObjectIdentity (org.springframework.security.acls.model.ObjectIdentity)3 Acl (org.springframework.security.acls.model.Acl)2 Permission (org.springframework.security.acls.model.Permission)2 Sid (org.springframework.security.acls.model.Sid)2 List (java.util.List)1 Locale (java.util.Locale)1 ObjectIdentityImpl (org.springframework.security.acls.domain.ObjectIdentityImpl)1