Search in sources :

Example 1 with SidRetrievalStrategy

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

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

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

the class SidRetrievalStrategyTests method roleHierarchyIsUsedWhenSet.

@Test
public void roleHierarchyIsUsedWhenSet() {
    RoleHierarchy rh = mock(RoleHierarchy.class);
    List rhAuthorities = AuthorityUtils.createAuthorityList("D");
    given(rh.getReachableGrantedAuthorities(anyCollection())).willReturn(rhAuthorities);
    SidRetrievalStrategy strat = new SidRetrievalStrategyImpl(rh);
    List<Sid> sids = strat.getSids(this.authentication);
    assertThat(sids).hasSize(2);
    assertThat(sids.get(0)).isNotNull();
    assertThat(sids.get(0) instanceof PrincipalSid).isTrue();
    assertThat(((GrantedAuthoritySid) sids.get(1)).getGrantedAuthority()).isEqualTo("D");
}
Also used : SidRetrievalStrategyImpl(org.springframework.security.acls.domain.SidRetrievalStrategyImpl) GrantedAuthoritySid(org.springframework.security.acls.domain.GrantedAuthoritySid) RoleHierarchy(org.springframework.security.access.hierarchicalroles.RoleHierarchy) List(java.util.List) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) SidRetrievalStrategy(org.springframework.security.acls.model.SidRetrievalStrategy) Sid(org.springframework.security.acls.model.Sid) GrantedAuthoritySid(org.springframework.security.acls.domain.GrantedAuthoritySid) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Test(org.junit.jupiter.api.Test)

Example 4 with SidRetrievalStrategy

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

the class SidRetrievalStrategyTests method correctSidsAreRetrieved.

@Test
public void correctSidsAreRetrieved() {
    SidRetrievalStrategy retrStrategy = new SidRetrievalStrategyImpl();
    List<Sid> sids = retrStrategy.getSids(this.authentication);
    assertThat(sids).isNotNull();
    assertThat(sids).hasSize(4);
    assertThat(sids.get(0)).isNotNull();
    assertThat(sids.get(0) instanceof PrincipalSid).isTrue();
    for (int i = 1; i < sids.size(); i++) {
        assertThat(sids.get(i) instanceof GrantedAuthoritySid).isTrue();
    }
    assertThat(((PrincipalSid) sids.get(0)).getPrincipal()).isEqualTo("scott");
    assertThat(((GrantedAuthoritySid) sids.get(1)).getGrantedAuthority()).isEqualTo("A");
    assertThat(((GrantedAuthoritySid) sids.get(2)).getGrantedAuthority()).isEqualTo("B");
    assertThat(((GrantedAuthoritySid) sids.get(3)).getGrantedAuthority()).isEqualTo("C");
}
Also used : SidRetrievalStrategyImpl(org.springframework.security.acls.domain.SidRetrievalStrategyImpl) GrantedAuthoritySid(org.springframework.security.acls.domain.GrantedAuthoritySid) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) SidRetrievalStrategy(org.springframework.security.acls.model.SidRetrievalStrategy) Sid(org.springframework.security.acls.model.Sid) GrantedAuthoritySid(org.springframework.security.acls.domain.GrantedAuthoritySid) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)4 SidRetrievalStrategy (org.springframework.security.acls.model.SidRetrievalStrategy)4 List (java.util.List)2 GrantedAuthoritySid (org.springframework.security.acls.domain.GrantedAuthoritySid)2 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)2 SidRetrievalStrategyImpl (org.springframework.security.acls.domain.SidRetrievalStrategyImpl)2 AclService (org.springframework.security.acls.model.AclService)2 ObjectIdentityRetrievalStrategy (org.springframework.security.acls.model.ObjectIdentityRetrievalStrategy)2 Sid (org.springframework.security.acls.model.Sid)2 Authentication (org.springframework.security.core.Authentication)2 RoleHierarchy (org.springframework.security.access.hierarchicalroles.RoleHierarchy)1 ObjectIdentityImpl (org.springframework.security.acls.domain.ObjectIdentityImpl)1 ObjectIdentity (org.springframework.security.acls.model.ObjectIdentity)1