aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidator.java
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2019-04-03 12:00:57 +0300
committerIttay Stern <ittay.stern@att.com>2019-04-03 12:27:06 +0300
commit80705cdf2dc38d48c4261a2ece3914234960233e (patch)
tree1d4f9a5cd6a45a0c900a8df20e8781e053914bcf /vid-app-common/src/main/java/org/onap/vid/roles/RoleValidator.java
parentfa9080bc0e2be3198aebbe1da20af73ed91376ce (diff)
Extract AlwaysValidRoleValidator from RoleValidator
Issue-ID: VID-448 Change-Id: Ic006aceca9c51305d0706df6c2c6062ccaaee3de Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/roles/RoleValidator.java')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/RoleValidator.java82
1 files changed, 12 insertions, 70 deletions
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<Role> userRoles;
-
- public RoleValidator(List<Role> 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<Role> 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);
}