Clover icon

sunshower-core

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

File MultitenantedHierarchicalPermissionEvaluator.java

 

Coverage histogram

../../../../img/srcFileCovDistChart1.png
59% of files have more coverage

Code metrics

6
13
4
1
43
36
7
0.54
3.25
4
1.75

Classes

Class Line # Actions
MultitenantedHierarchicalPermissionEvaluator 10 13 7
0.086956528.7%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package io.sunshower.service.security;
2   
3    import java.io.Serializable;
4    import java.util.Collection;
5    import org.springframework.security.acls.AclPermissionEvaluator;
6    import org.springframework.security.acls.model.AclService;
7    import org.springframework.security.core.Authentication;
8    import org.springframework.security.core.GrantedAuthority;
9   
 
10    public class MultitenantedHierarchicalPermissionEvaluator extends AclPermissionEvaluator {
11   
 
12  1 toggle public MultitenantedHierarchicalPermissionEvaluator(AclService aclService) {
13  1 super(aclService);
14    }
15   
 
16  0 toggle @Override
17    public boolean hasPermission(
18    Authentication authentication, Object domainObject, Object permission) {
19   
20  0 if (isAdmin(authentication)) return true;
21  0 return super.hasPermission(authentication, domainObject, permission);
22    }
23   
 
24  0 toggle @Override
25    public boolean hasPermission(
26    Authentication authentication, Serializable targetId, String targetType, Object permission) {
27  0 if (isAdmin(authentication)) {
28  0 return true;
29    }
30  0 return super.hasPermission(authentication, targetId, targetType, permission);
31    }
32   
 
33  0 toggle private boolean isAdmin(Authentication authentication) {
34  0 final String role = DefaultRoles.SITE_ADMINISTRATOR.authority();
35  0 Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
36  0 for (GrantedAuthority authority : authorities) {
37  0 if (role.equals(authority.getAuthority())) {
38  0 return true;
39    }
40    }
41  0 return false;
42    }
43    }