Class TokenService
java.lang.Object
org.elasticsearch.xpack.security.authc.TokenService
Service responsible for the creation, validation, and other management of
UserToken
objects for authentication-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.elasticsearch.common.settings.Setting<org.elasticsearch.core.TimeValue>static final org.elasticsearch.common.settings.Setting<org.elasticsearch.core.TimeValue>static final intstatic final Stringstatic final org.elasticsearch.common.settings.Setting<org.elasticsearch.core.TimeValue> -
Constructor Summary
ConstructorsConstructorDescriptionTokenService(org.elasticsearch.common.settings.Settings settings, Clock clock, org.elasticsearch.client.internal.Client client, org.elasticsearch.license.XPackLicenseState licenseState, org.elasticsearch.xpack.core.security.SecurityContext securityContext, SecurityIndexManager securityMainIndex, SecurityIndexManager securityTokensIndex, org.elasticsearch.cluster.service.ClusterService clusterService) Creates a new token service -
Method Summary
Modifier and TypeMethodDescriptionvoidauthenticateToken(org.elasticsearch.common.settings.SecureString tokenString, org.elasticsearch.action.ActionListener<org.elasticsearch.xpack.core.security.authc.Authentication> listener) Decodes the provided token, and validates it (for format, expiry and invalidation).voidcreateOAuth2Tokens(String accessToken, String refreshToken, org.elasticsearch.xpack.core.security.authc.Authentication authentication, org.elasticsearch.xpack.core.security.authc.Authentication originatingClientAuth, Map<String, Object> metadata, org.elasticsearch.action.ActionListener<TokenService.CreateTokenResult> listener) Creates an access token and optionally a refresh token as well from predefined values, based on the provided authentication and metadata.voidcreateOAuth2Tokens(org.elasticsearch.xpack.core.security.authc.Authentication authentication, org.elasticsearch.xpack.core.security.authc.Authentication originatingClientAuth, Map<String, Object> metadata, boolean includeRefreshToken, org.elasticsearch.action.ActionListener<TokenService.CreateTokenResult> listener) Creates an access token and optionally a refresh token as well, based on the provided authentication and metadata with auto-generated values.voidfindActiveTokensForRealm(String realmName, Predicate<Map<String, Object>> filter, org.elasticsearch.action.ActionListener<Collection<org.elasticsearch.core.Tuple<UserToken, String>>> listener) Find stored refresh and access tokens that have not been invalidated or expired, and were issued against the specified realm.voidfindActiveTokensForUser(String username, org.elasticsearch.action.ActionListener<Collection<org.elasticsearch.core.Tuple<UserToken, String>>> listener) Find stored refresh and access tokens that have not been invalidated or expired, and were issued for the specified user.voidgetAuthenticationAndMetadata(String token, org.elasticsearch.action.ActionListener<org.elasticsearch.core.Tuple<org.elasticsearch.xpack.core.security.authc.Authentication, Map<String, Object>>> listener) Reads the authentication and metadata from the given token.org.elasticsearch.core.TimeValueorg.elasticsearch.xpack.core.security.authc.TokenMetadataReturns the current in-use metdata of thisTokenServicestatic StringhashTokenString(String accessTokenString) Hashes an access or refresh token String so that it can safely be persisted in the index.voidinvalidateAccessToken(String accessToken, org.elasticsearch.action.ActionListener<org.elasticsearch.xpack.core.security.authc.support.TokensInvalidationResult> listener) This method performs the steps necessary to invalidate an access token so that it may no longer be used.voidinvalidateAccessToken(UserToken userToken, org.elasticsearch.action.ActionListener<org.elasticsearch.xpack.core.security.authc.support.TokensInvalidationResult> listener) This method performs the steps necessary to invalidate a token so that it may no longer be used.voidinvalidateActiveTokensForRealmAndUser(String realmName, String username, org.elasticsearch.action.ActionListener<org.elasticsearch.xpack.core.security.authc.support.TokensInvalidationResult> listener) Invalidates all access tokens and all refresh tokens of a givenrealmNameand/or of a givenusernameso that they may no longer be usedvoidinvalidateRefreshToken(String refreshToken, org.elasticsearch.action.ActionListener<org.elasticsearch.xpack.core.security.authc.support.TokensInvalidationResult> listener) This method invalidates a refresh token so that it may no longer be used.static BooleanisTokenServiceEnabled(org.elasticsearch.common.settings.Settings settings) static StringprependVersionAndEncodeRefreshToken(org.elasticsearch.Version version, String payload) voidrefreshToken(String refreshToken, org.elasticsearch.action.ActionListener<TokenService.CreateTokenResult> listener) Called by the transport action in order to start the process of refreshing a token.static org.elasticsearch.core.Tuple<org.elasticsearch.Version,String> unpackVersionAndPayload(String encodedPack) Unpacks a base64 encoded pair of a version tag and String payload.
-
Field Details
-
THREAD_POOL_NAME
- See Also:
-
TOKEN_EXPIRATION
public static final org.elasticsearch.common.settings.Setting<org.elasticsearch.core.TimeValue> TOKEN_EXPIRATION -
DELETE_INTERVAL
public static final org.elasticsearch.common.settings.Setting<org.elasticsearch.core.TimeValue> DELETE_INTERVAL -
DELETE_TIMEOUT
public static final org.elasticsearch.common.settings.Setting<org.elasticsearch.core.TimeValue> DELETE_TIMEOUT -
MINIMUM_BASE64_BYTES
public static final int MINIMUM_BASE64_BYTES
-
-
Constructor Details
-
TokenService
public TokenService(org.elasticsearch.common.settings.Settings settings, Clock clock, org.elasticsearch.client.internal.Client client, org.elasticsearch.license.XPackLicenseState licenseState, org.elasticsearch.xpack.core.security.SecurityContext securityContext, SecurityIndexManager securityMainIndex, SecurityIndexManager securityTokensIndex, org.elasticsearch.cluster.service.ClusterService clusterService) throws GeneralSecurityException Creates a new token service- Throws:
GeneralSecurityException
-
-
Method Details
-
createOAuth2Tokens
public void createOAuth2Tokens(org.elasticsearch.xpack.core.security.authc.Authentication authentication, org.elasticsearch.xpack.core.security.authc.Authentication originatingClientAuth, Map<String, Object> metadata, boolean includeRefreshToken, org.elasticsearch.action.ActionListener<TokenService.CreateTokenResult> listener) Creates an access token and optionally a refresh token as well, based on the provided authentication and metadata with auto-generated values. The created tokens are stored in the security index for versions up toVERSION_TOKENS_INDEX_INTRODUCEDand to a specific security tokens index for later versions. -
createOAuth2Tokens
public void createOAuth2Tokens(String accessToken, String refreshToken, org.elasticsearch.xpack.core.security.authc.Authentication authentication, org.elasticsearch.xpack.core.security.authc.Authentication originatingClientAuth, Map<String, Object> metadata, org.elasticsearch.action.ActionListener<TokenService.CreateTokenResult> listener) Creates an access token and optionally a refresh token as well from predefined values, based on the provided authentication and metadata. The created tokens are stored in the security index for versions up toVERSION_TOKENS_INDEX_INTRODUCEDand to a specific security tokens index for later versions. -
hashTokenString
Hashes an access or refresh token String so that it can safely be persisted in the index. We don't salt the values as these are v4 UUIDs that have enough entropy by themselves. -
authenticateToken
public void authenticateToken(org.elasticsearch.common.settings.SecureString tokenString, org.elasticsearch.action.ActionListener<org.elasticsearch.xpack.core.security.authc.Authentication> listener) Decodes the provided token, and validates it (for format, expiry and invalidation). If valid, the token'sAuthentication(seeUserToken.getAuthentication()is provided to the listener. If the token is invalid (expired etc), thenActionListener.onFailure(Exception)will be called. If tokens are not enabled, or the token does not exist,ActionListener.onResponse(Response)will be called with anullauthentication object. -
getAuthenticationAndMetadata
public void getAuthenticationAndMetadata(String token, org.elasticsearch.action.ActionListener<org.elasticsearch.core.Tuple<org.elasticsearch.xpack.core.security.authc.Authentication, Map<String, Object>>> listener) Reads the authentication and metadata from the given token. This method does not validate whether the token is expired or not. -
invalidateAccessToken
public void invalidateAccessToken(String accessToken, org.elasticsearch.action.ActionListener<org.elasticsearch.xpack.core.security.authc.support.TokensInvalidationResult> listener) This method performs the steps necessary to invalidate an access token so that it may no longer be used. The process of invalidation involves performing an update to the token document and setting theaccess_token.invalidatedfield totrue -
invalidateAccessToken
public void invalidateAccessToken(UserToken userToken, org.elasticsearch.action.ActionListener<org.elasticsearch.xpack.core.security.authc.support.TokensInvalidationResult> listener) This method performs the steps necessary to invalidate a token so that it may no longer be used. -
invalidateRefreshToken
public void invalidateRefreshToken(String refreshToken, org.elasticsearch.action.ActionListener<org.elasticsearch.xpack.core.security.authc.support.TokensInvalidationResult> listener) This method invalidates a refresh token so that it may no longer be used. Invalidation involves performing an update to the token document and setting therefresh_token.invalidatedfield totrue- Parameters:
refreshToken- The string representation of the refresh tokenlistener- the listener to notify upon completion
-
invalidateActiveTokensForRealmAndUser
public void invalidateActiveTokensForRealmAndUser(@Nullable String realmName, @Nullable String username, org.elasticsearch.action.ActionListener<org.elasticsearch.xpack.core.security.authc.support.TokensInvalidationResult> listener) Invalidates all access tokens and all refresh tokens of a givenrealmNameand/or of a givenusernameso that they may no longer be used- Parameters:
realmName- the realm of which the tokens should be invalidatedusername- the username for which the tokens should be invalidatedlistener- the listener to notify upon completion
-
refreshToken
public void refreshToken(String refreshToken, org.elasticsearch.action.ActionListener<TokenService.CreateTokenResult> listener) Called by the transport action in order to start the process of refreshing a token.- Parameters:
refreshToken- The refresh token as provided by the clientlistener- The listener to call upon completion with aTokenService.CreateTokenResultcontaining the serialized access token, serialized refresh token and authentication for which the token is created as these will be returned to the client
-
isTokenServiceEnabled
-
findActiveTokensForRealm
public void findActiveTokensForRealm(String realmName, @Nullable Predicate<Map<String, Object>> filter, org.elasticsearch.action.ActionListener<Collection<org.elasticsearch.core.Tuple<UserToken, String>>> listener) Find stored refresh and access tokens that have not been invalidated or expired, and were issued against the specified realm.- Parameters:
realmName- The name of the realm for which to get the tokensfilter- an optional Predicate to test the source of the found documents againstlistener- The listener to notify upon completion
-
findActiveTokensForUser
public void findActiveTokensForUser(String username, org.elasticsearch.action.ActionListener<Collection<org.elasticsearch.core.Tuple<UserToken, String>>> listener) Find stored refresh and access tokens that have not been invalidated or expired, and were issued for the specified user.- Parameters:
username- The user for which to get the tokenslistener- The listener to notify upon completion
-
getExpirationDelay
public org.elasticsearch.core.TimeValue getExpirationDelay() -
prependVersionAndEncodeRefreshToken
-
unpackVersionAndPayload
public static org.elasticsearch.core.Tuple<org.elasticsearch.Version,String> unpackVersionAndPayload(String encodedPack) throws IOException Unpacks a base64 encoded pair of a version tag and String payload.- Throws:
IOException
-
getTokenMetadata
public org.elasticsearch.xpack.core.security.authc.TokenMetadata getTokenMetadata()Returns the current in-use metdata of thisTokenService
-