Class AccessTokenProvider

java.lang.Object
ai.timefold.solver.tools.maven.AccessTokenProvider

public class AccessTokenProvider extends Object
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
    Modifier and Type
    Field
    Description
    static final String
    Id of the <server> entry the token is read from, unless the build configures a different one.
    protected static final String
     
    static final String
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Only meant for test doubles, which override getAccessToken() 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 Type
    Method
    Description
    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.
    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 String
    Overridable so that tests do not have to change the environment of the process they run in.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • AccessTokenProvider

      protected AccessTokenProvider()
      Only meant for test doubles, which override getAccessToken() 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

      public String 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

      public String getAccessToken() throws org.apache.maven.plugin.MojoExecutionException
      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

      protected String readEnvironmentToken()
      Overridable so that tests do not have to change the environment of the process they run in.