Skip to content

Commit b849a88

Browse files
committed
Process review comments
1 parent f2510aa commit b849a88

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

README.md

+24-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ Use another Keycloak Docker image/version than used in this Testcontainer:
4242
KeycloakContainer keycloak = new KeycloakContainer("quay.io/keycloak/keycloak:26.0");
4343
```
4444

45+
### Initial admin user credentials
46+
47+
Use different admin credentials than the default internal (`admin`/`admin`) ones:
48+
49+
```java
50+
@Container
51+
KeycloakContainer keycloak = new KeycloakContainer()
52+
.withAdminUsername("myKeycloakAdminUser")
53+
.withAdminPassword("tops3cr3t");
54+
```
55+
4556
### Realm Import
4657

4758
Power up a Keycloak instance with one or more existing realm JSON config files (from classpath):
@@ -56,13 +67,24 @@ or
5667
.withRealmImportFiles("/test-realm-1.json", "/test-realm-2.json");
5768
```
5869

59-
### Initial admin user credentials
70+
If your realm JSON configuration file includes user definitions - particularly the admin user
71+
for the master realm - ensure you disable the automatic bootstrapping of the admin user:
72+
73+
```java
74+
@Container
75+
KeycloakContainer keycloak = new KeycloakContainer()
76+
.withBootstrapAdminDisabled()
77+
.withRealmImportFile("/test-realm.json");
78+
```
6079

61-
Use different admin credentials than the defaut internal (`admin`/`admin`) ones:
80+
To retrieve a working Keycloak Admin Client from the container, make sure to override the admin
81+
credentials to match those in your imported realm JSON configuration file:
6282

6383
```java
6484
@Container
6585
KeycloakContainer keycloak = new KeycloakContainer()
86+
.withBootstrapAdminDisabled()
87+
.withRealmImportFile("/test-realm.json")
6688
.withAdminUsername("myKeycloakAdminUser")
6789
.withAdminPassword("tops3cr3t");
6890
```

src/main/java/dasniko/testcontainers/keycloak/ExtendableKeycloakContainer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ protected void configure() {
166166
withEnv("KC_FEATURES_DISABLED", String.join(",", featuresDisabled));
167167
}
168168

169-
if(bootstrapAdmin) {
169+
if (bootstrapAdmin) {
170170
withEnv("KC_BOOTSTRAP_ADMIN_USERNAME", adminUsername);
171171
withEnv("KC_BOOTSTRAP_ADMIN_PASSWORD", adminPassword);
172172
}
@@ -521,7 +521,7 @@ private SELF withDebug(int hostPort, boolean suspend) {
521521
}
522522

523523
/** Disable default bootstrapping of the keycloak admin. Useful when realms are imported. */
524-
public SELF withoutBootstrapAdmin() {
524+
public SELF withBootstrapAdminDisabled() {
525525
this.bootstrapAdmin = false;
526526
return self();
527527
}

src/test/java/dasniko/testcontainers/keycloak/KeycloakContainerTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
public class KeycloakContainerTest {
3535

3636
public static final String TEST_REALM_JSON = "/test-realm.json";
37-
public static final String MASTER_REALM_USERS_JSON = "/master-realm.json";
37+
public static final String MASTER_REALM_WITH_ADMIN_USER_JSON = "/master-realm-with-admin-user.json";
3838

3939
@Test
4040
public void shouldStartKeycloak() {
@@ -52,7 +52,7 @@ public void shouldConsiderConfiguredStartupTimeout() {
5252
try (KeycloakContainer keycloak = new KeycloakContainer().withStartupTimeout(duration)) {
5353
keycloak.start();
5454
}
55-
} catch(ContainerLaunchException ex) {
55+
} catch (ContainerLaunchException ex) {
5656
Duration observedDuration = Duration.between(start, Instant.now());
5757
assertTrue(observedDuration.toSeconds() >= MAX_TIMEOUT && observedDuration.toSeconds() < 30,
5858
String.format("Startup time should consider configured limit of %d seconds, but took %d seconds",
@@ -97,8 +97,8 @@ public void shouldImportMultipleRealms() {
9797
@Test
9898
public void shouldImportMasterRealmAdmin() {
9999
try (KeycloakContainer keycloak = new KeycloakContainer()
100-
.withoutBootstrapAdmin()
101-
.withRealmImportFiles(MASTER_REALM_USERS_JSON)) {
100+
.withBootstrapAdminDisabled()
101+
.withRealmImportFiles(MASTER_REALM_WITH_ADMIN_USER_JSON)) {
102102
keycloak.start();
103103

104104
// Throws because we have imported a different admin user with different password

0 commit comments

Comments
 (0)