spring-cloud / spring-cloud-vault

Configuration Integration with HashiCorp Vault
http://cloud.spring.io/spring-cloud-vault/
Apache License 2.0
270 stars 151 forks source link

HttpMessageConverterExtractor (v. 5.3.22) not respecting response class / responds type of VaultResponses #653

Open akuzni2 opened 1 year ago

akuzni2 commented 1 year ago

spring cloud version: 2021.0.3 spring version: 2.7.3 (Spring boot starter)

the vault library doesn't seem to be respecting the response type as it passes it in to HttpMessageConverterExtractor internally.

note please look at the screenshots of my debugger - you will see that HttpMessageConverterExtractor cannot properly parse VaultResponses

Ex:

public class SomeClass {
}
@SpringBootApplication
public class VaultdebugApplication {
    @Bean void createBean() {
        List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
        messageConverters.add(new ByteArrayHttpMessageConverter());
        messageConverters.add(new StringHttpMessageConverter());
        messageConverters.add(new ResourceHttpMessageConverter(false));
        HttpMessageConverterExtractor x = new HttpMessageConverterExtractor(SomeClass.class, messageConverters);
    }
    public static void main(String[] args) {
        SpringApplication.run(VaultdebugApplication.class, args);
    }
}

the above works - HttpMessageConverterExtractor recognizes SomeClass.class as the response type one I trace it through the debugger.

image

however - when I try to read a secret from a vault Versioned backend (kv2) for whatever reason running the debugger at that same place shows that HttpMessageConverterExtractor will not recognize SomeClass.class.

@SpringBootApplication
public class VaultdebugApplication {
    @Bean
    public Secrets secrets(VaultTemplate operations) {
        VaultResponseSupport<SomeClass> response = operations.read("some/vault/path", SomeClass.class);
        System.out.println(response.getRequiredData()); // results in null
        System.out.println(response.getData()); // results in null

        return null;
    }
    public static void main(String[] args) {
        SpringApplication.run(VaultdebugApplication.class, args);
    }
}

image

in fact you can even see that - whatever is passed into Type responseType field isn't a class but an instance of VaultResponses.

mp911de commented 1 year ago

Would you mind providing a complete minimal reproducer along with the data structures present in Vault so we can debug the issue on our own?