Search in sources :

Example 1 with ClientOptions

use of org.springframework.vault.support.ClientOptions in project spring-vault by spring-projects.

the class VaultNamespaceSecretIntegrationTests method before.

@BeforeEach
void before() {
    Assumptions.assumeTrue(prepare().getVersion().isEnterprise(), "Namespaces require enterprise version");
    List<String> namespaces = new ArrayList<>(Arrays.asList("dev/", "marketing/"));
    List<String> list = prepare().getVaultOperations().list("sys/namespaces");
    namespaces.removeAll(list);
    for (String namespace : namespaces) {
        prepare().getVaultOperations().write("sys/namespaces/" + namespace.replaceAll("/", ""));
    }
    this.devRestTemplate = RestTemplateBuilder.builder().requestFactory(ClientHttpRequestFactoryFactory.create(new ClientOptions(), Settings.createSslConfiguration())).endpoint(TestRestTemplateFactory.TEST_VAULT_ENDPOINT).customizers(restTemplate -> restTemplate.getInterceptors().add(VaultClients.createNamespaceInterceptor("dev")));
    this.marketingRestTemplate = RestTemplateBuilder.builder().requestFactory(ClientHttpRequestFactoryFactory.create(new ClientOptions(), Settings.createSslConfiguration())).endpoint(TestRestTemplateFactory.TEST_VAULT_ENDPOINT).defaultHeader(VaultHttpHeaders.VAULT_NAMESPACE, "marketing");
    VaultTemplate dev = new VaultTemplate(this.devRestTemplate, new SimpleSessionManager(new TokenAuthentication(Settings.token())));
    mountKv(dev, "dev-secrets");
    dev.opsForSys().createOrUpdatePolicy("relaxed", POLICY);
    this.devToken = dev.opsForToken().create(VaultTokenRequest.builder().withPolicy("relaxed").build()).getToken().getToken();
    VaultTemplate marketing = new VaultTemplate(this.marketingRestTemplate, new SimpleSessionManager(new TokenAuthentication(Settings.token())));
    mountKv(marketing, "marketing-secrets");
    marketing.opsForSys().createOrUpdatePolicy("relaxed", POLICY);
    this.marketingToken = marketing.opsForToken().create(VaultTokenRequest.builder().withPolicy("relaxed").build()).getToken().getToken();
}
Also used : Policy(org.springframework.vault.support.Policy) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Settings(org.springframework.vault.util.Settings) StepVerifier(reactor.test.StepVerifier) VaultEndpointProvider(org.springframework.vault.client.VaultEndpointProvider) ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ClientHttpRequestFactoryFactory(org.springframework.vault.client.ClientHttpRequestFactoryFactory) TestRestTemplateFactory(org.springframework.vault.util.TestRestTemplateFactory) TokenAuthentication(org.springframework.vault.authentication.TokenAuthentication) ArrayList(java.util.ArrayList) SimpleSessionManager(org.springframework.vault.authentication.SimpleSessionManager) VaultTokenRequest(org.springframework.vault.support.VaultTokenRequest) Map(java.util.Map) ClientAuthentication(org.springframework.vault.authentication.ClientAuthentication) VaultClients(org.springframework.vault.client.VaultClients) ClientHttpConnectorFactory(org.springframework.vault.client.ClientHttpConnectorFactory) VaultEndpoint(org.springframework.vault.client.VaultEndpoint) RestTemplateBuilder(org.springframework.vault.client.RestTemplateBuilder) Mono(reactor.core.publisher.Mono) ClientOptions(org.springframework.vault.support.ClientOptions) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SslConfiguration(org.springframework.vault.support.SslConfiguration) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) WebClientBuilder(org.springframework.vault.client.WebClientBuilder) List(java.util.List) Assumptions(org.junit.jupiter.api.Assumptions) VaultMount(org.springframework.vault.support.VaultMount) VaultHttpHeaders(org.springframework.vault.client.VaultHttpHeaders) VaultToken(org.springframework.vault.support.VaultToken) IntegrationTestSupport(org.springframework.vault.util.IntegrationTestSupport) AbstractVaultConfiguration(org.springframework.vault.config.AbstractVaultConfiguration) Collections(java.util.Collections) ClientOptions(org.springframework.vault.support.ClientOptions) ArrayList(java.util.ArrayList) TokenAuthentication(org.springframework.vault.authentication.TokenAuthentication) SimpleSessionManager(org.springframework.vault.authentication.SimpleSessionManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with ClientOptions

use of org.springframework.vault.support.ClientOptions in project spring-vault by spring-projects.

the class ClientHttpConnectorFactoryIntegrationTests method jettyClientWithExplicitEnabledProtocolsShouldWork.

@Test
void jettyClientWithExplicitEnabledProtocolsShouldWork() {
    List<String> enabledProtocols = new ArrayList<String>();
    enabledProtocols.add("TLSv1.2");
    ClientHttpConnector factory = JettyClient.usingJetty(new ClientOptions(), Settings.createSslConfiguration().withEnabledProtocols(enabledProtocols));
    WebClient webClient = WebClient.builder().clientConnector(factory).build();
    String response = request(webClient);
    assertThat(response).isNotNull().contains("initialized");
}
Also used : ClientOptions(org.springframework.vault.support.ClientOptions) ClientHttpConnector(org.springframework.http.client.reactive.ClientHttpConnector) ArrayList(java.util.ArrayList) WebClient(org.springframework.web.reactive.function.client.WebClient) Test(org.junit.jupiter.api.Test)

Example 3 with ClientOptions

use of org.springframework.vault.support.ClientOptions in project spring-vault by spring-projects.

the class ClientHttpConnectorFactoryIntegrationTests method reactorNettyClientShouldWork.

@Test
void reactorNettyClientShouldWork() {
    ClientHttpConnector factory = ReactorNetty.usingReactorNetty(new ClientOptions(), Settings.createSslConfiguration());
    WebClient webClient = WebClient.builder().clientConnector(factory).build();
    String response = request(webClient);
    assertThat(response).isNotNull().contains("initialized");
}
Also used : ClientOptions(org.springframework.vault.support.ClientOptions) ClientHttpConnector(org.springframework.http.client.reactive.ClientHttpConnector) WebClient(org.springframework.web.reactive.function.client.WebClient) Test(org.junit.jupiter.api.Test)

Example 4 with ClientOptions

use of org.springframework.vault.support.ClientOptions in project spring-vault by spring-projects.

the class ClientHttpConnectorFactoryIntegrationTests method jettyClientShouldWork.

@Test
void jettyClientShouldWork() {
    ClientHttpConnector factory = JettyClient.usingJetty(new ClientOptions(), Settings.createSslConfiguration());
    WebClient webClient = WebClient.builder().clientConnector(factory).build();
    String response = request(webClient);
    assertThat(response).isNotNull().contains("initialized");
}
Also used : ClientOptions(org.springframework.vault.support.ClientOptions) ClientHttpConnector(org.springframework.http.client.reactive.ClientHttpConnector) WebClient(org.springframework.web.reactive.function.client.WebClient) Test(org.junit.jupiter.api.Test)

Example 5 with ClientOptions

use of org.springframework.vault.support.ClientOptions in project spring-vault by spring-projects.

the class ClientHttpRequestFactoryFactoryIntegrationTests method okHttp3ClientWithExplicitCipherSuitesShouldWork.

@Test
void okHttp3ClientWithExplicitCipherSuitesShouldWork() throws Exception {
    List<String> enabledCipherSuites = new ArrayList<String>();
    enabledCipherSuites.add("TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384");
    enabledCipherSuites.add("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256");
    ClientHttpRequestFactory factory = OkHttp3.usingOkHttp3(new ClientOptions(), Settings.createSslConfiguration().withEnabledCipherSuites(enabledCipherSuites));
    RestTemplate template = new RestTemplate(factory);
    String response = request(template);
    assertThat(factory).isInstanceOf(OkHttp3ClientHttpRequestFactory.class);
    assertThat(response).isNotNull().contains("initialized");
    ((DisposableBean) factory).destroy();
}
Also used : ClientOptions(org.springframework.vault.support.ClientOptions) ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) Netty4ClientHttpRequestFactory(org.springframework.http.client.Netty4ClientHttpRequestFactory) OkHttp3ClientHttpRequestFactory(org.springframework.http.client.OkHttp3ClientHttpRequestFactory) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) DisposableBean(org.springframework.beans.factory.DisposableBean) ArrayList(java.util.ArrayList) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

ClientOptions (org.springframework.vault.support.ClientOptions)35 Test (org.junit.jupiter.api.Test)28 ClientHttpRequestFactory (org.springframework.http.client.ClientHttpRequestFactory)24 RestTemplate (org.springframework.web.client.RestTemplate)19 ArrayList (java.util.ArrayList)14 OkHttp3ClientHttpRequestFactory (org.springframework.http.client.OkHttp3ClientHttpRequestFactory)12 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)11 Netty4ClientHttpRequestFactory (org.springframework.http.client.Netty4ClientHttpRequestFactory)11 DisposableBean (org.springframework.beans.factory.DisposableBean)10 WebClient (org.springframework.web.reactive.function.client.WebClient)9 ClientHttpConnector (org.springframework.http.client.reactive.ClientHttpConnector)8 SslConfiguration (org.springframework.vault.support.SslConfiguration)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 ReactiveVaultTemplate (org.springframework.vault.core.ReactiveVaultTemplate)5 VaultTemplate (org.springframework.vault.core.VaultTemplate)5 StepVerifier (reactor.test.StepVerifier)5 ClientHttpConnectorFactory (org.springframework.vault.client.ClientHttpConnectorFactory)4 RestTemplateBuilder (org.springframework.vault.client.RestTemplateBuilder)4 IntegrationTestSupport (org.springframework.vault.util.IntegrationTestSupport)4 Settings (org.springframework.vault.util.Settings)4