Unable to read vault properties

I have configured my spring application to use vault with authentication based on approle. I have disabled bootstrapping. Handling approle based authentication programmatically.

Following are the artifacts :

enter image description here

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>pom.xml :
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<spring-cloud.version>2023.0.2</spring-cloud.version>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-vault-config</artifactId>
</dependency>
</code>
<code>pom.xml : <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.2.3</version> <relativePath/> <!-- lookup parent from repository --> </parent> <spring-cloud.version>2023.0.2</spring-cloud.version> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-vault-config</artifactId> </dependency> </code>
pom.xml :
               
                 <parent>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>3.2.3</version>
                <relativePath/> <!-- lookup parent from repository -->
            </parent>
        <spring-cloud.version>2023.0.2</spring-cloud.version>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-vault-config</artifactId>
        </dependency>
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>bootstrap.properties :
spring.application.name=mnp
spring.cloud.vault.authentication=approle
spring.cloud.vault.uri=http://127.0.0.1:8200
spring.cloud.vault.kv.enabled=true
spring.cloud.vault.kv.backend=secret
</code>
<code>bootstrap.properties : spring.application.name=mnp spring.cloud.vault.authentication=approle spring.cloud.vault.uri=http://127.0.0.1:8200 spring.cloud.vault.kv.enabled=true spring.cloud.vault.kv.backend=secret </code>
bootstrap.properties :

spring.application.name=mnp
spring.cloud.vault.authentication=approle
spring.cloud.vault.uri=http://127.0.0.1:8200
spring.cloud.vault.kv.enabled=true
spring.cloud.vault.kv.backend=secret
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>package com.hello.vaultDemo;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.cloud.vault.config.SecretBackendConfigurer;
import org.springframework.cloud.vault.config.VaultConfigurer;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import org.springframework.vault.authentication.AppRoleAuthentication;
import org.springframework.vault.authentication.AppRoleAuthenticationOptions;
import org.springframework.vault.authentication.ClientAuthentication;
import org.springframework.vault.client.VaultEndpoint;
import org.springframework.vault.config.AbstractVaultConfiguration;
@Configuration("CustomVaultConfiguration")
public class CustomVaultConfiguration extends AbstractVaultConfiguration implements VaultConfigurer{
private static final Logger logger = LogManager.getLogger(CustomVaultConfiguration.class);
@Override
public VaultEndpoint vaultEndpoint() {
return VaultEndpoint.from("http://127.0.0.1:8200");
}
@Override
public ClientAuthentication clientAuthentication() {
try {
String roleId = "d8de84ad-k201-48eb-5e8c-3d502b3e7496";
String secretId = "e5d8f8a3-8adc-312b-3a09-e494b09e1995";
AppRoleAuthenticationOptions.AppRoleAuthenticationOptionsBuilder builder = AppRoleAuthenticationOptions.builder().roleId(AppRoleAuthenticationOptions.RoleId.provided(roleId)).path("approle");
if (StringUtils.hasText(secretId)) {
builder = builder.secretId(AppRoleAuthenticationOptions.SecretId.provided(secretId));
}
return new AppRoleAuthentication(builder.build(), this.restOperations());
}catch (Exception ex){
logger.info("exception occurred while vault configuration, msg - {}", ex.getMessage(), ex);
throw new Error("Failed to initialize vault!");
}
}
@Override
public void addSecretBackends(SecretBackendConfigurer configurer) {
configurer.add("secret/data/mnp");
}
}
</code>
<code>package com.hello.vaultDemo; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.cloud.vault.config.SecretBackendConfigurer; import org.springframework.cloud.vault.config.VaultConfigurer; import org.springframework.context.annotation.Configuration; import org.springframework.util.StringUtils; import org.springframework.vault.authentication.AppRoleAuthentication; import org.springframework.vault.authentication.AppRoleAuthenticationOptions; import org.springframework.vault.authentication.ClientAuthentication; import org.springframework.vault.client.VaultEndpoint; import org.springframework.vault.config.AbstractVaultConfiguration; @Configuration("CustomVaultConfiguration") public class CustomVaultConfiguration extends AbstractVaultConfiguration implements VaultConfigurer{ private static final Logger logger = LogManager.getLogger(CustomVaultConfiguration.class); @Override public VaultEndpoint vaultEndpoint() { return VaultEndpoint.from("http://127.0.0.1:8200"); } @Override public ClientAuthentication clientAuthentication() { try { String roleId = "d8de84ad-k201-48eb-5e8c-3d502b3e7496"; String secretId = "e5d8f8a3-8adc-312b-3a09-e494b09e1995"; AppRoleAuthenticationOptions.AppRoleAuthenticationOptionsBuilder builder = AppRoleAuthenticationOptions.builder().roleId(AppRoleAuthenticationOptions.RoleId.provided(roleId)).path("approle"); if (StringUtils.hasText(secretId)) { builder = builder.secretId(AppRoleAuthenticationOptions.SecretId.provided(secretId)); } return new AppRoleAuthentication(builder.build(), this.restOperations()); }catch (Exception ex){ logger.info("exception occurred while vault configuration, msg - {}", ex.getMessage(), ex); throw new Error("Failed to initialize vault!"); } } @Override public void addSecretBackends(SecretBackendConfigurer configurer) { configurer.add("secret/data/mnp"); } } </code>
package com.hello.vaultDemo;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.cloud.vault.config.SecretBackendConfigurer;
import org.springframework.cloud.vault.config.VaultConfigurer;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import org.springframework.vault.authentication.AppRoleAuthentication;
import org.springframework.vault.authentication.AppRoleAuthenticationOptions;
import org.springframework.vault.authentication.ClientAuthentication;
import org.springframework.vault.client.VaultEndpoint;
import org.springframework.vault.config.AbstractVaultConfiguration;


@Configuration("CustomVaultConfiguration")
public class CustomVaultConfiguration extends AbstractVaultConfiguration implements  VaultConfigurer{
    private static final Logger logger = LogManager.getLogger(CustomVaultConfiguration.class);

    @Override
    public VaultEndpoint vaultEndpoint() {
        return VaultEndpoint.from("http://127.0.0.1:8200");
    }

    @Override
    public ClientAuthentication clientAuthentication() {
        try {
            String roleId = "d8de84ad-k201-48eb-5e8c-3d502b3e7496";
            String secretId = "e5d8f8a3-8adc-312b-3a09-e494b09e1995";
            AppRoleAuthenticationOptions.AppRoleAuthenticationOptionsBuilder builder = AppRoleAuthenticationOptions.builder().roleId(AppRoleAuthenticationOptions.RoleId.provided(roleId)).path("approle");
            if (StringUtils.hasText(secretId)) {
                builder = builder.secretId(AppRoleAuthenticationOptions.SecretId.provided(secretId));
            }
            return new AppRoleAuthentication(builder.build(), this.restOperations());
        }catch (Exception ex){
            logger.info("exception occurred while vault configuration, msg - {}", ex.getMessage(), ex);
            throw new Error("Failed to initialize vault!");
        }
    }

    @Override
    public void addSecretBackends(SecretBackendConfigurer configurer) {
        configurer.add("secret/data/mnp");
    }
}
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>package com.hello.vaultDemo;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.vault.core.VaultTemplate;
import org.springframework.vault.support.VaultResponse;
@Component
public class test {
@Value("${one:null}")
String onee;
@Value("${two:null}")
String twoo;
@Autowired
VaultTemplate vaultTemplate;
@Autowired
Environment environment;
@PostConstruct
public void init() {
VaultResponse response = vaultTemplate.read("secret/data/mnp");
System.out.println("response - "+ response.getData());
System.out.println("onee - "+ onee);
System.out.println("twoo - "+ twoo);
System.out.println("one "+environment.getProperty("one"));
}
}
OUTPUT :
response - {data={one=1, three=3, two=2}, metadata={created_time=2024-06-18T04:05:58.519111Z, custom_metadata=null, deletion_time=, destroyed=false, version=1}}
onee - null
twoo - null
one null
</code>
<code>package com.hello.vaultDemo; import jakarta.annotation.PostConstruct; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; import org.springframework.vault.core.VaultTemplate; import org.springframework.vault.support.VaultResponse; @Component public class test { @Value("${one:null}") String onee; @Value("${two:null}") String twoo; @Autowired VaultTemplate vaultTemplate; @Autowired Environment environment; @PostConstruct public void init() { VaultResponse response = vaultTemplate.read("secret/data/mnp"); System.out.println("response - "+ response.getData()); System.out.println("onee - "+ onee); System.out.println("twoo - "+ twoo); System.out.println("one "+environment.getProperty("one")); } } OUTPUT : response - {data={one=1, three=3, two=2}, metadata={created_time=2024-06-18T04:05:58.519111Z, custom_metadata=null, deletion_time=, destroyed=false, version=1}} onee - null twoo - null one null </code>
package com.hello.vaultDemo;

import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.vault.core.VaultTemplate;
import org.springframework.vault.support.VaultResponse;


@Component
public class test {
    @Value("${one:null}")
    String onee;

    @Value("${two:null}")
    String twoo;

    @Autowired
    VaultTemplate vaultTemplate;

    @Autowired
    Environment environment;

    @PostConstruct
    public void init() {
        VaultResponse response = vaultTemplate.read("secret/data/mnp");
        System.out.println("response - "+ response.getData());
        System.out.println("onee - "+ onee);
        System.out.println("twoo - "+ twoo);

        System.out.println("one "+environment.getProperty("one"));
    }
}


OUTPUT :

response - {data={one=1, three=3, two=2}, metadata={created_time=2024-06-18T04:05:58.519111Z, custom_metadata=null, deletion_time=, destroyed=false, version=1}}
onee - null
twoo - null
one null

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code></code>
<code></code>

application is able to access properties through vaulttemplate.read() method. How can i access properties using @Value or environment bean.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật