Clover icon

sunshower-core

  1. Project Clover database Fri Apr 6 2018 03:27:42 UTC
  2. Package io.sunshower.service.security

File CachingRoleHierarchy.java

 

Coverage histogram

../../../../img/srcFileCovDistChart8.png
14% of files have more coverage

Code metrics

8
7
3
1
42
34
7
1
2.33
3
2.33

Classes

Class Line # Actions
CachingRoleHierarchy 13 7 7
0.777777877.8%
 

Contributing tests

This file is covered by 19 tests. .

Source view

1    package io.sunshower.service.security;
2   
3    import io.sunshower.model.core.auth.Role;
4    import java.util.Collection;
5    import java.util.Collections;
6    import java.util.Set;
7    import java.util.stream.Collectors;
8    import java.util.stream.Stream;
9    import org.springframework.security.access.hierarchicalroles.RoleHierarchy;
10    import org.springframework.security.core.GrantedAuthority;
11   
12    /** Created by haswell on 5/9/17. */
 
13    public class CachingRoleHierarchy implements RoleHierarchy {
14   
 
15  33 toggle @Override
16    public Collection<? extends GrantedAuthority> getReachableGrantedAuthorities(
17    Collection<? extends GrantedAuthority> authorities) {
18   
19  33 return authorities == null
20    ? Collections.emptyList()
21    : authorities.stream().flatMap(CachingRoleHierarchy::collect).collect(Collectors.toList());
22    }
23   
 
24  34 toggle static Stream<? extends GrantedAuthority> collect(GrantedAuthority authority) {
25  34 if (authority == null) {
26  0 return Stream.empty();
27    }
28  34 if (authority instanceof Role) {
29  8 return Stream.concat(
30    Stream.of(authority),
31    children(((Role) authority).getChildren())
32    .stream()
33    .flatMap(CachingRoleHierarchy::collect));
34    }
35   
36  26 return Stream.of(authority);
37    }
38   
 
39  8 toggle private static Collection<Role> children(Set<Role> children) {
40  8 return children == null ? Collections.emptySet() : children;
41    }
42    }