Example usage for org.springframework.vault.core RestOperationsCallback RestOperationsCallback

List of usage examples for org.springframework.vault.core RestOperationsCallback RestOperationsCallback

Introduction

In this page you can find the example usage for org.springframework.vault.core RestOperationsCallback RestOperationsCallback.

Prototype

RestOperationsCallback

Source Link

Usage

From source file:example.helloworld.CubbyholeAuthenticationTests.java

/**
 * Write some data to Vault before Vault can be used as {@link VaultPropertySource}.
 *///from   w ww  .  j  a v a  2s . co m
@BeforeClass
public static void beforeClass() {

    VaultOperations vaultOperations = new VaultTestConfiguration().vaultTemplate();
    vaultOperations.write("secret/myapp/configuration", Collections.singletonMap("configuration.key", "value"));

    VaultResponse response = vaultOperations.doWithSession(new RestOperationsCallback<VaultResponse>() {

        @Override
        public VaultResponse doWithRestOperations(RestOperations restOperations) {

            HttpHeaders headers = new HttpHeaders();
            headers.add("X-Vault-Wrap-TTL", "10m");

            return restOperations.postForObject("auth/token/create", new HttpEntity<Object>(headers),
                    VaultResponse.class);
        }
    });

    // Response Wrapping requires Vault 0.6.0+
    Map<String, String> wrapInfo = response.getWrapInfo();
    initialToken = VaultToken.of(wrapInfo.get("token"));
}