-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate Keycloak Admin Client with TLS registry
- Loading branch information
1 parent
dac2bb6
commit 4115e48
Showing
14 changed files
with
389 additions
and
17 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
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
75 changes: 75 additions & 0 deletions
75
...o/quarkus/keycloak/admin/client/reactive/KeycloakAdminClientMutualTlsDevServicesTest.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,75 @@ | ||
package io.quarkus.keycloak.admin.client.reactive; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.resteasy.reactive.RestPath; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.keycloak.admin.client.Keycloak; | ||
import org.keycloak.representations.idm.RealmRepresentation; | ||
import org.keycloak.representations.idm.RoleRepresentation; | ||
import org.keycloak.representations.idm.RolesRepresentation; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
import io.restassured.RestAssured; | ||
import io.smallrye.certs.Format; | ||
import io.smallrye.certs.junit5.Certificate; | ||
import io.smallrye.certs.junit5.Certificates; | ||
|
||
@Certificates(baseDir = "target/certs", certificates = @Certificate(name = "mtls-test", password = "secret", formats = { | ||
Format.PKCS12, Format.PEM }, client = true)) | ||
public class KeycloakAdminClientMutualTlsDevServicesTest { | ||
|
||
@RegisterExtension | ||
final static QuarkusDevModeTest app = new QuarkusDevModeTest() | ||
.withApplicationRoot(jar -> jar | ||
.addClasses(MtlsResource.class) | ||
.addAsResource(new File("target/certs/mtls-test-keystore.p12"), "server-keystore.p12") | ||
.addAsResource(new File("target/certs/mtls-test-server-ca.crt"), "server-ca.crt") | ||
.addAsResource(new File("target/certs/mtls-test-client-keystore.p12"), "client-keystore.p12") | ||
.addAsResource(new File("target/certs/mtls-test-client-truststore.p12"), "client-truststore.p12") | ||
.addAsResource("app-mtls-config.properties", "application.properties")); | ||
|
||
@Test | ||
public void testCreateRealm() { | ||
// create realm | ||
RestAssured.given().post("/api/mtls").then().statusCode(204); | ||
// test realm created | ||
RestAssured.given().get("/api/mtls/Ron").then().statusCode(200).body(Matchers.is("Weasley")); | ||
} | ||
|
||
@Path("/api/mtls") | ||
public static class MtlsResource { | ||
|
||
@Inject | ||
Keycloak keycloak; | ||
|
||
@POST | ||
public void createMtlsRealm() { | ||
var realm = new RealmRepresentation(); | ||
realm.setRealm("mtls"); | ||
realm.setEnabled(true); | ||
RolesRepresentation roles = new RolesRepresentation(); | ||
List<RoleRepresentation> realmRoles = new ArrayList<>(); | ||
roles.setRealm(realmRoles); | ||
realm.setRoles(roles); | ||
realm.getRoles().getRealm().add(new RoleRepresentation("Ron", "Weasley", false)); | ||
keycloak.realms().create(realm); | ||
} | ||
|
||
@Path("{roleName}") | ||
@GET | ||
public String getRoleDescription(@RestPath String roleName) { | ||
return keycloak.realm("mtls").roles().get(roleName).toRepresentation().getDescription(); | ||
} | ||
|
||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...sions/keycloak-admin-rest-client/deployment/src/test/resources/app-mtls-config.properties
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,19 @@ | ||
# Configure Dev Services for Keycloak | ||
quarkus.keycloak.devservices.create-realm=false | ||
quarkus.keycloak.devservices.port=8083 | ||
quarkus.keycloak.devservices.start-command=start --https-client-auth=required --hostname-strict=false --https-key-store-file=/etc/server-keystore.p12 --https-key-store-password=secret --truststore-paths=/etc/server-ca.crt --https-port=8080 | ||
# using PEM CA cert because generated PKCS12 server trust-store is encrypted, but KC requires no password for trust-store | ||
quarkus.keycloak.devservices.resource-aliases.trust-store=server-ca.crt | ||
quarkus.keycloak.devservices.resource-mappings.trust-store=/etc/server-ca.crt | ||
quarkus.keycloak.devservices.resource-aliases.key-store=server-keystore.p12 | ||
quarkus.keycloak.devservices.resource-mappings.key-store=/etc/server-keystore.p12 | ||
|
||
# Configure Keycloak Admin Client | ||
quarkus.keycloak.admin-client.server-url=https://localhost:${quarkus.keycloak.devservices.port} | ||
quarkus.keycloak.admin-client.tls-configuration-name=kc-admin-client | ||
|
||
# Mutual TLS configuration | ||
quarkus.tls.kc-admin-client.key-store.p12.path=client-keystore.p12 | ||
quarkus.tls.kc-admin-client.key-store.p12.password=secret | ||
quarkus.tls.kc-admin-client.trust-store.p12.path=client-truststore.p12 | ||
quarkus.tls.kc-admin-client.trust-store.p12.password=secret |
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
Oops, something went wrong.