Allow dropping tokens from the session manager for easier recovery on lookup failures.
Closes gh-684
This commit is contained in:
@@ -25,7 +25,6 @@ import org.springframework.http.HttpEntity;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.vault.VaultException;
|
||||
import org.springframework.vault.authentication.event.*;
|
||||
import org.springframework.vault.client.VaultHttpHeaders;
|
||||
@@ -149,11 +148,18 @@ public class LifecycleAwareSessionManager extends LifecycleAwareSessionManagerSu
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
revoke();
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke and drop the current {@link VaultToken}.
|
||||
* @since 3.0.2
|
||||
*/
|
||||
public void revoke() {
|
||||
|
||||
Optional<TokenWrapper> token = getToken();
|
||||
setToken(Optional.empty());
|
||||
|
||||
token.filter(TokenWrapper::isRevocable).map(TokenWrapper::getToken).ifPresent(this::revoke);
|
||||
setToken(Optional.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.vault.VaultException;
|
||||
import org.springframework.vault.authentication.event.*;
|
||||
import org.springframework.vault.client.VaultHttpHeaders;
|
||||
@@ -145,6 +144,23 @@ public class ReactiveLifecycleAwareSessionManager extends LifecycleAwareSessionM
|
||||
revokeNow(tokenMono);
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke and drop the current {@link VaultToken}.
|
||||
* @return a mono emitting completion upon successful revocation.
|
||||
* @since 3.0.2
|
||||
*/
|
||||
public Mono<Void> revoke() {
|
||||
return doRevoke(this.token.get()).doOnSuccess(unused -> this.token.set(EMPTY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke and drop the current {@link VaultToken} now.
|
||||
* @since 3.0.2
|
||||
*/
|
||||
public void revokeNow() {
|
||||
revoke().block(Duration.ofSeconds(5));
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke a {@link VaultToken} now and block execution until revocation completes.
|
||||
* @param tokenMono
|
||||
|
||||
Reference in New Issue
Block a user