forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#44389 from michalvavrik/feature/kc-dev-s…
…vc-for-kc-admin-client Start Keycloak Dev Services for standalone Keycloak Admin REST/RESTEasy clients
- Loading branch information
Showing
15 changed files
with
239 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...arkus/keycloak/admin/client/reactive/devservices/KeycloakDevServiceRequiredBuildStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.quarkus.keycloak.admin.client.reactive.devservices; | ||
|
||
import java.util.Map; | ||
|
||
import io.quarkus.deployment.IsDevelopment; | ||
import io.quarkus.deployment.IsNormal; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.annotations.BuildSteps; | ||
import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig; | ||
import io.quarkus.devservices.keycloak.KeycloakAdminPageBuildItem; | ||
import io.quarkus.devservices.keycloak.KeycloakDevServicesRequiredBuildItem; | ||
import io.quarkus.devui.spi.page.CardPageBuildItem; | ||
import io.quarkus.keycloak.admin.client.common.KeycloakAdminClientInjectionEnabled; | ||
|
||
@BuildSteps(onlyIfNot = IsNormal.class, onlyIf = { GlobalDevServicesConfig.Enabled.class, | ||
KeycloakAdminClientInjectionEnabled.class }) | ||
public class KeycloakDevServiceRequiredBuildStep { | ||
|
||
private static final String SERVER_URL_CONFIG_KEY = "quarkus.keycloak.admin-client.server-url"; | ||
|
||
@BuildStep | ||
KeycloakDevServicesRequiredBuildItem requireKeycloakDevService() { | ||
return KeycloakDevServicesRequiredBuildItem.of( | ||
ctx -> Map.of(SERVER_URL_CONFIG_KEY, ctx.authServerInternalBaseUrl()), | ||
SERVER_URL_CONFIG_KEY); | ||
} | ||
|
||
@BuildStep(onlyIf = IsDevelopment.class) | ||
KeycloakAdminPageBuildItem addCardWithLinkToKeycloakAdmin() { | ||
return new KeycloakAdminPageBuildItem(new CardPageBuildItem()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
.../quarkus/keycloak/admin/client/reactive/KeycloakAdminClientZeroConfigDevServicesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.quarkus.keycloak.admin.client.reactive; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.keycloak.admin.client.Keycloak; | ||
import org.keycloak.representations.idm.RoleRepresentation; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
import io.restassured.RestAssured; | ||
import io.restassured.response.Response; | ||
|
||
public class KeycloakAdminClientZeroConfigDevServicesTest { | ||
|
||
@RegisterExtension | ||
final static QuarkusDevModeTest app = new QuarkusDevModeTest() | ||
.withApplicationRoot(jar -> jar.addClasses(AdminResource.class)); | ||
|
||
@Test | ||
public void testGetRoles() { | ||
// use 'password' grant type | ||
final Response getRolesReq = RestAssured.given().get("/api/admin/roles"); | ||
assertEquals(200, getRolesReq.statusCode()); | ||
final List<RoleRepresentation> roles = getRolesReq.jsonPath().getList(".", RoleRepresentation.class); | ||
assertNotNull(roles); | ||
// assert there are roles admin and user (among others) | ||
assertTrue(roles.stream().anyMatch(rr -> "user".equals(rr.getName()))); | ||
assertTrue(roles.stream().anyMatch(rr -> "admin".equals(rr.getName()))); | ||
} | ||
|
||
@Path("/api/admin") | ||
public static class AdminResource { | ||
|
||
@Inject | ||
Keycloak keycloak; | ||
|
||
@GET | ||
@Path("/roles") | ||
public List<RoleRepresentation> getRoles() { | ||
return keycloak.realm("quarkus").roles().list(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...rkus/keycloak/adminclient/deployment/devservices/KeycloakDevServiceRequiredBuildStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.quarkus.keycloak.adminclient.deployment.devservices; | ||
|
||
import java.util.Map; | ||
|
||
import io.quarkus.deployment.IsDevelopment; | ||
import io.quarkus.deployment.IsNormal; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.annotations.BuildSteps; | ||
import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig; | ||
import io.quarkus.devservices.keycloak.KeycloakAdminPageBuildItem; | ||
import io.quarkus.devservices.keycloak.KeycloakDevServicesRequiredBuildItem; | ||
import io.quarkus.devui.spi.page.CardPageBuildItem; | ||
import io.quarkus.keycloak.admin.client.common.KeycloakAdminClientInjectionEnabled; | ||
|
||
@BuildSteps(onlyIfNot = IsNormal.class, onlyIf = { GlobalDevServicesConfig.Enabled.class, | ||
KeycloakAdminClientInjectionEnabled.class }) | ||
public class KeycloakDevServiceRequiredBuildStep { | ||
|
||
private static final String SERVER_URL_CONFIG_KEY = "quarkus.keycloak.admin-client.server-url"; | ||
|
||
@BuildStep | ||
KeycloakDevServicesRequiredBuildItem requireKeycloakDevService() { | ||
return KeycloakDevServicesRequiredBuildItem.of( | ||
ctx -> Map.of(SERVER_URL_CONFIG_KEY, ctx.authServerInternalBaseUrl()), | ||
SERVER_URL_CONFIG_KEY); | ||
} | ||
|
||
@BuildStep(onlyIf = IsDevelopment.class) | ||
KeycloakAdminPageBuildItem addCardWithLinkToKeycloakAdmin() { | ||
return new KeycloakAdminPageBuildItem(new CardPageBuildItem()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.