aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org
diff options
context:
space:
mode:
authorEinat Vinouze <einat.vinouze@intl.att.com>2020-01-28 17:29:10 +0200
committerIttay Stern <ittay.stern@att.com>2020-01-29 21:31:17 +0200
commitf4993218ce5204a3e8b4527e40f71d5fdc5d1de9 (patch)
tree89b81955e9349ec2bf51badc57049e59d2d979f3 /vid-app-common/src/main/java/org
parentc0cbcef18427ec1d0edfb872385f128352487464 (diff)
RoleValidatorByOwningEntity permits by PermissionPropertiesOwningEntity
PermissionPropertiesOwningEntity is sharing a parent interface with PermissionPropertiesServiceType: WithPermissionProperties. Issue-ID: VID-758 Change-Id: I90c04cb8d4331d68329f3a12329244f09c6bc184 Signed-off-by: Einat Vinouze <einat.vinouze@intl.att.com> Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src/main/java/org')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java4
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java8
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/model/ServiceInstanceSearchResult.java4
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/PermissionProperties.kt29
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/Role.java27
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java15
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/RoleValidator.java5
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorByOwningEntity.java26
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorBySubscriberAndServiceType.java16
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorFactory.java5
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java6
11 files changed, 92 insertions, 53 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java
index dcbd9b9e4..2d7a9253e 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java
@@ -33,7 +33,7 @@ import org.onap.vid.model.aaiTree.Network;
import org.onap.vid.model.aaiTree.RelatedVnf;
import org.onap.vid.model.aaiTree.VpnBinding;
import org.onap.vid.properties.Features;
-import org.onap.vid.roles.PermissionProperties;
+import org.onap.vid.roles.PermissionPropertiesSubscriberAndServiceType;
import org.onap.vid.roles.RoleProvider;
import org.onap.vid.services.AaiService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -95,7 +95,7 @@ public class AaiController2 extends VidRestrictedBaseController {
final boolean isEditPermitted = roleProvider
.getUserRolesValidator(request)
- .isServicePermitted(new PermissionProperties(subscriberId, serviceType));
+ .isServicePermitted(new PermissionPropertiesSubscriberAndServiceType(subscriberId, serviceType));
return new Permissions(isEditPermitted);
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java b/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java
index 4b03ea4d9..ce8bbb50c 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java
@@ -33,7 +33,7 @@ import org.onap.vid.model.ServiceInfo;
import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
import org.onap.vid.mso.MsoResponseWrapper2;
import org.onap.vid.properties.Features;
-import org.onap.vid.roles.PermissionProperties;
+import org.onap.vid.roles.AllPermissionProperties;
import org.onap.vid.roles.RoleProvider;
import org.onap.vid.roles.RoleValidator;
import org.onap.vid.services.AsyncInstantiationBusinessLogic;
@@ -169,7 +169,11 @@ public class AsyncInstantiationController extends VidRestrictedBaseController {
private void throwExceptionIfAccessDenied(ServiceInstantiation request, HttpServletRequest httpServletRequest, String userId) {
if (featureManager.isActive(Features.FLAG_1906_INSTANTIATION_API_USER_VALIDATION)) {
RoleValidator roleValidator = roleProvider.getUserRolesValidator(httpServletRequest);
- if (!roleValidator.isServicePermitted(new PermissionProperties(request.getGlobalSubscriberId(), request.getSubscriptionServiceType()))) {
+ if (!roleValidator.isServicePermitted(new AllPermissionProperties(
+ request.getGlobalSubscriberId(),
+ request.getSubscriptionServiceType(),
+ request.getOwningEntityId()))
+ ) {
throw new AccessDeniedException(String.format("User %s is not allowed to make this request", userId));
}
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/model/ServiceInstanceSearchResult.java b/vid-app-common/src/main/java/org/onap/vid/model/ServiceInstanceSearchResult.java
index 01cc11d95..2665313d7 100644
--- a/vid-app-common/src/main/java/org/onap/vid/model/ServiceInstanceSearchResult.java
+++ b/vid-app-common/src/main/java/org/onap/vid/model/ServiceInstanceSearchResult.java
@@ -22,9 +22,9 @@ package org.onap.vid.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.StringUtils;
-import org.onap.vid.roles.WithPermissionProperties;
+import org.onap.vid.roles.WithPermissionPropertiesSubscriberAndServiceType;
-public class ServiceInstanceSearchResult implements WithPermissionProperties {
+public class ServiceInstanceSearchResult implements WithPermissionPropertiesSubscriberAndServiceType {
private final String SUBSCRIBER_ID_FRONTEND_ALIAS = "globalCustomerId";
diff --git a/vid-app-common/src/main/java/org/onap/vid/roles/PermissionProperties.kt b/vid-app-common/src/main/java/org/onap/vid/roles/PermissionProperties.kt
index f62b98aef..dbdd41326 100644
--- a/vid-app-common/src/main/java/org/onap/vid/roles/PermissionProperties.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/roles/PermissionProperties.kt
@@ -3,15 +3,32 @@ package org.onap.vid.roles
import org.onap.vid.aai.ServiceSubscription
-interface WithPermissionProperties {
+interface WithPermissionProperties
+
+interface WithPermissionPropertiesSubscriberAndServiceType: WithPermissionProperties {
val subscriberId: String?
val serviceType: String?
}
-data class PermissionProperties(
- override val subscriberId: String,
- override val serviceType: String
-) : WithPermissionProperties {
- constructor(serviceSubscription: ServiceSubscription, subscriberId: String) : this(subscriberId, serviceSubscription.serviceType)
+interface WithPermissionPropertiesOwningEntity: WithPermissionProperties {
+ val owningEntityId: String?
+}
+
+
+data class AllPermissionProperties(
+ override val subscriberId: String?,
+ override val serviceType: String?,
+ override val owningEntityId: String?
+): WithPermissionPropertiesOwningEntity, WithPermissionPropertiesSubscriberAndServiceType
+
+data class PermissionPropertiesOwningEntity(
+ override val owningEntityId: String?
+): WithPermissionPropertiesOwningEntity
+
+data class PermissionPropertiesSubscriberAndServiceType(
+ override val subscriberId: String?,
+ override val serviceType: String?
+) : WithPermissionPropertiesSubscriberAndServiceType {
+ constructor(serviceSubscription: ServiceSubscription, subscriberId: String?) : this(subscriberId, serviceSubscription.serviceType)
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/roles/Role.java b/vid-app-common/src/main/java/org/onap/vid/roles/Role.java
index 3d94dc00a..3de894480 100644
--- a/vid-app-common/src/main/java/org/onap/vid/roles/Role.java
+++ b/vid-app-common/src/main/java/org/onap/vid/roles/Role.java
@@ -20,49 +20,44 @@
package org.onap.vid.roles;
-/**
- * Created by Oren on 7/1/17.
- */
-
public class Role {
- private EcompRole ecompRole;
+ private final EcompRole ecompRole;
+
+ private final String subscriberId;
- private String subscriberId;
+ private final String serviceType;
- private String serviceType;
+ private final String tenant;
- private String tenant;
+ private final String owningEntityId;
- public Role(EcompRole ecompRole, String subscriberId, String serviceType, String tenant) {
+ public Role(EcompRole ecompRole, String subscriberId, String serviceType, String tenant, String owningEntityId) {
this.ecompRole = ecompRole;
this.subscriberId = subscriberId;
this.serviceType = serviceType;
this.tenant = tenant;
+ this.owningEntityId = owningEntityId;
}
public EcompRole getEcompRole() {
return ecompRole;
}
-
public String getSubscriberId() {
return subscriberId;
}
- public void setSubscriberId(String subscriberId) {
- this.subscriberId = subscriberId;
- }
-
public String getServiceType() {
return serviceType;
}
-
public String getTenant() {
return tenant;
}
-
+ public String getOwningEntityId() {
+ return owningEntityId;
+ }
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java b/vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java
index d9f2fdedf..c35f5f704 100644
--- a/vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java
+++ b/vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java
@@ -42,11 +42,6 @@ import org.onap.vid.services.AaiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-
-/**
- * Created by Oren on 7/1/17.
- */
-
@Component
public class RoleProvider {
@@ -147,11 +142,13 @@ public class RoleProvider {
public Role createRoleFromStringArr(String[] roleParts, String rolePrefix) throws RoleParsingException {
String globalCustomerID = replaceSubscriberNameToGlobalCustomerID(roleParts[0], rolePrefix);
+ String owningEntityId = translateOwningEntityNameToOwningEntityId(roleParts[0]);
+
try {
if (roleParts.length > 2) {
- return new Role(EcompRole.READ, globalCustomerID, roleParts[1], roleParts[2]);
+ return new Role(EcompRole.READ, globalCustomerID, roleParts[1], roleParts[2], owningEntityId);
} else {
- return new Role(EcompRole.READ, globalCustomerID, roleParts[1], null);
+ return new Role(EcompRole.READ, globalCustomerID, roleParts[1], null, owningEntityId);
}
} catch (ArrayIndexOutOfBoundsException e) {
if (roleParts.length > 0)
@@ -165,6 +162,10 @@ public class RoleProvider {
}
+ private String translateOwningEntityNameToOwningEntityId(String owningEntityName) {
+ return owningEntityName; // TODO: translate to id
+ }
+
public RoleValidator getUserRolesValidator(HttpServletRequest request) {
return roleValidatorFactory.by(getUserRoles(request));
}
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 7b7401a01..14c027392 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
@@ -21,13 +21,8 @@
package org.onap.vid.roles;
-import java.util.List;
-import org.apache.commons.lang3.StringUtils;
-import org.onap.portalsdk.core.util.SystemProperties;
-
public interface RoleValidator {
-
boolean isSubscriberPermitted(String subscriberId);
boolean isServicePermitted(WithPermissionProperties serviceInstanceSearchResult);
diff --git a/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorByOwningEntity.java b/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorByOwningEntity.java
index 50fc1091e..8d73dc400 100644
--- a/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorByOwningEntity.java
+++ b/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorByOwningEntity.java
@@ -21,10 +21,25 @@
package org.onap.vid.roles;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+
public class RoleValidatorByOwningEntity implements RoleValidator{
- public boolean isOwningEntityIdPermitted(String owningEntityId){
- return false;
+ private final List<Role> userRoles;
+
+ RoleValidatorByOwningEntity(List<Role> roles) {
+ this.userRoles = roles;
+ }
+
+ private boolean isOwningEntityIdPermitted(String owningEntityId) {
+ if (StringUtils.isEmpty(owningEntityId)) {
+ return false;
+ }
+
+ return userRoles.stream().anyMatch(userRole ->
+ StringUtils.equals(userRole.getOwningEntityId(), owningEntityId)
+ );
}
@Override
@@ -34,7 +49,12 @@ public class RoleValidatorByOwningEntity implements RoleValidator{
@Override
public boolean isServicePermitted(WithPermissionProperties permissionProperties) {
- return false;
+ if (permissionProperties instanceof WithPermissionPropertiesOwningEntity) {
+ String owningEntityId = ((WithPermissionPropertiesOwningEntity) permissionProperties).getOwningEntityId();
+ return isOwningEntityIdPermitted(owningEntityId);
+ } else {
+ return false;
+ }
}
@Override
diff --git a/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorBySubscriberAndServiceType.java b/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorBySubscriberAndServiceType.java
index 1e0f9f461..24a00f6e8 100644
--- a/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorBySubscriberAndServiceType.java
+++ b/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorBySubscriberAndServiceType.java
@@ -21,6 +21,7 @@
package org.onap.vid.roles;
import java.util.List;
+import org.apache.commons.lang3.StringUtils;
public class RoleValidatorBySubscriberAndServiceType implements RoleValidator {
@@ -42,14 +43,21 @@ public class RoleValidatorBySubscriberAndServiceType implements RoleValidator {
@Override
public boolean isServicePermitted(WithPermissionProperties permissionProperties) {
- for (Role role : userRoles) {
- if (role.getSubscriberId().equals(permissionProperties.getSubscriberId()) && role.getServiceType().equals(permissionProperties.getServiceType())) {
- return true;
- }
+ if (permissionProperties instanceof WithPermissionPropertiesSubscriberAndServiceType) {
+ return isServicePermitted(
+ (WithPermissionPropertiesSubscriberAndServiceType) permissionProperties
+ );
}
return false;
}
+ private boolean isServicePermitted(WithPermissionPropertiesSubscriberAndServiceType permissionProperties) {
+ return userRoles.stream().anyMatch(userRole ->
+ StringUtils.equals(userRole.getSubscriberId(), permissionProperties.getSubscriberId())
+ && StringUtils.equals(userRole.getServiceType(), permissionProperties.getServiceType())
+ );
+ }
+
@Override
public boolean isTenantPermitted(String subscriberId, String serviceType, String tenantName) {
for (Role role : userRoles) {
diff --git a/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorFactory.java b/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorFactory.java
index f4334b1be..b171ad7e7 100644
--- a/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorFactory.java
+++ b/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorFactory.java
@@ -2,8 +2,7 @@
* ============LICENSE_START=======================================================
* VID
* ================================================================================
- * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2018 - 2019 Nokia. All rights reserved.
+ * Copyright (C) 2017 - 2020 AT&T Intellectual Property. 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.
@@ -54,7 +53,7 @@ public class RoleValidatorFactory {
else if (featureManager.isActive(Features.FLAG_2006_USER_PERMISSIONS_BY_OWNING_ENTITY)){
return new RoleValidatorsComposer(
new RoleValidatorBySubscriberAndServiceType(roles),
- new RoleValidatorByOwningEntity()
+ new RoleValidatorByOwningEntity(roles)
);
}
else {
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java
index 66c0e6c04..696aca5ea 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java
@@ -85,7 +85,7 @@ import org.onap.vid.model.aaiTree.NodeType;
import org.onap.vid.model.aaiTree.RelatedVnf;
import org.onap.vid.model.aaiTree.VpnBinding;
import org.onap.vid.model.aaiTree.VpnBindingKt;
-import org.onap.vid.roles.PermissionProperties;
+import org.onap.vid.roles.PermissionPropertiesSubscriberAndServiceType;
import org.onap.vid.roles.RoleValidator;
import org.onap.vid.utils.Intersection;
import org.onap.vid.utils.Logging;
@@ -268,7 +268,7 @@ public class AaiServiceImpl implements AaiService {
AaiResponse<Services> subscriberResponse = aaiClient.getSubscriberData(subscriberId, omitServiceInstances);
for (ServiceSubscription serviceSubscription : subscriberResponse.getT().serviceSubscriptions.serviceSubscription) {
serviceSubscription.isPermitted = roleValidator.isServicePermitted(
- new PermissionProperties(serviceSubscription, subscriberResponse.getT().globalCustomerId));
+ new PermissionPropertiesSubscriberAndServiceType(serviceSubscription, subscriberResponse.getT().globalCustomerId));
}
return subscriberResponse;
@@ -312,7 +312,7 @@ public class AaiServiceImpl implements AaiService {
if (serviceSubscriptions != null) {
for (ServiceSubscription serviceSubscription : serviceSubscriptions.serviceSubscription) {
- serviceSubscription.isPermitted = roleValidator.isServicePermitted(new PermissionProperties(serviceSubscription, subscriberId));
+ serviceSubscription.isPermitted = roleValidator.isServicePermitted(new PermissionPropertiesSubscriberAndServiceType(serviceSubscription, subscriberId));
results.addAll(getSearchResultsForSingleSubscription(
serviceSubscription, subscriberId, instanceIdentifier, subscriberName,
serviceSubscription.serviceType, roleValidator)