diff options
Diffstat (limited to 'ms/sliboot/src/main/java')
-rw-r--r-- | ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/FilterConfiguration.java | 66 | ||||
-rw-r--r-- | ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/SlibootApp.java | 6 |
2 files changed, 69 insertions, 3 deletions
diff --git a/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/FilterConfiguration.java b/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/FilterConfiguration.java new file mode 100644 index 00000000..295953a4 --- /dev/null +++ b/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/FilterConfiguration.java @@ -0,0 +1,66 @@ +package org.onap.ccsdk.apps.ms.sliboot; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.Properties; + +import org.onap.aaf.cadi.filter.CadiFilter; +import org.onap.ccsdk.sli.core.utils.common.EnvProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.Order; + +@Configuration +@ConditionalOnProperty("cadi.properties.path") +public class FilterConfiguration { + private static final Logger log = LoggerFactory.getLogger(FilterConfiguration.class); + + @Value( "${cadi.properties.path:none}" ) + private String cadiPropFile; + + @Bean + @Order(1) + public FilterRegistrationBean<CadiFilter> cadiFilter() { + CadiFilter filter = new CadiFilter(); + + FilterRegistrationBean<CadiFilter> registrationBean = new FilterRegistrationBean<>(); + registrationBean.setFilter(filter); + if ("none".equals(cadiPropFile)) { + log.info("cadi.properties.path undefined, AAF CADI disabled"); + registrationBean.setEnabled(false); + registrationBean.addUrlPatterns("/xxxx/*"); + } else { + // Note: assume that cadi.properties.path specifies full path to properties file + File cadiFile = new File(cadiPropFile); + if (!cadiFile.exists()) { + log.info("cadi properties file {} not found, AAF CADI disabled", cadiPropFile); + registrationBean.setEnabled(false); + registrationBean.addUrlPatterns("/xxxx/*"); + } else { + Properties cadiProperties = new EnvProperties(); + try { + cadiProperties.load(new FileReader(cadiFile)); + cadiProperties.forEach((k, v) -> { + registrationBean.addInitParameter((String) k, cadiProperties.getProperty((String) k)); + }); + registrationBean.addUrlPatterns("/*"); + log.info("Installed and configured CADI filter"); + } catch (IOException e) { + log.info("Caught exception loading cadi properties file {}, AAF CADI disabled", cadiPropFile, e); + registrationBean.setEnabled(false); + registrationBean.addUrlPatterns("/xxxx/*"); + } + } + + } + + return registrationBean; + } + +} diff --git a/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/SlibootApp.java b/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/SlibootApp.java index 2bca1dbc..0fd23a9e 100644 --- a/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/SlibootApp.java +++ b/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/SlibootApp.java @@ -7,9 +7,9 @@ * 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.
@@ -67,6 +67,6 @@ public class SlibootApp { }
return registrationBean;
- }
+ }
}
|