Skip to content

Commit

Permalink
HTTPS for integration-enabler-spring-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
plavjanik committed Nov 27, 2018
1 parent cb499e0 commit f05bf19
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 23 deletions.
Expand Up @@ -30,8 +30,8 @@
@EnableEurekaClient
@EnableWebFlux
@EnableApiDiscovery
@ComponentScan({ "com.ca.mfaas.enable", "com.ca.mfaas.apicatalog", "com.ca.mfaas.product",
"com.ca.mfaas.product.discovery", "com.ca.mfaas.product.web" })
@ComponentScan({ "com.ca.mfaas.enable", "com.ca.mfaas.apicatalog", "com.ca.mfaas.product.config",
"com.ca.mfaas.product.web" })
@EnableScheduling
@EnableRetry
@EnableAsync
Expand Down
Expand Up @@ -15,7 +15,7 @@
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@ComponentScan("com.ca.mfaas.product")
@ComponentScan("com.ca.mfaas.product.web")
public class WebConfig implements WebMvcConfigurer {

@Override
Expand Down
Expand Up @@ -25,7 +25,7 @@
@EnableApiDiscovery
@EnableConfigurationProperties
@EnableWebSocket
@ComponentScan(value = { "com.ca.mfaas.client", "com.ca.mfaas.product.discovery", "com.ca.mfaas.enable", "com.ca.mfaas.product.web" })
@ComponentScan(value = { "com.ca.mfaas.client", "com.ca.mfaas.enable", "com.ca.mfaas.product.web" })
public class DiscoverableClientSampleApplication implements ApplicationListener<ApplicationReadyEvent> {

public static void main(String[] args) {
Expand Down
9 changes: 6 additions & 3 deletions integration-enabler-spring-v2/build.gradle
Expand Up @@ -13,15 +13,17 @@ jar {
}

dependencies {
compile(project(':gateway-common'))
compile(project(':common-service-core'))

compile libraries.springFox
compile libraries.springFoxWeb
compile libraries.javax_validation
compile libraries.spring_cloud_starter_eureka
compile libraries.spring_boot_starter_actuator

compileOnly libraries.lombok
compileOnly libraries.spring_boot_starter_web
compileOnly libraries.spring_cloud_starter_eureka
compileOnly libraries.javax_servlet_api

testCompile libraries.gson
testCompile libraries.powermock_api_mockito2
Expand All @@ -31,5 +33,6 @@ dependencies {
testCompile libraries.spring_boot_starter_test
testCompile libraries.lombok
testCompile libraries.javax_servlet_api
testCompile(group: 'org.yaml', name: 'snakeyaml', version: '1.23')
testCompile libraries.snakeyaml
testCompile libraries.javax_servlet_api
}
Expand Up @@ -9,16 +9,15 @@
*/
package com.ca.mfaas.enable;

import com.ca.mfaas.enable.conditions.ConditionalOnMissingProperty;
import com.ca.mfaas.enable.model.ApiPropertiesContainer;
import com.ca.mfaas.product.conditions.ConditionalOnMissingProperty;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@ConditionalOnProperty(prefix = "eureka.instance.metadata-map.mfaas.discovery", value = "enableApiDoc", havingValue = "true", matchIfMissing = true)
@Configuration
public class EnablerV2Config {
Expand Down
Expand Up @@ -7,7 +7,7 @@
*
* Copyright Contributors to the Zowe Project.
*/
package com.ca.mfaas.product.conditions;
package com.ca.mfaas.enable.conditions;

import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
Expand Down
@@ -0,0 +1,85 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/
package com.ca.mfaas.enable.discovery;

import com.ca.mfaas.security.HttpsConfig;
import com.ca.mfaas.security.HttpsFactory;
import com.netflix.discovery.DiscoveryClient;
import com.netflix.discovery.shared.transport.jersey.EurekaJerseyClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.security.NoSuchAlgorithmException;

import javax.annotation.PostConstruct;

@Configuration
@Slf4j
public class EurekaClientSecurityConfiguration {
@Value("${server.ssl.protocol:TLSv1.2}")
private String protocol;

@Value("${spring.application.name}")
private String serviceId;

@Value("${eureka.client.serviceUrl.defaultZone}")
private String eurekaServerUrl;

@Value("${server.ssl.trustStore:#{null}}")
private String trustStore;

@Value("${server.ssl.trustStorePassword:#{null}}")
private String trustStorePassword;

@Value("${server.ssl.trustStoreType:PKCS12}")
private String trustStoreType;

@Value("${server.ssl.keyAlias:#{null}}")
private String keyAlias;

@Value("${server.ssl.keyStore:#{null}}")
private String keyStore;

@Value("${server.ssl.keyPassword:#{null}}")
private String keyPassword;

@Value("${server.ssl.keyStorePassword:#{null}}")
private String keyStorePassword;

@Value("${server.ssl.keyStoreType:PKCS12}")
private String keyStoreType;

@Value("${apiml.security.verifySslCertificatesOfServices:true}")
private boolean verifySslCertificatesOfServices;

private EurekaJerseyClient eurekaJerseyClient;

@PostConstruct
public void init() {
HttpsConfig httpsConfig = HttpsConfig.builder().keyAlias(keyAlias).protocol(protocol).keyStore(keyStore).keyPassword(keyPassword)
.keyStorePassword(keyStorePassword).keyStoreType(keyStoreType).trustStore(trustStore)
.trustStoreType(trustStoreType).trustStorePassword(trustStorePassword)
.verifySslCertificatesOfServices(verifySslCertificatesOfServices).build();

log.info("Using HTTPS configuration: {}", httpsConfig.toString());

HttpsFactory factory = new HttpsFactory(httpsConfig);
eurekaJerseyClient = factory.createEurekaJerseyClientBuilder(eurekaServerUrl, serviceId).build();
}

@Bean
public DiscoveryClient.DiscoveryClientOptionalArgs discoveryClientOptionalArgs() throws NoSuchAlgorithmException {
DiscoveryClient.DiscoveryClientOptionalArgs args = new DiscoveryClient.DiscoveryClientOptionalArgs();
args.setEurekaJerseyClient(eurekaJerseyClient);
return args;
}
}
Expand Up @@ -18,7 +18,7 @@
@SpringBootApplication
@EnableApiDiscovery
@EnableConfigurationProperties
@ComponentScan({"com.ca.mfaas.enable", "com.ca.mfaas.product"})
@ComponentScan({"com.ca.mfaas.enable"})
public class StaticSwaggerApplication {
public static void main(String[] args) {
SpringApplication.run(StaticSwaggerApplication.class, args);
Expand Down
11 changes: 11 additions & 0 deletions integration-enabler-spring-v2/src/test/resources/application.yml
Expand Up @@ -14,6 +14,17 @@ logging:
##############################################################################################
# MFAAS configuration section
##############################################################################################

environment:
hostname: localhost
port: 10021
discoveryLocations: http://eureka:password@localhost:10011/eureka/
preferIpAddress: false
ipAddress: 127.0.0.1
serverIpAddress: 127.0.0.1
serviceTitle: Sample V2 Client
serviceDescription: Sample V2 Client

mfaas:
discovery:
serviceId: ${environment.serviceId:${spring.application.name}}
Expand Down
11 changes: 0 additions & 11 deletions integration-enabler-spring-v2/src/test/resources/bootstrap.yml

This file was deleted.

0 comments on commit f05bf19

Please sign in to comment.