aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/roles
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/roles')
-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
3 files changed, 60 insertions, 13 deletions
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);
+ }
+}