diff --git a/misc/keycloak-test-helper/src/main/java/org/keycloak/test/TestsHelper.java b/misc/keycloak-test-helper/src/main/java/org/keycloak/test/TestsHelper.java index fecfbc76da..27bf7de039 100644 --- a/misc/keycloak-test-helper/src/main/java/org/keycloak/test/TestsHelper.java +++ b/misc/keycloak-test-helper/src/main/java/org/keycloak/test/TestsHelper.java @@ -43,6 +43,8 @@ import java.io.InputStream; import java.net.URI; import java.util.Arrays; +import static org.keycloak.test.builders.ClientBuilder.AccessType.PUBLIC; + public class TestsHelper { public static String baseUrl; @@ -83,7 +85,7 @@ public class TestsHelper { } public static String createDirectGrantClient() { - return createClient(ClientBuilder.create("test-dga").publicClient(true)); + return createClient(ClientBuilder.create("test-dga").accessType(PUBLIC)); } public static void deleteClient(String clientId) { diff --git a/misc/keycloak-test-helper/src/main/java/org/keycloak/test/builders/ClientBuilder.java b/misc/keycloak-test-helper/src/main/java/org/keycloak/test/builders/ClientBuilder.java index 0e51c9058e..b4c78bcd7a 100644 --- a/misc/keycloak-test-helper/src/main/java/org/keycloak/test/builders/ClientBuilder.java +++ b/misc/keycloak-test-helper/src/main/java/org/keycloak/test/builders/ClientBuilder.java @@ -28,6 +28,8 @@ public class ClientBuilder { private ClientRepresentation rep; + public enum AccessType { BEARER_ONLY, PUBLIC, CONFIDENTIAL }; + public static ClientBuilder create(String clientId) { ClientRepresentation rep = new ClientRepresentation(); rep.setEnabled(Boolean.TRUE); @@ -39,9 +41,19 @@ public class ClientBuilder { this.rep = rep; } - public ClientRepresentation bearerOnly(boolean bearerOnly) { - rep.setBearerOnly(bearerOnly); - return rep; + public ClientRepresentation accessType(AccessType accessType) { + switch (accessType) { + case BEARER_ONLY: + rep.setBearerOnly(true); + break; + case PUBLIC: + rep.setPublicClient(true); + break; + case CONFIDENTIAL: + rep.setPublicClient(false); + break; + } + return defaultSettings(); } public ClientBuilder rootUrl(String rootUrl) { @@ -64,9 +76,13 @@ public class ClientBuilder { return this; } - public ClientRepresentation publicClient(boolean publicClient) { + public ClientBuilder secret(String secret) { + rep.setSecret(secret); + return this; + } + + private ClientRepresentation defaultSettings() { rep.setFullScopeAllowed(true); - rep.setPublicClient(publicClient); rep.setDirectAccessGrantsEnabled(true); rep.setAdminUrl(rep.getRootUrl());