Skip to content

Commit 480a295

Browse files
committed
Refine logging on revocation failures.
We now log token accessors if a token revocation has failed. Closes gh-766
1 parent aeaf571 commit 480a295

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

spring-vault-core/src/main/java/org/springframework/vault/authentication/LifecycleAwareSessionManager.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.scheduling.TaskScheduler;
2525
import org.springframework.util.Assert;
2626
import org.springframework.util.ClassUtils;
27+
import org.springframework.util.StringUtils;
2728
import org.springframework.vault.VaultException;
2829
import org.springframework.vault.authentication.event.*;
2930
import org.springframework.vault.client.VaultHttpHeaders;
@@ -167,7 +168,14 @@ protected void revoke(VaultToken token) {
167168
dispatch(new AfterLoginTokenRevocationEvent(token));
168169
}
169170
catch (RuntimeException e) {
170-
this.logger.warn(String.format("Cannot revoke VaultToken: %s", token.getToken()), e);
171+
if (LoginToken.hasAccessor(token)) {
172+
this.logger.warn(
173+
String.format("Cannot revoke VaultToken with accessor: %s", ((LoginToken) token).getAccessor()),
174+
e);
175+
}
176+
else {
177+
this.logger.warn("Cannot revoke VaultToken", e);
178+
}
171179
dispatch(new LoginTokenRevocationFailedEvent(token, e));
172180
}
173181
}

spring-vault-core/src/main/java/org/springframework/vault/authentication/LoginToken.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
import java.time.Duration;
1919
import java.util.Arrays;
2020

21+
import org.apache.commons.logging.Log;
22+
2123
import org.springframework.lang.Nullable;
2224
import org.springframework.util.Assert;
25+
import org.springframework.util.StringUtils;
2326
import org.springframework.vault.support.VaultToken;
2427

2528
/**
@@ -202,6 +205,10 @@ public static LoginToken renewable(char[] token, Duration leaseDuration) {
202205
return new LoginToken(token, leaseDuration, true, null, null);
203206
}
204207

208+
static boolean hasAccessor(VaultToken token) {
209+
return token instanceof LoginToken && StringUtils.hasText(((LoginToken) token).getAccessor());
210+
}
211+
205212
/**
206213
* @return the lease duration in seconds. May be {@literal 0} if none.
207214
*/

spring-vault-core/src/main/java/org/springframework/vault/authentication/ReactiveLifecycleAwareSessionManager.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.scheduling.TaskScheduler;
2727
import org.springframework.util.Assert;
2828
import org.springframework.util.ClassUtils;
29+
import org.springframework.util.StringUtils;
2930
import org.springframework.vault.VaultException;
3031
import org.springframework.vault.authentication.event.*;
3132
import org.springframework.vault.client.VaultHttpHeaders;
@@ -168,19 +169,23 @@ protected Mono<Void> revoke(VaultToken token) {
168169
}).retrieve().bodyToMono(String.class)
169170
.doOnSubscribe(ignore -> dispatch(new BeforeLoginTokenRevocationEvent(token)))
170171
.doOnNext(ignore -> dispatch(new AfterLoginTokenRevocationEvent(token)))
171-
.onErrorResume(WebClientResponseException.class, e -> {
172+
.onErrorResume(WebClientResponseException.class, e -> onRevokeFailed(token, e))
173+
.onErrorResume(Exception.class, e -> onRevokeFailed(token, e)).then();
174+
}
172175

173-
this.logger.warn(format("Could not revoke token", e));
174-
dispatch(new LoginTokenRevocationFailedEvent(token, e));
176+
private Mono<String> onRevokeFailed(VaultToken token, Throwable e) {
175177

176-
return Mono.empty();
177-
}).onErrorResume(Exception.class, e -> {
178+
if (LoginToken.hasAccessor(token)) {
179+
this.logger.warn(
180+
String.format("Cannot revoke VaultToken with accessor: %s", ((LoginToken) token).getAccessor()), e);
181+
}
182+
else {
183+
this.logger.warn("Cannot revoke VaultToken", e);
184+
}
178185

179-
this.logger.warn("Could not revoke token", e);
180-
dispatch(new LoginTokenRevocationFailedEvent(token, e));
186+
dispatch(new LoginTokenRevocationFailedEvent(token, e));
181187

182-
return Mono.empty();
183-
}).then();
188+
return Mono.empty();
184189
}
185190

186191
/**

0 commit comments

Comments
 (0)