@Service @Singleton public class AuthTokenManager extends Object
Some DAS commands submit admin commands to be run elsewhere - either in another process on the same host or, via ssh, to another host. Given that it is already executing, the DAS command in progress has already been authenticated (if required). Therefore we want the soon-to-be submitted commands to also be authenticated, but we do not want to send the username and/or password information that was used to authenticate the currently-running DAS command to the other process for it to use.
Instead, the currently-running DAS command can use this service to obtain a one-time authentication token. The DAS command then includes the token, rather than username/password credentials, in the submitted command.
This service records which tokens have been given out but not yet used up. When an admin request arrives with a token, the AdminAdapter consults this service to see if the token is valid and, if so, the AdminAdapter allows the request to run.
We allow each token to be used twice, once for retrieving the command metadata and then the second time to execute the command. (Also see the note below.)
Tokens have a limited life as measured in time also. If a token is created but not fully consumed before it expires, then this manager considers the token invalid and removes it from the collection of known valid tokens. NOTE Commands that trigger other commands on multiple hosts - such as start-cluster - will need to reuse the authentication token more than twice. For such purposes the code using the token can append a "+" to the token. When such a token is used, this manager does NOT decrement the remaining number of uses. Rather, it only refreshes the token's expiration time.
| Modifier and Type | Field and Description |
|---|---|
static String |
AUTH_TOKEN_OPTION_NAME |
| Constructor and Description |
|---|
AuthTokenManager() |
| Modifier and Type | Method and Description |
|---|---|
Subject |
consumeToken(String token)
Records the use of an authentication token by an admin request.
|
String |
createToken()
Creates a new limited use authentication token with the default
lifetime.
|
String |
createToken(long lifetime)
Creates a new limited use authentication token with the specified
lifetime but no Subject.
|
String |
createToken(Subject subject)
Creates a new limited use authentication token with the given Subject
and the default lifetime.
|
String |
createToken(Subject subject,
long lifetime)
Creates a new limited use authentication token with the specified
lifetime (in ms).
|
Subject |
findToken(String token)
Locates the Subject for the specified token (if any) without consuming
the token.
|
static String |
markTokenForReuse(String token) |
Subject |
subject(String token) |
public static final String AUTH_TOKEN_OPTION_NAME
public String createToken(Subject subject, long lifetime)
subject - the Subject to associate with this token when it is consumedlifetime - how long each use of the token extends its lifetimepublic String createToken()
public String createToken(Subject subject)
subject - the Subject to associated with this token when it is consumedpublic String createToken(long lifetime)
lifetime - how long each use of the token extends its lifetimepublic Subject findToken(String token)
Use this method only from authentication logic that needs to find the token. Later command processing will consume the token if it is present. This avoids having to force the special admin LoginModule to run even if username/password authentication works.
token - the token to findpublic Subject consumeToken(String token)
Just to make it easier for callers, the token value can have any number of trailing reuse markers. This simplifies the code in RemoteAdminCommand which actually sends two requests for each command: one to retrieve metadata and one to execute the command. It might be that the command itself might be reusing the token, in which case it will already have appened a reuse marker to it. Then the code which sends the metadata request can freely append the marker again without having to check if it is already present.
token - the token consumed, with 0 or more cppies of the reuse marker appendedCopyright © 2017–2020 Eclipse Foundation. All rights reserved.