2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.vid.roles;
23 import java.util.List;
25 import org.onap.portalsdk.core.util.SystemProperties;
26 import org.onap.vid.mso.rest.RequestDetails;
29 * Created by Oren on 7/12/17.
31 public class RoleValidator {
33 private boolean disableRoles;
34 private final List<Role> userRoles;
36 public RoleValidator(List<Role> roles) {
37 this.userRoles = roles;
38 disableRoles = SystemProperties.getProperty("role_management_activated").equals("false");
41 public boolean isSubscriberPermitted(String subscriberName) {
42 if (this.disableRoles) {
46 for (Role role : userRoles) {
47 if (role.getSubscribeName().equals(subscriberName)) {
54 public boolean isServicePermitted(String subscriberName, String serviceType) {
55 if (this.disableRoles) {
59 for (Role role : userRoles) {
60 if (role.getSubscribeName().equals(subscriberName) && role.getServiceType().equals(serviceType)) {
67 boolean isMsoRequestValid(RequestDetails msoRequest) {
68 if (this.disableRoles) {
73 String globalSubscriberIdRequested = (String) ((Map) ((Map) msoRequest.getAdditionalProperties()
74 .get("requestDetails")).get("subscriberInfo")).get("globalSubscriberId");
75 String serviceType = (String) ((Map) ((Map) msoRequest.getAdditionalProperties().get("requestDetails"))
76 .get("requestParameters")).get("subscriptionServiceType");
77 return isServicePermitted(globalSubscriberIdRequested, serviceType);
78 } catch (Exception e) {
79 //Until we'll get the exact information regarding the tenants and the global customer id, we'll return true on unknown requests to mso
84 public boolean isTenantPermitted(String globalCustomerId, String serviceType, String tenantName) {
85 if (this.disableRoles) {
89 for (Role role : userRoles) {
90 if (role.getSubscribeName().equals(globalCustomerId)
91 && role.getServiceType().equals(serviceType)
92 && (role.getTenant() == null || role.getTenant().equalsIgnoreCase(tenantName))) {
100 this.disableRoles = false;