Class KeycloakTokenRepository
- All Implemented Interfaces:
TokenProvider
This implementation fetches actual tokens from a Keycloak authentication server, making it suitable for integration benchmarks that need to test against real authentication infrastructure.
Features:
- Fetches tokens from Keycloak using password grant
- Maintains a pool of tokens for rotation
- Supports SSL verification configuration
- Provides round-robin token distribution
- Author:
- Oliver Wolff
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCustom exception for token fetch errors. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new KeycloakTokenRepository with the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionGets the next token from the provider.intReturns the current size of the token pool.voidRefreshes the token pool with new tokens.
-
Constructor Details
-
KeycloakTokenRepository
Creates a new KeycloakTokenRepository with the given configuration.- Parameters:
config- the configuration for connecting to Keycloak
-
-
Method Details
-
getNextToken
Gets the next token from the provider.Implementations should provide round-robin or similar rotation strategy to ensure even distribution of tokens and realistic cache behavior.
Gets the next token from the pool using round-robin rotation. This ensures even distribution and simulates cache miss scenarios. If the pool is empty, fetches a single token directly from Keycloak.
- Specified by:
getNextTokenin interfaceTokenProvider- Returns:
- a valid JWT access token
-
getTokenPoolSize
Returns the current size of the token pool.This method is useful for monitoring and capacity planning during benchmarks.
Returns the current size of the token pool.
- Specified by:
getTokenPoolSizein interfaceTokenProvider- Returns:
- the number of tokens currently available in the pool
-
refreshTokens
Refreshes the token pool with new tokens.This method allows for token renewal during long-running benchmarks. Implementations may choose to:
- Generate new tokens (mock implementations)
- Fetch fresh tokens from authentication server (real implementations)
- Do nothing if token refresh is not supported
Refreshes the token pool by fetching new tokens from Keycloak. This replaces all existing tokens in the pool with fresh ones.
- Specified by:
refreshTokensin interfaceTokenProvider- Throws:
KeycloakTokenRepository.TokenFetchException- if unable to fetch new tokens from Keycloak
-