##### Coverage Report - com.ctrip.framework.apollo.portal.auth.PermissionValidator

Classes in this File | Line Coverage | Branch Coverage | Complexity
PermissionValidator |
12% | 1/8
N/A | N/A
| 1.0;1

1 |  |
     package com.ctrip.framework.apollo.portal.auth;
2 |  |
3 |  |
     import com.ctrip.framework.apollo.portal.constant.PermissionType;
4 |  |
     import com.ctrip.framework.apollo.portal.service.RolePermissionService;
5 |  |
     import com.ctrip.framework.apollo.portal.util.RoleUtils;
6 |  |
7 |  |
     import org.springframework.beans.factory.annotation.Autowired;
8 |  |
     import org.springframework.stereotype.Component;
9 |  |
10 |  |
     @Component("permissionValidator")
11 | 1 |
     public class PermissionValidator {
12 |  |
13 |  |
       @Autowired
14 |  |
       private UserInfoHolder userInfoHolder;
15 |  |
       @Autowired
16 |  |
       private RolePermissionService rolePermissionService;
17 |  |
18 |  |
       public boolean hasModifyNamespacePermission(String appId, String namespaceName){
19 | 0 |
         return rolePermissionService.userHasPermission(userInfoHolder.getUser().getUserId(),
20 |  |
                                                 PermissionType.MODIFY_NAMESPACE,
21 | 0 |
                                                 RoleUtils.buildNamespaceTargetId(appId, namespaceName));
22 |  |
23 |  |
       }
24 |  |
25 |  |
       public boolean hasReleaseNamespacePermission(String appId, String namespaceName){
26 | 0 |
         return rolePermissionService.userHasPermission(userInfoHolder.getUser().getUserId(),
27 |  |
                                                        PermissionType.RELEASE_NAMESPACE,
28 | 0 |
                                                        RoleUtils.buildNamespaceTargetId(appId, namespaceName));
29 |  |
30 |  |
       }
31 |  |
32 |  |
       public boolean hasAssignRolePermission(String appId){
33 | 0 |
         return rolePermissionService.userHasPermission(userInfoHolder.getUser().getUserId(),
34 |  |
                                                        PermissionType.ASSIGN_ROLE,
35 |  |
                                                        appId);
36 |  |
       }
37 |  |
38 |  |
       public boolean hasCreateNamespacePermission(String appId){
39 | 0 |
         return rolePermissionService.userHasPermission(userInfoHolder.getUser().getUserId(),
40 |  |
                                                        PermissionType.CREATE_NAMESPACE,
41 |  |
                                                        appId);
42 |  |
       }
43 |  |
44 |  |
45 |  |
       public boolean hasCreateClusterPermission(String appId){
46 | 0 |
         return rolePermissionService.userHasPermission(userInfoHolder.getUser().getUserId(),
47 |  |
                                                        PermissionType.CREATE_CLUSTER,
48 |  |
                                                        appId);
49 |  |
       }
50 |  |
     }