title: Spring boot HTTP Basic pass through to JDBC
body: <p>I have configured a JDBC data source and autowired the JDBCTemplate to execute custom SQL queries. I also have a simple HTTP Basic authentication:</p>
  
  <pre><code>auth.inMemoryAuthentication()
                  .withUser("user").password("password").roles("USER");
  </code></pre>
  
  <p>However, I would like to use the user and password used for HTTP Basic to authenticate the user to the data base itself, i.e pass through the credentials of HTTP Basic to the data source and execute queries as the user who logged in with HTTP Basic authentication. I'm facing two issues here, one is that the username and password are in the application.properties file that I want to override every time a user authenticates and also (reload?) execute queries as that user instead of the ones specified in the properties file.</p>
  
  <p>Update 1:</p>
  
  <p>I could programmatically use username and password like below:</p>
  
  <pre><code>@Bean
  @Primary
  public DataSource dataSource() {
      return DataSourceBuilder
          .create()
          .username("")
          .password("")
          .url("")
          .driverClassName("")
          .build();
  }
  </code></pre>
  
  <p>But how to call this every time a user logs with the HTTP Basic auth with those credentials?</p>