title: "Secret id missing" error while connecting to Vault using Spring cloud vault
body: <p>I am trying to connect to spring vault using role based authentication (spring boot project).</p>
  
  <p>As per documentation, I should be able to connect to spring vault only using approle (pull mode). However, I am getting secrect-id missing exception on application start up.</p>
  
  <p><a href="http://cloud.spring.io/spring-cloud-vault/single/spring-cloud-vault.html#_approle_authentication" rel="nofollow noreferrer">http://cloud.spring.io/spring-cloud-vault/single/spring-cloud-vault.html#_approle_authentication</a></p>
  
  <p>When I pass, secret-id also, I am able to connect and properties/values are getting correctly autowired.</p>
  
  <p>Is there any way I can connect with vault using "token + role/role-id" and spring generate secret-id for me automatically at run time using mentioned info.</p>
  
  <pre><code>spring.cloud.vault:
      scheme: http
      host: &lt;host url&gt;
      port: 80
      token : &lt;token&gt;
      generic.application-name: vault/abc/pqr/test
      generic.backend: &lt;some value&gt;
      generic.default-context: vault/abc/pqr/test
      token: &lt;security token&gt;
      authentication: approle
      app-role:
        role-id: &lt;role-id&gt;
  </code></pre>
  
  <p>POM:</p>
  
  <pre><code>&lt;dependency&gt;
          &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
          &lt;artifactId&gt;spring-cloud-vault-starter-config&lt;/artifactId&gt;
          &lt;version&gt;1.0.0.BUILD-SNAPSHOT&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>Please let me know in case any other info is required.</p>
  
  <h1>Update</h1>
  
  <p>@mp911de, I tried as per your suggestion, however spring-cloud-vault is picking properties set in bootstrap.yml and not one set inside "onApplicationEvent" and thus solution is not working. I tried setting property by "System.setProperty" method but that event didn't worked.</p>
  
  <p>However, if I am setting properties in main before run method, it is working as expected. But I need to load application.properties first (need to pick some configuration from there) and thus don't want to write logic there.</p>
  
  <p>Is there anything wrong in my approach ??</p>
  
  <pre><code>@Component public class LoadVaultProperties implements ApplicationListener&lt;ApplicationEnvironmentPreparedEvent&gt; {
  private RestTemplate restTemplate = new RestTemplate();
  
  @Override
  public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
      try {
          String roleId = getRoleIdForRole(event); //helper method
          String secretId = getSecretIdForRoleId(event); //helper method
  
          Properties properties = new Properties();
  
          properties.put("spring.cloud.vault.app-role.secret-id", secretId);
          properties.put("spring.cloud.vault.app-role.role-id", roleId); 
  
          event.getEnvironment().getPropertySources().addFirst(new PropertiesPropertySource(
                  PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME, properties));          
      } catch (Exception ex) {
          throw new IllegalStateException(ex);
      }
  }
  </code></pre>