Class TokenExchangeCli

java.lang.Object
com.irurueta.authserver.serviceclient.TokenExchangeCli
All Implemented Interfaces:
org.springframework.boot.CommandLineRunner

@Component @Profile("token-exchange") public class TokenExchangeCli extends Object implements org.springframework.boot.CommandLineRunner
Command-line client of the OAuth 2.0 token exchange grant (RFC 8693): exchanges the access token of a user, read from the SERVICE_CLIENT_SUBJECT_TOKEN environment variable, for one that names the user as subject and this client as actor, lists the documents the resource server shows that user and prints each one as a JSON line.

Running it from the packaged jar:

 SERVICE_CLIENT_SUBJECT_TOKEN=... java -jar service-client-boot.jar --spring.profiles.active=token-exchange
 
with the same client settings as ClientCredentialsCli. With --service-client.cli.print-access-token=true a last Access token: ... line prints the exchanged token. On any failure the process ends with a non-zero exit code.

Why it lives in src/main: the end-to-end test runs the packaged service-client jar, so the runner has to be in it; it is a genuine, reusable tool of the application and not a test double.

  • Field Details

    • PROFILE

      public static final String PROFILE
      Name of the Spring profile that turns the runner on.
      See Also:
    • listDocumentsOnBehalfOfUseCase

      private final ListDocumentsOnBehalfOfUseCase listDocumentsOnBehalfOfUseCase
      Lists the documents of a user.
    • serviceTokens

      private final ServiceTokens serviceTokens
      Gives the exchanged token.
    • output

      private final CliOutput output
      Writes the lines.
    • jsonMapper

      private final tools.jackson.databind.json.JsonMapper jsonMapper
      Writes a document as JSON.
    • properties

      private final CliProperties properties
      The settings.
  • Constructor Details

    • TokenExchangeCli

      public TokenExchangeCli()
  • Method Details

    • run

      public void run(String... args)
      Exchanges the token, lists the documents and, when asked, prints the exchanged token.
      Specified by:
      run in interface org.springframework.boot.CommandLineRunner
      Parameters:
      args - ignored: settings arrive as Spring properties.
      Throws:
      IllegalStateException - if there is no subject token.
      DocumentAccessException - if the exchange is refused or the resource server refuses the call.