Upgrade sonar plugin
[vid.git] / vid-app-common / src / main / java / org / openecomp / vid / roles / RoleValidator.java
1 package org.openecomp.vid.roles;
2
3 import org.openecomp.vid.mso.rest.RequestDetails;
4
5 import java.util.List;
6 import java.util.Map;
7
8 /**
9  * Created by Oren on 7/12/17.
10  */
11 public class RoleValidator {
12
13         //Disable roles until AAF integration finishes
14         private boolean disableRoles = true;
15     private List<Role> userRoles;
16
17     public RoleValidator(List<Role> roles) {
18         this.userRoles = roles;
19     }
20
21     public boolean isSubscriberPermitted(String subscriberName) {
22         if(this.disableRoles) return true;
23         
24         for (Role role : userRoles) {
25             if (role.getSubscribeName().equals(subscriberName))
26                 return true;
27         }
28         return false;
29     }
30
31     public boolean isServicePermitted(String subscriberName, String serviceType) {
32         if(this.disableRoles) return true;
33         
34         for (Role role : userRoles) {
35             if (role.getSubscribeName().equals(subscriberName) && role.getServiceType().equals(serviceType))
36                 return true;
37         }
38         return false;
39     }
40
41     public boolean isMsoRequestValid(RequestDetails mso_request) {
42         if(this.disableRoles) return true;
43         
44         try {
45             String globalSubscriberIdRequested = (String) ((Map) ((Map) mso_request.getAdditionalProperties().get("requestDetails")).get("subscriberInfo")).get("globalSubscriberId");
46             String serviceType = (String) ((Map) ((Map) mso_request.getAdditionalProperties().get("requestDetails")).get("requestParameters")).get("subscriptionServiceType");
47             return isServicePermitted(globalSubscriberIdRequested, serviceType);
48         } catch (Exception e) {
49             //Until we'll get the exact information regarding the tenants and the global customer id, we'll return true on unknown requests to mso
50             return true;
51         }
52 //        return false;
53     }
54
55     public boolean isTenantPermitted(String globalCustomerId, String serviceType, String tenant) {
56         if(this.disableRoles) return true;
57         
58         for (Role role : userRoles) {
59             if (role.getSubscribeName().equals(globalCustomerId)
60                     && role.getServiceType().equals(serviceType)
61                     && (role.getTenant() == null || role.getTenant().equals(tenant))) {
62                 return true;
63             }
64         }
65         return false;
66     }
67 }