summaryrefslogtreecommitdiffstats
path: root/policy-endpoints/src/main/java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-08-23 12:27:41 -0400
committerJim Hahn <jrh3@att.com>2021-08-23 13:02:30 -0400
commit32ab41fa6a6998ff88cd9dbef31f7c65f39ee0e1 (patch)
treea26ba53f30818565c2d568b6f981a5462c89c04e /policy-endpoints/src/main/java
parent395e6be364eac3d7b7ce9449ac5ba5d4b0035760 (diff)
Support multiple filters in RestServer
Added an API to RestServer so that multiple Filters may be provided. Issue-ID: POLICY-3531 Change-Id: I21f474c01d58237c744d1d70f5b39c2c90fdb401 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'policy-endpoints/src/main/java')
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/RestServer.java34
1 files changed, 29 insertions, 5 deletions
diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/RestServer.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/RestServer.java
index cb50bb33..133a1e7d 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/RestServer.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/RestServer.java
@@ -27,6 +27,7 @@ import java.util.List;
import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;
+import javax.servlet.Filter;
import lombok.ToString;
import org.onap.policy.common.endpoints.http.server.aaf.AafAuthFilter;
import org.onap.policy.common.endpoints.parameters.RestServerParameters;
@@ -59,7 +60,28 @@ public class RestServer extends ServiceManagerContainer {
public RestServer(final RestServerParameters restServerParameters, Class<? extends AafAuthFilter> aafFilter,
Class<?>... jaxrsProviders) {
- if (jaxrsProviders.length == 0) {
+ this(restServerParameters, makeFilterList(aafFilter), Arrays.asList(jaxrsProviders));
+ }
+
+ private static List<Class<? extends Filter>> makeFilterList(Class<? extends AafAuthFilter> aafFilter) {
+ if (aafFilter == null) {
+ return List.of();
+ } else {
+ return List.of(aafFilter);
+ }
+ }
+
+ /**
+ * Constructs the object.
+ *
+ * @param restServerParameters the rest server parameters
+ * @param filters class of object to use to filter requests, or {@code null}
+ * @param jaxrsProviders classes providing the services
+ */
+ public RestServer(final RestServerParameters restServerParameters, List<Class<? extends Filter>> filters,
+ List<Class<?>> jaxrsProviders) {
+
+ if (jaxrsProviders.isEmpty()) {
throw new IllegalArgumentException("no providers specified");
}
@@ -67,8 +89,10 @@ public class RestServer extends ServiceManagerContainer {
.build(getServerProperties(restServerParameters, getProviderClassNames(jaxrsProviders)));
for (HttpServletServer server : this.servers) {
- if (aafFilter != null && server.isAaf()) {
- server.addFilterClass(null, aafFilter.getName());
+ for (Class<? extends Filter> filter : filters) {
+ if (!AafAuthFilter.class.isAssignableFrom(filter) || server.isAaf()) {
+ server.addFilterClass(null, filter.getName());
+ }
}
addAction("REST " + server.getName(), server::start, server::stop);
@@ -123,8 +147,8 @@ public class RestServer extends ServiceManagerContainer {
* @param jaxrsProviders classes providing the services
* @return the provider class names
*/
- private String getProviderClassNames(Class<?>[] jaxrsProviders) {
- return String.join(",", Arrays.stream(jaxrsProviders).map(Class::getName).collect(Collectors.toList()));
+ private String getProviderClassNames(List<Class<?>> jaxrsProviders) {
+ return String.join(",", jaxrsProviders.stream().map(Class::getName).collect(Collectors.toList()));
}
private String getValue(final String value) {