From 80705cdf2dc38d48c4261a2ece3914234960233e Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Wed, 3 Apr 2019 12:00:57 +0300 Subject: Extract AlwaysValidRoleValidator from RoleValidator Issue-ID: VID-448 Change-Id: Ic006aceca9c51305d0706df6c2c6062ccaaee3de Signed-off-by: Ittay Stern --- .../java/org/onap/vid/roles/RoleValidator.java | 82 ++++------------------ 1 file changed, 12 insertions(+), 70 deletions(-) (limited to 'vid-app-common/src/main/java/org/onap/vid/roles/RoleValidator.java') diff --git a/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidator.java b/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidator.java index 4b92b6413..d37477610 100644 --- a/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidator.java +++ b/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidator.java @@ -3,6 +3,7 @@ * VID * ================================================================================ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2018 - 2019 Nokia. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,82 +22,23 @@ package org.onap.vid.roles; import java.util.List; -import java.util.Map; +import org.apache.commons.lang3.StringUtils; import org.onap.portalsdk.core.util.SystemProperties; -import org.onap.vid.mso.rest.RequestDetails; -/** - * Created by Oren on 7/12/17. - */ -public class RoleValidator { - - private boolean disableRoles; - private final List userRoles; - - public RoleValidator(List roles) { - this.userRoles = roles; - disableRoles = SystemProperties.getProperty("role_management_activated").equals("false"); - } - - public boolean isSubscriberPermitted(String subscriberName) { - if (this.disableRoles) { - return true; - } - - for (Role role : userRoles) { - if (role.getSubscribeName().equals(subscriberName)) { - return true; - } - } - return false; - } - - public boolean isServicePermitted(String subscriberName, String serviceType) { - if (this.disableRoles) { - return true; - } - - for (Role role : userRoles) { - if (role.getSubscribeName().equals(subscriberName) && role.getServiceType().equals(serviceType)) { - return true; - } - } - return false; - } +public interface RoleValidator { - boolean isMsoRequestValid(RequestDetails msoRequest) { - if (this.disableRoles) { - return true; - } + static RoleValidator by(List roles) { + boolean disableRoles = + StringUtils.equals(SystemProperties.getProperty("role_management_activated"), "false"); - try { - String globalSubscriberIdRequested = (String) ((Map) ((Map) msoRequest.getAdditionalProperties() - .get("requestDetails")).get("subscriberInfo")).get("globalSubscriberId"); - String serviceType = (String) ((Map) ((Map) msoRequest.getAdditionalProperties().get("requestDetails")) - .get("requestParameters")).get("subscriptionServiceType"); - return isServicePermitted(globalSubscriberIdRequested, serviceType); - } catch (Exception e) { - //Until we'll get the exact information regarding the tenants and the global customer id, we'll return true on unknown requests to mso - return true; - } + return disableRoles + ? new AlwaysValidRoleValidator() + : new RoleValidatorByRoles(roles); } - public boolean isTenantPermitted(String globalCustomerId, String serviceType, String tenantName) { - if (this.disableRoles) { - return true; - } + boolean isSubscriberPermitted(String subscriberName); - for (Role role : userRoles) { - if (role.getSubscribeName().equals(globalCustomerId) - && role.getServiceType().equals(serviceType) - && (role.getTenant() == null || role.getTenant().equalsIgnoreCase(tenantName))) { - return true; - } - } - return false; - } + boolean isServicePermitted(String subscriberName, String serviceType); - void enableRoles() { - this.disableRoles = false; - } + boolean isTenantPermitted(String globalCustomerId, String serviceType, String tenantName); } -- cgit 1.2.3-korg