List of usage examples for org.springframework.vault.support VaultToken of
public static VaultToken of(char[] token)
From source file:example.helloworld.CubbyholeAuthenticationTests.java
/** * Write some data to Vault before Vault can be used as {@link VaultPropertySource}. *///from www . j ava2 s .com @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")); }
From source file:org.springframework.vault.authentication.CubbyholeAuthentication.java
private VaultToken getToken(VaultResponseEntity<VaultResponse> entity, Map<String, Object> data) { if (options.isWrappedToken()) { VaultResponse response = vaultClient.unwrap((String) data.get("response"), VaultResponse.class); return LoginTokenUtil.from(response.getAuth()); }// w ww . j av a 2 s .c om if (data == null || data.isEmpty()) { throw new VaultException( String.format("Cannot retrieve Token from cubbyhole: Response at %s does not contain a token", entity.getUri())); } if (data.size() == 1) { String token = (String) data.get(data.keySet().iterator().next()); return VaultToken.of(token); } throw new VaultException(String.format( "Cannot retrieve Token from cubbyhole: Response at %s does not contain an unique token", entity.getUri())); }