Class AccessTokenProvider
java.lang.Object
ai.timefold.solver.tools.maven.AccessTokenProvider
Resolves the personal access token that authenticates the build against Timefold Platform, either from the
environment, or from a
<server> entry of the Maven settings.
The latter exists so that the token does not have to be exported into every shell the build runs in, without having
to keep it in clear text on disk either: it is stored the same way as any other Maven credential, encrypted with
mvn --encrypt-password and decrypted here through Maven's own SettingsDecrypter.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedOnly meant for test doubles, which overridegetAccessToken()and therefore never read either source.AccessTokenProvider(org.apache.maven.settings.Settings settings, org.apache.maven.settings.crypto.SettingsDecrypter settingsDecrypter, String serverId, org.apache.maven.plugin.logging.Log log) -
Method Summary
Modifier and TypeMethodDescriptionThe environment takes precedence, so that a build which already exports the token, typically on CI, keeps authenticating with it even when the machine also has a server entry configured.The id of the<server>entry that is actually read, i.e. the configured one once normalized, or the default when the build configures none.protected StringOverridable so that tests do not have to change the environment of the process they run in.
-
Field Details
-
PAT_ENV_VARIABLE
- See Also:
-
DEFAULT_SERVER_ID
Id of the<server>entry the token is read from, unless the build configures a different one.- See Also:
-
ENCRYPTION_GUIDE_URL
- See Also:
-
-
Constructor Details
-
AccessTokenProvider
protected AccessTokenProvider()Only meant for test doubles, which overridegetAccessToken()and therefore never read either source. -
AccessTokenProvider
public AccessTokenProvider(org.apache.maven.settings.Settings settings, org.apache.maven.settings.crypto.SettingsDecrypter settingsDecrypter, String serverId, org.apache.maven.plugin.logging.Log log)
-
-
Method Details
-
getServerId
The id of the<server>entry that is actually read, i.e. the configured one once normalized, or the default when the build configures none. Reporting anything else would point at an entry that was never consulted. -
getAccessToken
The environment takes precedence, so that a build which already exports the token, typically on CI, keeps authenticating with it even when the machine also has a server entry configured.Not finding a token and finding one that cannot be read are told apart: a build that configures none simply has none, whereas one that stored an encrypted token clearly meant to authenticate with it, so leaving that token unread would only surface later as an authentication error that says nothing about the real problem.
- Returns:
- null when neither source provides a token
- Throws:
org.apache.maven.plugin.MojoExecutionException- when the server entry holds a token that cannot be turned into a usable one, i.e. decryption fails or leaves it in its encrypted form
-
readEnvironmentToken
Overridable so that tests do not have to change the environment of the process they run in.
-