'BasicAuthRequestInterceptor Send Dynamic username and password from RequestBody of a DTO

I Want to send username and password dynamically each time i get it from DTO Body when Api hit.

can anyone explain me. how i can send dynamic username and password into BasicAuthInterceptor each time when username and password comes from method DTO RequestBody through cron.

here BasicInterceptor config is placed in a different service.

public class LOCBasicAuthFeignClientConfiguration {

    @Bean
    public BasicAuthRequestInterceptor basicAuthRequestInterceptor() {
        return new BasicAuthRequestInterceptor("username", "password");
    }

    @Bean
    public Client feignClient()
    {
        return new Client.Default(getSSLSocketFactory(), new NoopHostnameVerifier());
    }

    private SSLSocketFactory getSSLSocketFactory() {
        try {
            TrustStrategy acceptingTrustStrategy = (chain, authType) -> true;

            SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();
            return sslContext.getSocketFactory();
        } catch (Exception ignored) {
        }
        return null;
    }
}

here is the configuration file

@Configuration
@ComponentScan("com.orderapi.config")
@EnableFeignClients("com.orderapi.api")
public class OrderSharedConfigurationReference {}

I get username and password from an api.i want to set username and password which i get from api into this method dynamically.

   @Bean
   public BasicAuthRequestInterceptor 
   basicAuthRequestInterceptor() {
   return new BasicAuthRequestInterceptor("username", 
   "password");
   }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source