Arica
Arica

Reputation: 1

Configuring Security and Streamlining WebClient in Helidon: Adding Security Services and Handling Readers, Writers, and Media Support via CONFIG File

I am currently working on adding security to the Helidon webclient programmatically. To achieve this, I'm using the WebClientSecurity class to create a security service and integrating it into the WebClient using the addService method. However, I'm wondering if it's possible to handle the security configuration through a CONFIG file instead, eliminating the need for explicit code.

Security clientSecurity = Security.builder()
      .addProvider(HttpBasicAuthProvider.builder().build())
      .build();
WebClient.Builder builder = WebClient.builder()
      .baseUri(..)
      .config(..)
      .addService(WebClientSecurity.create(clientSecurity))
      .addReader(..)
      .addWriter(..)
      .addMediaSupport(..)
      .addMediaSupport(..);
private WebClient webClient= builder.build();

In addition to that, I'm also curious if it's possible to streamline the code further by removing the addReader, addWriter, and addMediaSupport methods from the WebClient and instead relying on the configuration file to handle them.

For example, can I create the WebClient like this?

WebClient webClient = WebClient.builder() .baseUri(..) .config(config) .build();

I would appreciate any insights or suggestions on achieving these configurations. Thank you!

Upvotes: 0

Views: 104

Answers (1)

Arjav Desai
Arjav Desai

Reputation: 46

We currently don't have support for config based security for webclient. You may want to update https://github.com/helidon-io/helidon/issues/2122 and https://github.com/helidon-io/helidon/issues/1733 with your usecase or atleast give them thumbs up.

In the meantime, you can build security using config and then set that programmatically on webclient, that should act as work around e.g. see "configuration pattern" at https://helidon.io/docs/latest/#/se/security/introduction

Upvotes: 0

Related Questions