org.glassfish.common.util.admin
Class AuthTokenManager

java.lang.Object
  extended by org.glassfish.common.util.admin.AuthTokenManager

@Service
@Scoped(value=org.jvnet.hk2.component.Singleton.class)
public class AuthTokenManager
extends java.lang.Object

Coordinates generation and consumption of very-limited-use authentication tokens.

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.

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.

Author:
Tim Quinn

Field Summary
static java.lang.String AUTH_TOKEN_OPTION_NAME
           
 
Constructor Summary
AuthTokenManager()
           
 
Method Summary
 boolean consumeToken(java.lang.String token)
          Records the use of an authentication token by an admin request.
 java.lang.String createToken()
          Creates a new limited use authentication token.
static java.lang.String markTokenForReuse(java.lang.String token)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUTH_TOKEN_OPTION_NAME

public static final java.lang.String AUTH_TOKEN_OPTION_NAME
See Also:
Constant Field Values
Constructor Detail

AuthTokenManager

public AuthTokenManager()
Method Detail

createToken

public java.lang.String createToken()
Creates a new limited use authentication token.

Returns:
auth token

consumeToken

public boolean consumeToken(java.lang.String token)
Records the use of an authentication token by an admin request.

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.

Parameters:
token - the token consumed, with 0 or more cppies of the reuse marker appended
Returns:
true if the token was valid (and had remaining uses on it); false otherwise

markTokenForReuse

public static java.lang.String markTokenForReuse(java.lang.String token)


Copyright © 2012 GlassFish Community. All Rights Reserved.