Class ClientCredentialsCli

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

@Component @Profile("client-credentials") public class ClientCredentialsCli extends Object implements org.springframework.boot.CommandLineRunner
Command-line client of the OAuth 2.0 client credentials grant: obtains an access token with its own credentials, lists the documents the resource server shows it and prints each one as a JSON line.

Running it from the packaged jar:

 java -jar service-client-boot.jar --spring.profiles.active=client-credentials \
     --service-client.auth.token-uri=http://localhost:9000/oauth2/token \
     --service-client.resource-server.base-uri=http://localhost:8081
 
with SERVICE_CLIENT_ID and SERVICE_CLIENT_SECRET (or --service-client.auth.method and its key or SSL bundle for the other authentication methods, see application-client-credentials.yml). With --service-client.cli.print-access-token=true a last Access token: ... line prints the 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:
    • listDocumentsUseCase

      private final ListDocumentsUseCase listDocumentsUseCase
      Lists the documents.
    • serviceTokens

      private final ServiceTokens serviceTokens
      Gives the token the call used.
    • 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

    • ClientCredentialsCli

      public ClientCredentialsCli()
  • Method Details

    • run

      public void run(String... args)
      Lists the documents and, when asked, prints the token.
      Specified by:
      run in interface org.springframework.boot.CommandLineRunner
      Parameters:
      args - ignored: settings arrive as Spring properties.
      Throws:
      DocumentAccessException - if the token cannot be obtained or the resource server refuses the call.