2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 * Modifications copyright (c) 2019 Nokia
20 * ================================================================================
22 package org.openecomp.sdc.config;
24 import nl.altindag.ssl.SSLFactory;
25 import nl.altindag.ssl.util.JettySslUtils;
26 import org.apache.http.impl.client.CloseableHttpClient;
27 import org.eclipse.jetty.util.ssl.SslContextFactory;
28 import org.onap.config.api.JettySSLUtils;
29 import org.onap.portalsdk.core.onboarding.exception.CipherUtilException;
30 import org.onap.sdc.security.PortalClient;
31 import org.openecomp.sdc.be.auditing.impl.ConfigurationProvider;
32 import org.openecomp.sdc.be.components.impl.ComponentLocker;
33 import org.openecomp.sdc.be.components.impl.aaf.RoleAuthorizationHandler;
34 import org.openecomp.sdc.be.components.impl.lock.ComponentLockAspect;
35 import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
36 import org.openecomp.sdc.be.config.Configuration;
37 import org.openecomp.sdc.be.config.ConfigurationManager;
38 import org.openecomp.sdc.be.ecomp.converters.AssetMetadataConverter;
39 import org.openecomp.sdc.be.filters.FilterConfiguration;
40 import org.openecomp.sdc.be.filters.PortalConfiguration;
41 import org.openecomp.sdc.be.filters.ThreadLocalUtils;
42 import org.springframework.context.annotation.Bean;
43 import org.springframework.context.annotation.ComponentScan;
44 import org.springframework.core.annotation.Order;
46 import javax.net.ssl.SSLSessionContext;
47 import javax.net.ssl.X509ExtendedKeyManager;
48 import javax.net.ssl.X509ExtendedTrustManager;
49 import java.io.IOException;
50 import java.nio.file.Files;
51 import java.nio.file.Path;
52 import java.nio.file.StandardOpenOption;
56 @org.springframework.context.annotation.Configuration
58 "org.openecomp.sdc.be.user",
59 "org.openecomp.sdc.be.facade.operations",
60 "org.openecomp.sdc.be.impl",
61 "org.openecomp.sdc.be.auditing.impl",
62 "org.openecomp.sdc.be.distribution",
63 "org.openecomp.sdc.be.switchover.detector",
64 "org.openecomp.sdc.be.tosca",
65 "org.openecomp.sdc.be.components.validation",
66 "org.openecomp.sdc.be.catalog.impl",
67 "org.openecomp.sdc.be.components.impl",
68 "org.openecomp.sdc.be.components.path",
69 "org.openecomp.sdc.be.components.merge",
70 "org.openecomp.sdc.be.components.csar",
71 "org.openecomp.sdc.be.components.property",
72 "org.openecomp.sdc.be.components.attribute",
73 "org.openecomp.sdc.be.csar.security",
74 "org.openecomp.sdc.be.datamodel.utils",
75 "org.openecomp.sdc.be.components.upgrade",
76 "org.openecomp.sdc.be.externalapi.servlet",
77 "org.openecomp.sdc.be.servlets",
78 "org.openecomp.sdc.be.filters",
79 "org.openecomp.sdc.be.plugins",
80 "org.openecomp.sdc.be.togglz",
81 "org.openecomp.sdc.be.model.cache",
82 "org.openecomp.sdc.be.ui.mapper"})
84 public class CatalogBESpringConfig {
86 private static final int BEFORE_TRANSACTION_MANAGER = 0;
87 private final ComponentLocker componentLocker;
88 private final JettySSLUtils.JettySslConfig sslConfig;
90 public CatalogBESpringConfig(ComponentLocker componentLocker) {
91 this.componentLocker = componentLocker;
92 sslConfig = JettySSLUtils.getSSLConfig();
95 @Bean(name = "lifecycleBusinessLogic")
96 public LifecycleBusinessLogic lifecycleBusinessLogic() {
97 return new LifecycleBusinessLogic();
100 @Bean(name = "configurationProvider")
101 public ConfigurationProvider configurationProvider() {
102 return new ConfigurationProvider();
105 @Bean(name = "asset-metadata-utils")
106 public AssetMetadataConverter assetMetadataConverter() {
107 return new AssetMetadataConverter();
110 @Bean(name = "componentLockAspect")
111 @Order(BEFORE_TRANSACTION_MANAGER)
112 public ComponentLockAspect componentLockAspect() {
113 return new ComponentLockAspect(componentLocker);
117 public RoleAuthorizationHandler roleAuthorizationHandler() {
118 return new RoleAuthorizationHandler();
122 public CloseableHttpClient httpClientConnectionManager() {
123 HttpClientFactory httpClientFactory = new HttpClientFactory();
124 return httpClientFactory.createHttpClient();
128 public PortalConfiguration portalConfiguration() throws CipherUtilException {
129 return new PortalConfiguration();
133 public FilterConfiguration filterConfiguration() {
134 return new FilterConfiguration(configuration());
138 public ThreadLocalUtils threadLocalUtils() {
139 return new ThreadLocalUtils();
143 public PortalClient portalClient() throws CipherUtilException {
144 return new PortalClient(httpClientConnectionManager(), portalConfiguration());
148 public Configuration configuration() {
149 return ConfigurationManager.getConfigurationManager().getConfiguration();
153 public SSLFactory sslFactory() throws IOException {
154 return SSLFactory.builder().withSwappableIdentityMaterial()
155 .withIdentityMaterial(Files.newInputStream(Path.of(sslConfig.getKeystorePath()), StandardOpenOption.READ), sslConfig.getKeystorePass().toCharArray(), sslConfig.getKeystoreType()).withSwappableTrustMaterial()
156 .withTrustMaterial(Files.newInputStream(Path.of(sslConfig.getTruststorePath()), StandardOpenOption.READ), sslConfig.getTruststorePass().toCharArray(), sslConfig.getTruststoreType()).withNeedClientAuthentication()
161 public SslContextFactory.Server sslContextFactory(SSLFactory sslFactory) {
162 return JettySslUtils.forServer(sslFactory);
166 public X509ExtendedKeyManager keyManager(SSLFactory sslFactory) throws Exception {
167 return sslFactory.getKeyManager().orElseThrow(Exception::new);
171 public X509ExtendedTrustManager trustManager(SSLFactory sslFactory) throws Exception {
172 return sslFactory.getTrustManager().orElseThrow(Exception::new);
176 public SSLSessionContext serverSessionContext(SSLFactory sslFactory) {
177 return sslFactory.getSslContext().getServerSessionContext();