X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Fclds%2FApplication.java;h=e83ff3e767b9ba9d3f1734ab5baf1a28890c03d7;hb=4f47b61e3dc7608f9883b1bde4d6cb60438c6368;hp=bebb07844c8b52670c0f5aaf06c88176c65d85de;hpb=f527ac93d843bd545bd6637cb012378c75a62e65;p=clamp.git diff --git a/src/main/java/org/onap/clamp/clds/Application.java b/src/main/java/org/onap/clamp/clds/Application.java index bebb0784..e83ff3e7 100644 --- a/src/main/java/org/onap/clamp/clds/Application.java +++ b/src/main/java/org/onap/clamp/clds/Application.java @@ -2,125 +2,128 @@ * ============LICENSE_START======================================================= * ONAP CLAMP * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights + * Copyright (C) 2017-2018 AT&T Intellectual Property. 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. + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ + * 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 + * + * 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============================================ * =================================================================== - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.clamp.clds; -import java.util.ArrayList; -import java.util.Collection; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; - -import org.apache.camel.component.servlet.CamelHttpTransportServlet; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import java.io.IOException; +import java.io.InputStream; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.Enumeration; import org.apache.catalina.connector.Connector; -import org.camunda.bpm.spring.boot.starter.webapp.CamundaBpmWebappAutoConfiguration; +import org.onap.clamp.clds.util.ClampVersioning; +import org.onap.clamp.clds.util.ResourceFileUtils; +import org.onap.clamp.util.PassDecoder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; -import org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration; -import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; -import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; +import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.boot.web.servlet.ServletRegistrationBean; -import org.springframework.boot.web.support.SpringBootServletInitializer; -import org.springframework.context.ApplicationContext; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; +import org.springframework.core.env.Environment; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.scheduling.annotation.EnableAsync; - -import com.att.ajsc.common.utility.SystemPropertiesLoader; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -@SpringBootApplication -@ComponentScan(basePackages = { "org.onap.clamp.clds", "com.att.ajsc" }) -@EnableAutoConfiguration(exclude = { CamundaBpmWebappAutoConfiguration.class, HibernateJpaAutoConfiguration.class, - JpaRepositoriesAutoConfiguration.class, SecurityAutoConfiguration.class, - ManagementWebSecurityAutoConfiguration.class }) +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@ComponentScan(basePackages = { "org.onap.clamp" }) +@SpringBootApplication(exclude = { SecurityAutoConfiguration.class, UserDetailsServiceAutoConfiguration.class }) +@EnableJpaRepositories(basePackages = { "org.onap.clamp" }) +@EntityScan(basePackages = { "org.onap.clamp" }) +@EnableTransactionManagement +@EnableConfigurationProperties @EnableAsync +@EnableScheduling +@EnableJpaAuditing public class Application extends SpringBootServletInitializer { - protected static final EELFLogger logger = EELFManager.getInstance().getLogger(Application.class); - - @Autowired - protected ApplicationContext appContext; - - private static final String CAMEL_SERVLET_NAME = "CamelServlet"; - private static final String CAMEL_URL_MAPPING = "/restservices/clds/v1/*"; - + protected static final EELFLogger eelfLogger = EELFManager.getInstance().getLogger(Application.class); // This settings is an additional one to Spring config, // only if we want to have an additional port automatically redirected to // HTTPS @Value("${server.http-to-https-redirection.port:none}") - private String httpRedirectedPort; - + private String httpRedirectedPort; /** * This 8080 is the default port used by spring if this parameter is not * specified in application.properties. */ @Value("${server.port:8080}") - private String springServerPort; - + private String springServerPort; @Value("${server.ssl.key-store:none}") - private String sslKeystoreFile; + private String sslKeystoreFile; + + @Autowired + private Environment env; @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class); } - public static void main(String[] args) throws Exception { - SystemPropertiesLoader.addSystemProperties(); + public static void main(String[] args) { + // Start the Spring application SpringApplication.run(Application.class, args); } + /** + * This method is used to declare the camel servlet. + * + * @return A servlet bean + * @throws IOException IO Exception + */ @Bean - public ServletRegistrationBean servletRegistrationBean() { - ServletRegistrationBean registration = new ServletRegistrationBean(); - registration.setName(CAMEL_SERVLET_NAME); - registration.setServlet(new CamelHttpTransportServlet()); - Collection urlMappings = new ArrayList<>(); - urlMappings.add(CAMEL_URL_MAPPING); - registration.setUrlMappings(urlMappings); + public ServletRegistrationBean camelServletRegistrationBean() throws IOException { + eelfLogger.info(ResourceFileUtils.getResourceAsString("boot-message.txt") + "(v" + + ClampVersioning.getCldsVersionFromProps() + ")" + System.getProperty("line.separator") + + getSslExpirationDate()); + ServletRegistrationBean registration = new ServletRegistrationBean(new ClampServlet(), "/restservices/clds/*"); + registration.setName("CamelServlet"); return registration; } - @Bean - public Client restClient() { - return ClientBuilder.newClient(); - } - /** * This method is used by Spring to create the servlet container factory. - * + * * @return The TomcatEmbeddedServletContainerFactory just created */ @Bean - public EmbeddedServletContainerFactory getEmbeddedServletContainerFactory() { - TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory(); + public ServletWebServerFactory getEmbeddedServletContainerFactory() { + TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory(); if (!"none".equals(httpRedirectedPort) && !"none".equals(sslKeystoreFile)) { // Automatically redirect to HTTPS tomcat = new TomcatEmbeddedServletContainerFactoryRedirection(); @@ -128,16 +131,14 @@ public class Application extends SpringBootServletInitializer { if (newConnector != null) { tomcat.addAdditionalTomcatConnectors(newConnector); } - } return tomcat; - } private Connector createRedirectConnector(int redirectSecuredPort) { if (redirectSecuredPort <= 0) { - logger.warn( - "HTTP port redirection to HTTPS is disabled because the HTTPS port is 0 (random port) or -1 (Connector disabled)"); + eelfLogger.warn("HTTP port redirection to HTTPS is disabled because the HTTPS port is 0 (random port) or -1" + + " (Connector disabled)"); return null; } Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); @@ -148,4 +149,34 @@ public class Application extends SpringBootServletInitializer { return connector; } + private String getSslExpirationDate() throws IOException { + StringBuilder result = new StringBuilder(" :: SSL Certificates :: "); + try { + if (env.getProperty("server.ssl.key-store") != null) { + + KeyStore keystore = KeyStore.getInstance(env.getProperty("server.ssl.key-store-type")); + String password = PassDecoder.decode(env.getProperty("server.ssl.key-store-password"), + env.getProperty("clamp.config.keyFile")); + String keyStore = env.getProperty("server.ssl.key-store"); + InputStream is = ResourceFileUtils.getResourceAsStream(keyStore.replaceAll("classpath:", "")); + keystore.load(is, password.toCharArray()); + + Enumeration aliases = keystore.aliases(); + while (aliases.hasMoreElements()) { + String alias = aliases.nextElement(); + if ("X.509".equals(keystore.getCertificate(alias).getType())) { + result.append("* " + alias + " expires " + + ((X509Certificate) keystore.getCertificate(alias)).getNotAfter() + + System.getProperty("line.separator")); + } + } + } else { + result.append("* NONE HAS been configured"); + } + } catch (CertificateException | NoSuchAlgorithmException | KeyStoreException e) { + eelfLogger.warn("SSL certificate access error ", e); + + } + return result.toString(); + } }