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-exchangewith 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 Summary
FieldsModifier and TypeFieldDescriptionprivate final tools.jackson.databind.json.JsonMapperWrites a document as JSON.private final ListDocumentsOnBehalfOfUseCaseLists the documents of a user.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 exchanged token. -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
PROFILE
Name of the Spring profile that turns the runner on.- See Also:
-
listDocumentsOnBehalfOfUseCase
Lists the documents of a user. -
serviceTokens
Gives the exchanged token. -
output
Writes the lines. -
jsonMapper
private final tools.jackson.databind.json.JsonMapper jsonMapperWrites a document as JSON. -
properties
The settings.
-
-
Constructor Details
-
TokenExchangeCli
public TokenExchangeCli()
-
-
Method Details
-
run
Exchanges the token, lists the documents and, when asked, prints the exchanged token.- Specified by:
runin interfaceorg.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.
-