data) {
if (options.isWrappedToken()) {
- VaultResponse response = vaultClient.unwrap((String) data.get("response"),
+ VaultResponse response = VaultResponses.unwrap((String) data.get("response"),
VaultResponse.class);
return LoginTokenUtil.from(response.getAuth());
}
@@ -175,7 +187,7 @@ public class CubbyholeAuthentication implements ClientAuthentication {
throw new VaultException(
String.format(
"Cannot retrieve Token from cubbyhole: Response at %s does not contain a token",
- entity.getUri()));
+ options.getPath()));
}
if (data.size() == 1) {
@@ -186,6 +198,6 @@ public class CubbyholeAuthentication implements ClientAuthentication {
throw new VaultException(
String.format(
"Cannot retrieve Token from cubbyhole: Response at %s does not contain an unique token",
- entity.getUri()));
+ options.getPath()));
}
}
diff --git a/spring-vault-core/src/main/java/org/springframework/vault/authentication/CubbyholeAuthenticationOptions.java b/spring-vault-core/src/main/java/org/springframework/vault/authentication/CubbyholeAuthenticationOptions.java
index 09a88ce8..95a89027 100644
--- a/spring-vault-core/src/main/java/org/springframework/vault/authentication/CubbyholeAuthenticationOptions.java
+++ b/spring-vault-core/src/main/java/org/springframework/vault/authentication/CubbyholeAuthenticationOptions.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2016-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@ import org.springframework.vault.support.VaultToken;
*
* Authentication options provide the path below cubbyhole and the cubbyhole mode.
* Instances of this class are immutable once constructed.
- *
+ *
* @author Mark Paluch
* @see CubbyholeAuthentication
* @see #builder()
@@ -99,7 +99,7 @@ public class CubbyholeAuthenticationOptions {
/**
* Configure the initial {@link VaultToken} to access Cubbyhole.
- *
+ *
* @param initialToken must not be {@literal null}.
* @return {@code this} {@link CubbyholeAuthenticationOptionsBuilder}.
*/
@@ -141,7 +141,7 @@ public class CubbyholeAuthenticationOptions {
/**
* Build a new {@link CubbyholeAuthenticationOptions} instance. Requires
* {@link #path(String)} or {@link #wrapped()} to be configured.
- *
+ *
* @return a new {@link CubbyholeAuthenticationOptions}.
*/
public CubbyholeAuthenticationOptions build() {
diff --git a/spring-vault-core/src/main/java/org/springframework/vault/authentication/LifecycleAwareSessionManager.java b/spring-vault-core/src/main/java/org/springframework/vault/authentication/LifecycleAwareSessionManager.java
index 9b8450a8..93b3ba3b 100644
--- a/spring-vault-core/src/main/java/org/springframework/vault/authentication/LifecycleAwareSessionManager.java
+++ b/spring-vault-core/src/main/java/org/springframework/vault/authentication/LifecycleAwareSessionManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2016-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,16 +25,19 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.core.task.AsyncTaskExecutor;
+import org.springframework.http.HttpEntity;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.TriggerContext;
import org.springframework.util.Assert;
import org.springframework.util.NumberUtils;
-import org.springframework.util.StringUtils;
-import org.springframework.vault.client.VaultClient;
-import org.springframework.vault.client.VaultException;
-import org.springframework.vault.client.VaultResponseEntity;
+import org.springframework.vault.VaultException;
+import org.springframework.vault.client.VaultHttpHeaders;
+import org.springframework.vault.client.VaultResponses;
import org.springframework.vault.support.VaultToken;
+import org.springframework.web.client.HttpStatusCodeException;
+import org.springframework.web.client.RestClientException;
+import org.springframework.web.client.RestOperations;
/**
* Lifecycle-aware Session Manager. This {@link SessionManager} obtains tokens from a
@@ -63,29 +66,32 @@ public class LifecycleAwareSessionManager implements SessionManager, DisposableB
.getLog(LifecycleAwareSessionManager.class);
private final ClientAuthentication clientAuthentication;
- private final VaultClient vaultClient;
+
+ private final RestOperations restOperations;
+
private final AsyncTaskExecutor taskExecutor;
+
private final Object lock = new Object();
private volatile VaultToken token;
/**
* Create a {@link LifecycleAwareSessionManager} given {@link ClientAuthentication},
- * {@link AsyncTaskExecutor} and {@link VaultClient}.
- *
+ * {@link AsyncTaskExecutor} and {@link RestOperations}.
+ *
* @param clientAuthentication must not be {@literal null}.
* @param taskExecutor must not be {@literal null}.
- * @param vaultClient must not be {@literal null}.
+ * @param restOperations must not be {@literal null}.
*/
public LifecycleAwareSessionManager(ClientAuthentication clientAuthentication,
- AsyncTaskExecutor taskExecutor, VaultClient vaultClient) {
+ AsyncTaskExecutor taskExecutor, RestOperations restOperations) {
Assert.notNull(clientAuthentication, "ClientAuthentication must not be null");
Assert.notNull(taskExecutor, "AsyncTaskExecutor must not be null");
- Assert.notNull(vaultClient, "VaultClient must not be null");
+ Assert.notNull(restOperations, "RestOperations must not be null");
this.clientAuthentication = clientAuthentication;
- this.vaultClient = vaultClient;
+ this.restOperations = restOperations;
this.taskExecutor = taskExecutor;
}
@@ -96,12 +102,14 @@ public class LifecycleAwareSessionManager implements SessionManager, DisposableB
this.token = null;
if (token instanceof LoginToken) {
- VaultResponseEntity