summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java
diff options
context:
space:
mode:
authorAlexey Sandler <alexey.sandler@intl.att.com>2020-01-28 16:57:39 +0200
committerAlexey Sandler <alexey.sandler@intl.att.com>2020-01-28 16:57:39 +0200
commit35a9debcc64b05163612165043690ddb128b1293 (patch)
tree00c66d6ed8c6d512b729d872f154b10951799291 /vid-app-common/src/main/java
parent22fb6d661b72bcb99e467c2289257d360d5e13a9 (diff)
create RoleValidatorFactory component.
Issue-ID: VID-758 Signed-off-by: Alexey Sandler <alexey.sandler@intl.att.com> Change-Id: Id444ddbe74b6d28d697e130caa73bd7bfae9ce52
Diffstat (limited to 'vid-app-common/src/main/java')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java14
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java10
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/RoleValidator.java10
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorFactory.java53
4 files changed, 65 insertions, 22 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java
index 563c9ff20..a9ce40bba 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java
@@ -49,7 +49,6 @@ import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
import org.onap.vid.aai.util.AAIRestInterface;
import org.onap.vid.model.VersionByInvariantIdsRequest;
import org.onap.vid.properties.Features;
-import org.onap.vid.roles.Role;
import org.onap.vid.roles.RoleProvider;
import org.onap.vid.roles.RoleValidator;
import org.onap.vid.services.AaiService;
@@ -137,7 +136,7 @@ public class AaiController extends RestrictedBaseController {
@RequestMapping(value = "/aai_get_services", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> doGetServices(HttpServletRequest request) throws IOException {
- RoleValidator roleValidator = RoleValidator.by(roleProvider.getUserRoles(request));
+ RoleValidator roleValidator = roleProvider.getUserRolesValidator(request);
AaiResponse subscriberList = aaiService.getServices(roleValidator);
return aaiResponseToResponseEntity(subscriberList);
@@ -225,7 +224,7 @@ public class AaiController extends RestrictedBaseController {
@RequestMapping(value = "/aai_get_full_subscribers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> getFullSubscriberList(HttpServletRequest request) throws IOException {
ResponseEntity<String> responseEntity;
- RoleValidator roleValidator = RoleValidator.by(roleProvider.getUserRoles(request));
+ RoleValidator roleValidator = roleProvider.getUserRolesValidator(request);
SubscriberFilteredResults subscriberList = aaiService.getFullSubscriberList(roleValidator);
if (subscriberList.getHttpCode() == 200) {
responseEntity = new ResponseEntity<>(objectMapper.writeValueAsString(subscriberList.getSubscriberList()),
@@ -256,8 +255,7 @@ public class AaiController extends RestrictedBaseController {
@RequestMapping(value = "/aai_sub_details/{subscriberId}", method = RequestMethod.GET)
public ResponseEntity<String> getSubscriberDetails(HttpServletRequest request, @PathVariable("subscriberId") String subscriberId,
@RequestParam(value="omitServiceInstances", required = false, defaultValue = "false") boolean omitServiceInstances) throws IOException {
- List<Role> roles = roleProvider.getUserRoles(request);
- RoleValidator roleValidator = RoleValidator.by(roles);
+ RoleValidator roleValidator = roleProvider.getUserRolesValidator(request);
AaiResponse subscriberData = aaiService.getSubscriberData(subscriberId, roleValidator,
featureManager.isActive(Features.FLAG_1906_AAI_SUB_DETAILS_REDUCE_DEPTH) && omitServiceInstances);
String httpMessage = subscriberData.getT() != null ? objectMapper.writeValueAsString(subscriberData.getT()) : subscriberData.getErrorMessage();
@@ -274,8 +272,7 @@ public class AaiController extends RestrictedBaseController {
@RequestParam(value = "owningEntity", required = false) List<String> owningEntities) throws IOException {
ResponseEntity responseEntity;
- List<Role> roles = roleProvider.getUserRoles(request);
- RoleValidator roleValidator = RoleValidator.by(roles);
+ RoleValidator roleValidator = roleProvider.getUserRolesValidator(request);
AaiResponse<ServiceInstancesSearchResults> searchResult = aaiService
.getServiceInstanceSearchResults(subscriberId, instanceIdentifier, roleValidator, owningEntities, projects);
@@ -404,8 +401,7 @@ public class AaiController extends RestrictedBaseController {
ResponseEntity responseEntity;
try {
- List<Role> roles = roleProvider.getUserRoles(request);
- RoleValidator roleValidator = RoleValidator.by(roles);
+ RoleValidator roleValidator = roleProvider.getUserRolesValidator(request);
AaiResponse<GetTenantsResponse[]> response = aaiService
.getTenants(globalCustomerId, serviceType, roleValidator);
if (response.getHttpCode() == 200) {
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 898db332c..d9f2fdedf 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
@@ -58,16 +58,20 @@ public class RoleProvider {
private Function<HttpServletRequest, Integer> getUserIdFunction;
private Function<HttpServletRequest, Map> getRolesFunction;
+ private final RoleValidatorFactory roleValidatorFactory;
@Autowired
- public RoleProvider(AaiService aaiService) {
+ public RoleProvider(AaiService aaiService, RoleValidatorFactory roleValidatorFactory) {
this.aaiService=aaiService;
+ this.roleValidatorFactory = roleValidatorFactory;
getUserIdFunction = UserUtils::getUserId;
getRolesFunction = UserUtils::getRoles;
}
- RoleProvider(AaiService aaiService, Function<HttpServletRequest, Integer> getUserIdFunction, Function<HttpServletRequest, Map> getRolesFunction) {
+ RoleProvider(AaiService aaiService, RoleValidatorFactory roleValidatorFactory,
+ Function<HttpServletRequest, Integer> getUserIdFunction, Function<HttpServletRequest, Map> getRolesFunction) {
this.aaiService = aaiService;
+ this.roleValidatorFactory = roleValidatorFactory;
this.getRolesFunction = getRolesFunction;
this.getUserIdFunction = getUserIdFunction;
}
@@ -162,7 +166,7 @@ public class RoleProvider {
}
public RoleValidator getUserRolesValidator(HttpServletRequest request) {
- return RoleValidator.by(getUserRoles(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 ed280c8b8..7b7401a01 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
@@ -27,16 +27,6 @@ import org.onap.portalsdk.core.util.SystemProperties;
public interface RoleValidator {
- static RoleValidator by(List<Role> roles) {
- final boolean disableRoles = StringUtils.equals(SystemProperties.getProperty("role_management_activated"), "false");
- return by(roles, disableRoles);
- }
-
- static RoleValidator by(List<Role> roles, boolean disableRoles) {
- return disableRoles
- ? new AlwaysValidRoleValidator()
- : new RoleValidatorBySubscriberAndServiceType(roles);
- }
boolean isSubscriberPermitted(String subscriberId);
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
new file mode 100644
index 000000000..12865401d
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorFactory.java
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.vid.roles;
+
+
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.portalsdk.core.util.SystemProperties;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.togglz.core.manager.FeatureManager;
+
+@Component
+public class RoleValidatorFactory {
+ private final FeatureManager featureManager;
+
+ @Autowired
+ public RoleValidatorFactory(FeatureManager featureManager) {
+ this.featureManager = featureManager;
+ }
+
+
+ public RoleValidator by(List<Role> roles) {
+ final boolean disableRoles = StringUtils
+ .equals(SystemProperties.getProperty("role_management_activated"), "false");
+ return by(roles, disableRoles);
+ }
+
+ public RoleValidator by(List<Role> roles, boolean disableRoles) {
+ return disableRoles
+ ? new AlwaysValidRoleValidator()
+ : new RoleValidatorBySubscriberAndServiceType(roles);
+ }
+}