Search in sources :

Example 1 with ObjectIdentityRetrievalStrategy

use of org.springframework.security.acls.model.ObjectIdentityRetrievalStrategy 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.jupiter.api.Test)

Example 2 with ObjectIdentityRetrievalStrategy

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

the class AclPermissionCacheOptimizerTests method eagerlyLoadsRequiredAcls.

@Test
public void eagerlyLoadsRequiredAcls() {
    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") };
    given(oidStrat.getObjectIdentity(dos[0])).willReturn(oids[0]);
    given(oidStrat.getObjectIdentity(dos[2])).willReturn(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.jupiter.api.Test)

Example 3 with ObjectIdentityRetrievalStrategy

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

the class AclPermissionEvaluatorTests method hasPermissionReturnsTrueIfAclGrantsPermission.

@Test
public void hasPermissionReturnsTrueIfAclGrantsPermission() {
    AclService service = mock(AclService.class);
    AclPermissionEvaluator pe = new AclPermissionEvaluator(service);
    ObjectIdentity oid = mock(ObjectIdentity.class);
    ObjectIdentityRetrievalStrategy oidStrategy = mock(ObjectIdentityRetrievalStrategy.class);
    given(oidStrategy.getObjectIdentity(any(Object.class))).willReturn(oid);
    pe.setObjectIdentityRetrievalStrategy(oidStrategy);
    pe.setSidRetrievalStrategy(mock(SidRetrievalStrategy.class));
    Acl acl = mock(Acl.class);
    given(service.readAclById(any(ObjectIdentity.class), anyList())).willReturn(acl);
    given(acl.isGranted(anyList(), anyList(), eq(false))).willReturn(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) 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) Test(org.junit.jupiter.api.Test)

Example 4 with ObjectIdentityRetrievalStrategy

use of org.springframework.security.acls.model.ObjectIdentityRetrievalStrategy 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);
    given(oidStrategy.getObjectIdentity(any(Object.class))).willReturn(oid);
    pe.setObjectIdentityRetrievalStrategy(oidStrategy);
    pe.setSidRetrievalStrategy(mock(SidRetrievalStrategy.class));
    Acl acl = mock(Acl.class);
    given(service.readAclById(any(ObjectIdentity.class), anyList())).willReturn(acl);
    given(acl.isGranted(anyList(), anyList(), eq(false))).willReturn(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) 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) Test(org.junit.jupiter.api.Test)

Example 5 with ObjectIdentityRetrievalStrategy

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

the class ObjectIdentityRetrievalStrategyImplTests method testObjectIdentityCreation.

@Test
public void testObjectIdentityCreation() {
    MockIdDomainObject domain = new MockIdDomainObject();
    domain.setId(1);
    ObjectIdentityRetrievalStrategy retStrategy = new ObjectIdentityRetrievalStrategyImpl();
    ObjectIdentity identity = retStrategy.getObjectIdentity(domain);
    assertThat(identity).isNotNull();
    assertThat(new ObjectIdentityImpl(domain)).isEqualTo(identity);
}
Also used : ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) ObjectIdentityRetrievalStrategy(org.springframework.security.acls.model.ObjectIdentityRetrievalStrategy) Test(org.junit.jupiter.api.Test)

Aggregations

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