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 Summary
FieldsModifier and TypeFieldDescriptionprivate final tools.jackson.databind.json.JsonMapperWrites a document as JSON.private final ListDocumentsUseCaseLists the documents.private final CliOutputWrites the lines.static final StringName of the Spring profile that turns the runner on.private final CliPropertiesThe settings.private final ServiceTokensGives the token the call used. -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
PROFILE
Name of the Spring profile that turns the runner on.- See Also:
-
listDocumentsUseCase
Lists the documents. -
serviceTokens
Gives the token the call used. -
output
Writes the lines. -
jsonMapper
private final tools.jackson.databind.json.JsonMapper jsonMapperWrites a document as JSON. -
properties
The settings.
-
-
Constructor Details
-
ClientCredentialsCli
public ClientCredentialsCli()
-
-
Method Details
-
run
Lists the documents and, when asked, prints the token.- Specified by:
runin interfaceorg.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.
-