org.springframework.vault.client.SimpleVaultEndpointProvider Java Examples

The following examples show how to use org.springframework.vault.client.SimpleVaultEndpointProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VaultBootstrapConfiguration.java    From spring-cloud-vault with Apache License 2.0 6 votes vote down vote up
public VaultBootstrapConfiguration(ConfigurableApplicationContext applicationContext,
		VaultProperties vaultProperties,
		ObjectProvider<VaultEndpointProvider> endpointProvider,
		ObjectProvider<List<RestTemplateCustomizer>> customizers,
		ObjectProvider<List<RestTemplateRequestCustomizer<?>>> requestCustomizers) {

	this.applicationContext = applicationContext;
	this.vaultProperties = vaultProperties;

	VaultEndpointProvider provider = endpointProvider.getIfAvailable();

	if (provider == null) {
		provider = SimpleVaultEndpointProvider
				.of(VaultConfigurationUtil.createVaultEndpoint(vaultProperties));
	}

	this.endpointProvider = provider;
	this.customizers = new ArrayList<>(
			customizers.getIfAvailable(Collections::emptyList));
	AnnotationAwareOrderComparator.sort(this.customizers);

	this.requestCustomizers = new ArrayList<>(
			requestCustomizers.getIfAvailable(Collections::emptyList));
	AnnotationAwareOrderComparator.sort(this.requestCustomizers);
}
 
Example #2
Source File: VaultReactiveBootstrapConfiguration.java    From spring-cloud-vault with Apache License 2.0 5 votes vote down vote up
public VaultReactiveBootstrapConfiguration(BeanFactory beanFactory,
		VaultProperties vaultProperties,
		ObjectProvider<VaultEndpointProvider> endpointProvider,
		ObjectProvider<List<WebClientCustomizer>> webClientCustomizers) {

	this.beanFactory = beanFactory;
	this.vaultProperties = vaultProperties;

	VaultEndpointProvider provider = endpointProvider.getIfAvailable();

	if (provider == null) {
		provider = SimpleVaultEndpointProvider
				.of(VaultConfigurationUtil.createVaultEndpoint(vaultProperties));
	}

	this.webClientBuilder = WebClientBuilder.builder()
			.httpConnector(createConnector(this.vaultProperties))
			.endpointProvider(provider);
	List<WebClientCustomizer> customizers = new ArrayList<>(
			webClientCustomizers.getIfAvailable(Collections::emptyList));
	AnnotationAwareOrderComparator.sort(customizers);

	customizers.forEach(this.webClientBuilder::customizers);

	if (StringUtils.hasText(this.vaultProperties.getNamespace())) {
		this.webClientBuilder.defaultHeader(VaultHttpHeaders.VAULT_NAMESPACE,
				this.vaultProperties.getNamespace());
	}
}
 
Example #3
Source File: KubernetesHashicorpVaultClientAuthenticationProvider.java    From knox with Apache License 2.0 5 votes vote down vote up
private RestOperations getRestOperations(Map<String, String> properties) throws Exception {
  String vaultAddress = properties.get(HashicorpVaultAliasService.VAULT_ADDRESS_KEY);
  VaultEndpoint vaultEndpoint = VaultEndpoint.from(new URI(vaultAddress));
  VaultEndpointProvider vaultEndpointProvider = SimpleVaultEndpointProvider.of(vaultEndpoint);
  ClientOptions clientOptions = new ClientOptions();
  SslConfiguration sslConfiguration = SslConfiguration.unconfigured();
  ClientHttpRequestFactory clientHttpRequestFactory = ClientHttpRequestFactoryFactory.create(
      clientOptions, sslConfiguration);
  return VaultClients.createRestTemplate(vaultEndpointProvider, clientHttpRequestFactory);
}
 
Example #4
Source File: VaultTemplate.java    From spring-vault with Apache License 2.0 4 votes vote down vote up
/**
 * Create a new {@link VaultTemplate} with a {@link VaultEndpoint} and
 * {@link ClientAuthentication}.
 * @param vaultEndpoint must not be {@literal null}.
 * @param clientAuthentication must not be {@literal null}.
 */
public VaultTemplate(VaultEndpoint vaultEndpoint, ClientAuthentication clientAuthentication) {

	Assert.notNull(vaultEndpoint, "VaultEndpoint must not be null");
	Assert.notNull(clientAuthentication, "ClientAuthentication must not be null");

	this.sessionManager = new SimpleSessionManager(clientAuthentication);
	this.dedicatedSessionManager = true;

	ClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();

	VaultEndpointProvider endpointProvider = SimpleVaultEndpointProvider.of(vaultEndpoint);

	this.statelessTemplate = doCreateRestTemplate(endpointProvider, requestFactory);
	this.sessionTemplate = doCreateSessionTemplate(endpointProvider, requestFactory);
}
 
Example #5
Source File: AbstractVaultConfiguration.java    From spring-vault with Apache License 2.0 2 votes vote down vote up
/**
 * @return a {@link VaultEndpointProvider} returning the value of
 * {@link #vaultEndpoint()}.
 * @since 1.1
 */
public VaultEndpointProvider vaultEndpointProvider() {
	return SimpleVaultEndpointProvider.of(vaultEndpoint());
}
 
Example #6
Source File: VaultTemplate.java    From spring-vault with Apache License 2.0 2 votes vote down vote up
/**
 * Create a new {@link VaultTemplate} with a {@link VaultEndpoint}. This constructor
 * does not use a {@link ClientAuthentication} mechanism. It is intended for usage
 * with Vault Agent to inherit Vault Agent's authentication without using the
 * {@link VaultHttpHeaders#VAULT_TOKEN authentication token header}.
 * @param vaultEndpoint must not be {@literal null}.
 * @since 2.2.1
 */
public VaultTemplate(VaultEndpoint vaultEndpoint) {
	this(SimpleVaultEndpointProvider.of(vaultEndpoint), new SimpleClientHttpRequestFactory());
}
 
Example #7
Source File: VaultTemplate.java    From spring-vault with Apache License 2.0 2 votes vote down vote up
/**
 * Create a new {@link VaultTemplate} with a {@link VaultEndpoint}, and
 * {@link ClientHttpRequestFactory}. This constructor does not use a
 * {@link ClientAuthentication} mechanism. It is intended for usage with Vault Agent
 * to inherit Vault Agent's authentication without using the
 * {@link VaultHttpHeaders#VAULT_TOKEN authentication token header}.
 * @param vaultEndpoint must not be {@literal null}.
 * @param clientHttpRequestFactory must not be {@literal null}.
 * @since 2.2.1
 */
public VaultTemplate(VaultEndpoint vaultEndpoint, ClientHttpRequestFactory clientHttpRequestFactory) {
	this(SimpleVaultEndpointProvider.of(vaultEndpoint), clientHttpRequestFactory);
}
 
Example #8
Source File: VaultTemplate.java    From spring-vault with Apache License 2.0 2 votes vote down vote up
/**
 * Create a new {@link VaultTemplate} with a {@link VaultEndpoint},
 * {@link ClientHttpRequestFactory} and {@link SessionManager}.
 * @param vaultEndpoint must not be {@literal null}.
 * @param clientHttpRequestFactory must not be {@literal null}.
 * @param sessionManager must not be {@literal null}.
 */
public VaultTemplate(VaultEndpoint vaultEndpoint, ClientHttpRequestFactory clientHttpRequestFactory,
		SessionManager sessionManager) {
	this(SimpleVaultEndpointProvider.of(vaultEndpoint), clientHttpRequestFactory, sessionManager);
}
 
Example #9
Source File: ReactiveVaultTemplate.java    From spring-vault with Apache License 2.0 2 votes vote down vote up
/**
 * Create a new {@link ReactiveVaultTemplate} with a {@link VaultEndpoint},
 * {@link ClientHttpConnector}. This constructor does not use a
 * {@link VaultTokenSupplier}. It is intended for usage with Vault Agent to inherit
 * Vault Agent's authentication without using the {@link VaultHttpHeaders#VAULT_TOKEN
 * authentication token header}.
 * @param vaultEndpoint must not be {@literal null}.
 * @param connector must not be {@literal null}.
 * @since 2.2.1
 */
public ReactiveVaultTemplate(VaultEndpoint vaultEndpoint, ClientHttpConnector connector) {
	this(SimpleVaultEndpointProvider.of(vaultEndpoint), connector);
}
 
Example #10
Source File: ReactiveVaultTemplate.java    From spring-vault with Apache License 2.0 2 votes vote down vote up
/**
 * Create a new {@link ReactiveVaultTemplate} with a {@link VaultEndpoint},
 * {@link ClientHttpConnector} and {@link VaultTokenSupplier}.
 * @param vaultEndpoint must not be {@literal null}.
 * @param connector must not be {@literal null}.
 * @param vaultTokenSupplier must not be {@literal null}.
 */
public ReactiveVaultTemplate(VaultEndpoint vaultEndpoint, ClientHttpConnector connector,
		VaultTokenSupplier vaultTokenSupplier) {
	this(SimpleVaultEndpointProvider.of(vaultEndpoint), connector, vaultTokenSupplier);
}