* limitations under the License.
* ============LICENSE_END=========================================================
*/
-/**
- * This copy of Woodstox XML processor is licensed under the
- * Apache (Software) License, version 2.0 ("the License").
- * See the License for details about distribution rights, and the
- * specific rights regarding derivate works.
- *
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/
- *
- * A copy is also included in the downloadable source code package
- * containing Woodstox, in file "ASL2.0", under the same directory
- * as this file.
- */
package org.onap.aai.sparky;
-import org.apache.camel.builder.RouteBuilder;
+import javax.servlet.Filter;
+
import org.apache.camel.component.servlet.CamelHttpTransportServlet;
-import org.apache.camel.model.rest.RestBindingMode;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
+import org.onap.aai.sparky.config.PropertyPasswordConfiguration;
+import org.onap.aai.sparky.security.filter.LoginFilter;
+import org.openecomp.portalsdk.core.onboarding.crossapi.PortalRestAPIProxy;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
-import org.springframework.boot.web.support.SpringBootServletInitializer;
-import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
-import org.springframework.stereotype.Component;
@SpringBootApplication
-public class Application /*extends SpringBootServletInitializer */ {
+public class Application {
- private @Autowired AutowireCapableBeanFactory beanFactory;
-
+ private static final String SPARKY_SSL_ENABLED_PROPERTY = "sparky.ssl.enabled";
+ private static final String SPARKY_PORTAL_ENABLED_PROPERTY = "sparky.portal.enabled";
+ private static final String SPARKY_SSL_ENABLED_ENV = "SPARKY_SSL_ENABLED";
+ private static final String SPARKY_PORTAL_ENABLED_ENV = "SPARKY_PORTAL_ENABLED";
+
+ private Filter loginFilter = new LoginFilter();
+
public static void main(String[] args) {
- ApplicationContext applicationContext = SpringApplication.run(Application.class, args);
-
- /*for (String name : applicationContext.getBeanDefinitionNames()) {
- System.out.println(name);
- }*/
-
+ setDefaultProperties();
+ SpringApplication app = new SpringApplication(Application.class);
+ app.addInitializers(new PropertyPasswordConfiguration());
+ app.run(args);
+
}
- /* @Component
- class RestApi extends RouteBuilder {
+ protected static void setDefaultProperties() {
- @Override
- public void configure() {
-
- //restConfiguration().component("restlet").contextPath("/rs").bindingMode(RestBindingMode.json);
-
+ /*
+ * By default we want ssl and portal integration, however it is possible to turn these off with
+ * properties for local development and interop in some situations.
+ */
- /*rest("/books").description("Books REST service")
- .get("/").description("The list of all the books")
- .route().routeId("books-api")
- .bean(Database.class, "findBooks")
- .endRest()
- .get("order/{id}").description("Details of an order by id")
- .route().routeId("order-api")
- .bean(Database.class, "findOrder(${header.id})");*/
- /* }
- }*/
-
+ if (System.getenv(SPARKY_SSL_ENABLED_ENV) == null) {
+ System.setProperty(SPARKY_SSL_ENABLED_PROPERTY, "true");
+ } else {
+ System.setProperty(SPARKY_SSL_ENABLED_PROPERTY, System.getenv(SPARKY_SSL_ENABLED_ENV));
+ }
+
+ boolean sslEnabled = Boolean.parseBoolean(System.getProperty(SPARKY_SSL_ENABLED_PROPERTY));
+
+ if (sslEnabled) {
+ System.setProperty("server.ssl.key-store-password", System.getenv("KEYSTORE_PASSWORD"));
+ System.setProperty("server.ssl.key-password", System.getenv("KEYSTORE_ALIAS_PASSWORD"));
+ }
+
+ if (System.getenv(SPARKY_PORTAL_ENABLED_ENV) == null) {
+ System.setProperty(SPARKY_PORTAL_ENABLED_PROPERTY, "true");
+ } else {
+ System.setProperty(SPARKY_PORTAL_ENABLED_PROPERTY, System.getenv(SPARKY_PORTAL_ENABLED_ENV));
+ }
+ }
- /*
- * TODO: we need to figure out the initialization required for our restlets
- */
-
- /*@Bean
- public ServletRegistrationBean restletBootstrapInitialization() {
-
- SpringServerServlet serverServlet = new SpringServerServlet();
- ServletRegistrationBean regBean = new ServletRegistrationBean( serverServlet, "/rest/*");
-
-
- Map<String,String> params = new HashMap<String,String>();
-
- params.put("org.restlet.component", "restletComponent");
-
- regBean.setInitParameters(params);
-
- return regBean;
- }*/
-
-
-
/*
* This initialization code enabled access to aai-ui-proxy-processor
*/
-
@Bean
ServletRegistrationBean servletRegistrationBean() {
final ServletRegistrationBean servlet =
return servlet;
}
- /* @Bean
- public EmbeddedServletContainerFactory servletContainerFactory() {
- return new TomcatEmbeddedServletContainerFactory() {
-
- /*
- * Stackoverflow solution for adding a WAR into our embedded tomcat runtime
- * https://stackoverflow.com/questions/31374726/spring-boot-how-to-add-another-war-files-to-the-embedded-tomcat
- */
-
-
- /* @Override
- protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat tomcat) {
- // Ensure that the webapps directory exists
- System.out.println("catalina base = " + tomcat.getServer().getCatalinaBase());
- new File(tomcat.getServer().getCatalinaBase(), "webapps").mkdirs();
-
- try {
- Context context = tomcat.addWebapp("/services/aai/webapp", "X:\\2018_dev\\OSEAAI\\NUC-7257-spring-boot-conversion\\onap_sparky-be\\src\\main\\resources\\extApps\\aai.war");
-
- // Allow the webapp to load classes from your fat jar
- context.setParentClassLoader(getClass().getClassLoader());
- } catch (ServletException ex) {
- throw new IllegalStateException("Failed to add webapp", ex);
- }
- return super.getTomcatEmbeddedServletContainer(tomcat);
- }
-
- };
- }*/
-
/**
- * bind LoginFilter
+ * bind LoginFilter
*/
-
- /*@Bean
- public FilterRegistrationBean myFilter() {
- FilterRegistrationBean registration = new FilterRegistrationBean();
- Filter myFilter = new LoginFilter();
- beanFactory.autowireBean(myFilter);
- registration.setFilter(myFilter);
- registration.addUrlPatterns("/*");
- return registration;
- }*/
-
-
-
-
+ @Bean
+ @ConditionalOnProperty(value = "sparky.portal.enabled", havingValue = "true")
+ public FilterRegistrationBean loginFilterRegistrationBean() {
+ FilterRegistrationBean registration = new FilterRegistrationBean();
+
+ registration.setFilter(loginFilter);
+ registration.addUrlPatterns("/*");
+
+ return registration;
+ }
+
+ /**
+ * Bind the Portal API Proxy
+ */
+ @Bean
+ @ConditionalOnProperty(value = "sparky.portal.enabled", havingValue = "true")
+ public ServletRegistrationBean portalApiProxy() {
+
+ final ServletRegistrationBean servlet =
+ new ServletRegistrationBean(new PortalRestAPIProxy(), "/api/v2/*");
+ servlet.setName("PortalRestApiProxy");
+ return servlet;
+ }
+
}