Class DevDataInitializer
- All Implemented Interfaces:
org.springframework.boot.ApplicationRunner
dev profile is active,
so a freshly started authorization server has someone to sign in, a client to sign in through and a client for the
OAuth 2.0 Device Authorization Grant (device-client, which the polling command line tool of the
service-client uses).
The device-client is dev-only on purpose: it is a public client that anybody who can reach the server can
use to start a device flow, and its user-facing name and scopes are those of a demo. A deployment registers its own
device clients through the admin API with the urn:ietf:params:oauth:grant-type:device_code grant type.
Purpose: local development and the end-to-end tests. Started with
spring-boot:run -Dspring-boot.run.profiles=dev, it lets a developer sign in through the BFF by hand. The
e2e-tests module (SignInSmokeIT) starts the packaged jar with the dev profile and
reads the generated credentials from the log lines below.
Why it lives in src/main although it only seeds demo data: the end-to-end tests run the real jar, and
a class under src/test never reaches it. It is inert everywhere else: without the dev profile the
bean is not even created. Never activate that profile outside local development.
It lives in the persistence adapter, next to the Flyway migrations, because it writes the tables those migrations create: a schema change that breaks it is then caught by this module's own tests.
Secrets are generated at first start and logged once as DEV ONLY warnings; nothing is committed.
Running it again does not change existing data.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final StringAudience of the authorization server's own API (authserver.api.audience).Post-logout redirect URIs of the BFF client (authserver.clients.bff.post-logout-redirect-uris); empty when not configured.Redirect URIs of the BFF client (authserver.clients.bff.redirect-uris, which thedevprofile sets to the local BFF); empty when not configured.private final ClientRegistrationRepositoryRepository where the BFF client is stored.(package private) static final StringUsername of the demo user.private static final DurationLifetime of the access tokens of the device client.(package private) static final StringClient id of the public client of the device authorization grant.(package private) static final StringGrant type of the device authorization grant.private static final DurationLifetime of the refresh tokens of the device client.Scopes of the device client.private final org.springframework.security.crypto.password.PasswordEncoderEncoder of generated secrets.private final org.springframework.jdbc.core.simple.JdbcClientJDBC client used to insert the demo user.private final SecureRandomSource of randomness for generated secrets.private static final intNumber of random bytes of generated secrets. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidCreates the BFF client from its default definition and the configured redirect URIs, with a generated secret, unless it already exists or no redirect URI is configured.private voidCreates the demo user, with a generated password, unless it already exists.private voidCreates the public device client, which has no secret and needs no redirect URI, unless it already exists.private StringGenerates a random URL-safe secret.voidrun(org.springframework.boot.ApplicationArguments args) Creates the demo user, the BFF client and the device client when they do not exist yet.
-
Field Details
-
DEMO_USERNAME
Username of the demo user.- See Also:
-
DEVICE_CLIENT_ID
Client id of the public client of the device authorization grant.- See Also:
-
DEVICE_CODE_GRANT
Grant type of the device authorization grant.- See Also:
-
DEVICE_SCOPES
Scopes of the device client.openidis left out on purpose: Spring Authorization Server refuses it in a device authorization request, because the device flow issues no ID token. -
DEVICE_ACCESS_TOKEN_TTL
Lifetime of the access tokens of the device client. -
DEVICE_REFRESH_TOKEN_TTL
Lifetime of the refresh tokens of the device client. -
SECRET_BYTES
private static final int SECRET_BYTESNumber of random bytes of generated secrets.- See Also:
-
random
Source of randomness for generated secrets. -
jdbc
private final org.springframework.jdbc.core.simple.JdbcClient jdbcJDBC client used to insert the demo user. -
encoder
private final org.springframework.security.crypto.password.PasswordEncoder encoderEncoder of generated secrets. -
clients
Repository where the BFF client is stored. -
bffRedirectUris
Redirect URIs of the BFF client (authserver.clients.bff.redirect-uris, which thedevprofile sets to the local BFF); empty when not configured. -
bffPostLogoutRedirectUris
@Value("${authserver.clients.bff.post-logout-redirect-uris:}") private final List<String> bffPostLogoutRedirectUrisPost-logout redirect URIs of the BFF client (authserver.clients.bff.post-logout-redirect-uris); empty when not configured. -
apiAudience
Audience of the authorization server's own API (authserver.api.audience).
-
-
Constructor Details
-
DevDataInitializer
public DevDataInitializer()
-
-
Method Details
-
run
@Transactional public void run(org.springframework.boot.ApplicationArguments args) Creates the demo user, the BFF client and the device client when they do not exist yet.- Specified by:
runin interfaceorg.springframework.boot.ApplicationRunner- Parameters:
args- application arguments (unused).
-
createDemoUser
private void createDemoUser()Creates the demo user, with a generated password, unless it already exists. -
createBffClient
private void createBffClient()Creates the BFF client from its default definition and the configured redirect URIs, with a generated secret, unless it already exists or no redirect URI is configured. -
createDeviceClient
private void createDeviceClient()Creates the public device client, which has no secret and needs no redirect URI, unless it already exists. It requires the user's consent to the requested scopes, as the verification page asks for it. -
generateSecret
Generates a random URL-safe secret.- Returns:
- the secret.
-