Polishing
Pass token in auth/token/… within the POST body instead of using the URL. See gh-336. Original pull request: gh-337.
This commit is contained in:
@@ -72,7 +72,7 @@ public interface VaultTokenOperations {
|
||||
* @param vaultToken must not be {@literal null}.
|
||||
* @return a {@link VaultTokenResponse}
|
||||
* @see <a href="https://www.vaultproject.io/docs/auth/token.html">POST
|
||||
* /auth/token/renew/{token}</a>
|
||||
* /auth/token/renew</a>
|
||||
*/
|
||||
VaultTokenResponse renew(VaultToken vaultToken);
|
||||
|
||||
@@ -81,7 +81,7 @@ public interface VaultTokenOperations {
|
||||
*
|
||||
* @param vaultToken must not be {@literal null}.
|
||||
* @see <a href="https://www.vaultproject.io/docs/auth/token.html">POST
|
||||
* /auth/token/revoke/{token}</a>
|
||||
* /auth/token/revoke</a>
|
||||
*/
|
||||
void revoke(VaultToken vaultToken);
|
||||
|
||||
@@ -90,7 +90,7 @@ public interface VaultTokenOperations {
|
||||
*
|
||||
* @param vaultToken must not be {@literal null}.
|
||||
* @see <a href="https://www.vaultproject.io/docs/auth/token.html">POST
|
||||
* /auth/token/revoke-orphan/{token}</a>
|
||||
* /auth/token/revoke-orphan</a>
|
||||
*/
|
||||
void revokeOrphan(VaultToken vaultToken);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.vault.core;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -80,9 +82,7 @@ public class VaultTokenTemplate implements VaultTokenOperations {
|
||||
|
||||
Assert.notNull(vaultToken, "VaultToken must not be null");
|
||||
|
||||
return writeAndReturn(
|
||||
String.format("auth/token/renew/%s", vaultToken.getToken()), null,
|
||||
VaultTokenResponse.class);
|
||||
return writeAndReturn("auth/token/renew", vaultToken, VaultTokenResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,8 +90,7 @@ public class VaultTokenTemplate implements VaultTokenOperations {
|
||||
|
||||
Assert.notNull(vaultToken, "VaultToken must not be null");
|
||||
|
||||
write(String.format("auth/token/revoke/%s", vaultToken.getToken()),
|
||||
VaultTokenResponse.class);
|
||||
writeToken("auth/token/revoke", vaultToken, VaultTokenResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,8 +98,7 @@ public class VaultTokenTemplate implements VaultTokenOperations {
|
||||
|
||||
Assert.notNull(vaultToken, "VaultToken must not be null");
|
||||
|
||||
write(String.format("auth/token/revoke-orphan/%s", vaultToken.getToken()),
|
||||
VaultTokenResponse.class);
|
||||
writeToken("auth/token/revoke-orphan", vaultToken, VaultTokenResponse.class);
|
||||
}
|
||||
|
||||
private <T extends VaultResponseSupport<?>> T writeAndReturn(String path,
|
||||
@@ -126,21 +124,23 @@ public class VaultTokenTemplate implements VaultTokenOperations {
|
||||
return response;
|
||||
}
|
||||
|
||||
private void write(String path, Class<?> responseType) {
|
||||
@Nullable
|
||||
private void writeToken(String path, VaultToken token, Class<?> responseType) {
|
||||
|
||||
Assert.hasText(path, "Path must not be empty");
|
||||
|
||||
vaultOperations.doWithSession(restOperations -> {
|
||||
|
||||
try {
|
||||
restOperations.exchange(path, HttpMethod.POST, HttpEntity.EMPTY,
|
||||
restOperations.exchange(path, HttpMethod.POST, new HttpEntity<>(
|
||||
Collections.singletonMap("token", token.getToken())),
|
||||
responseType);
|
||||
|
||||
return null;
|
||||
}
|
||||
catch (HttpStatusCodeException e) {
|
||||
throw VaultResponses.buildException(e, path);
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user