public class LifecycleAwareSessionManager extends Object implements SessionManager, org.springframework.beans.factory.DisposableBean
SessionManager obtains tokens from a
ClientAuthentication upon request. Tokens are
renewed asynchronously if a token has a lease duration. This happens 5 seconds before
the token expires, see REFRESH_PERIOD_BEFORE_EXPIRY.
This SessionManager also implements DisposableBean to revoke the
LoginToken once it's not required anymore. Token revocation will stop regular
token refresh. Tokens are only revoked only if the associated
ClientAuthentication returned a LoginToken.
If Token renewal runs into a client-side error, it assumes the token was revoked/expired and discards the token state so the next attempt will lead to another login attempt.
By default, VaultToken are looked up in Vault to determine renewability and the
remaining TTL, see setTokenSelfLookupEnabled(boolean).
LoginToken,
SessionManager,
AsyncTaskExecutor| Modifier and Type | Class and Description |
|---|---|
static class |
LifecycleAwareSessionManager.FixedTimeoutRefreshTrigger
LifecycleAwareSessionManager.RefreshTrigger implementation using a fixed timeout to schedule renewal
before a LoginToken expires. |
static interface |
LifecycleAwareSessionManager.RefreshTrigger
Common interface for trigger objects that determine the next execution time of a
refresh task that they get associated with.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
REFRESH_PERIOD_BEFORE_EXPIRY
Refresh 5 seconds before the token expires.
|
| Constructor and Description |
|---|
LifecycleAwareSessionManager(ClientAuthentication clientAuthentication,
org.springframework.scheduling.TaskScheduler taskScheduler,
org.springframework.web.client.RestOperations restOperations)
Create a
LifecycleAwareSessionManager given ClientAuthentication,
AsyncTaskExecutor and RestOperations. |
LifecycleAwareSessionManager(ClientAuthentication clientAuthentication,
org.springframework.scheduling.TaskScheduler taskScheduler,
org.springframework.web.client.RestOperations restOperations,
LifecycleAwareSessionManager.RefreshTrigger refreshTrigger)
Create a
LifecycleAwareSessionManager given ClientAuthentication,
AsyncTaskExecutor and RestOperations. |
| Modifier and Type | Method and Description |
|---|---|
void |
destroy() |
VaultToken |
getSessionToken()
Obtain a session token.
|
protected boolean |
isTokenRenewable() |
boolean |
isTokenSelfLookupEnabled()
Returns whether token self-lookup is enabled to augment
VaultToken obtained
from a ClientAuthentication. |
protected VaultToken |
login() |
protected boolean |
renewToken()
Performs a token refresh.
|
protected void |
revoke(VaultToken token)
Revoke a
VaultToken. |
void |
setTokenSelfLookupEnabled(boolean tokenSelfLookupEnabled)
Enables/disables token self-lookup.
|
public static final int REFRESH_PERIOD_BEFORE_EXPIRY
public LifecycleAwareSessionManager(ClientAuthentication clientAuthentication, org.springframework.scheduling.TaskScheduler taskScheduler, org.springframework.web.client.RestOperations restOperations)
LifecycleAwareSessionManager given ClientAuthentication,
AsyncTaskExecutor and RestOperations.clientAuthentication - must not be null.taskScheduler - must not be null.restOperations - must not be null.public LifecycleAwareSessionManager(ClientAuthentication clientAuthentication, org.springframework.scheduling.TaskScheduler taskScheduler, org.springframework.web.client.RestOperations restOperations, LifecycleAwareSessionManager.RefreshTrigger refreshTrigger)
LifecycleAwareSessionManager given ClientAuthentication,
AsyncTaskExecutor and RestOperations.clientAuthentication - must not be null.taskScheduler - must not be null.restOperations - must not be null.refreshTrigger - must not be null.public boolean isTokenSelfLookupEnabled()
VaultToken obtained
from a ClientAuthentication. Self-lookup determines whether a token is
renewable and its TTL. Self lookup is skipped for LoginToken. Self-lookup
requests decrement token usage count by one. Skipped for LoginToken.
Self-lookup for tokens without a permission to access
auth/token/lookup-self will fail gracefully and continue without token
renewal.public void setTokenSelfLookupEnabled(boolean tokenSelfLookupEnabled)
VaultToken
obtained from a ClientAuthentication. Self-lookup determines whether a
token is renewable and its TTL.tokenSelfLookupEnabled - true to enable self-lookup,
false to disable self-lookup. Enabled by default.public void destroy()
destroy in interface org.springframework.beans.factory.DisposableBeanprotected void revoke(VaultToken token)
VaultToken.token - the token to revoke, must not be null.protected boolean renewToken()
public VaultToken getSessionToken()
SessionManagergetSessionToken in interface SessionManagerprotected VaultToken login()
protected boolean isTokenRenewable()
Copyright © 2016–2017 Pivotal Software, Inc.. All rights reserved.