Inclusion of support for credentials

- Added support for credentials
- Less verbose methods
This commit is contained in:
Bruno Oliveira 2017-03-31 17:16:29 -03:00
parent 0db2640076
commit f9c017efaf
2 changed files with 24 additions and 6 deletions

View file

@ -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) {

View file

@ -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());