use of org.keycloak.admin.client.resource.ComponentsResource in project keycloak by keycloak.
the class Creator method create.
public static Creator<ComponentResource> create(RealmResource realmResource, ComponentRepresentation rep) {
final ComponentsResource components = realmResource.components();
try (Response response = components.add(rep)) {
String createdId = getCreatedId(response);
final ComponentResource r = components.component(createdId);
LOG.debugf("Created component ID %s", createdId);
return new Creator(createdId, r, r::remove);
}
}
use of org.keycloak.admin.client.resource.ComponentsResource in project keycloak by keycloak.
the class ComponentsTest method failCreateWithLongName.
@Test
public void failCreateWithLongName() {
StringBuilder name = new StringBuilder();
while (name.length() < 30) {
name.append("invalid");
}
ComponentRepresentation rep = createComponentRepresentation(name.toString());
rep.getConfig().addFirst("required", "foo");
ComponentsResource components = realm.components();
try (Response response = components.add(rep)) {
if (Response.Status.INTERNAL_SERVER_ERROR.getStatusCode() == response.getStatus()) {
// using database should fail due to constraint violations
assertFalse(components.query().stream().map(ComponentRepresentation::getName).anyMatch(name.toString()::equals));
} else if (Response.Status.CREATED.getStatusCode() == response.getStatus()) {
// using the map storage should work because there are no constraints
String id = ApiUtil.getCreatedId(response);
assertNotNull(components.component(id).toRepresentation());
} else {
fail("Unexpected response");
}
}
}
use of org.keycloak.admin.client.resource.ComponentsResource in project keycloak by keycloak.
the class ComponentsTest method createComponent.
private String createComponent(RealmResource realm, ComponentRepresentation rep) {
Response response = null;
try {
ComponentsResource components = realm.components();
response = components.add(rep);
String id = ApiUtil.getCreatedId(response);
getCleanup(realm.toRepresentation().getRealm()).addComponentId(id);
return id;
} finally {
if (response != null) {
response.bufferEntity();
response.close();
}
}
}
Aggregations