Search in sources :

Example 1 with ComponentsResource

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);
    }
}
Also used : Response(javax.ws.rs.core.Response) Logger(org.jboss.logging.Logger) ComponentResource(org.keycloak.admin.client.resource.ComponentResource) ComponentsResource(org.keycloak.admin.client.resource.ComponentsResource)

Example 2 with ComponentsResource

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");
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) ComponentsResource(org.keycloak.admin.client.resource.ComponentsResource) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 3 with ComponentsResource

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();
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) ComponentsResource(org.keycloak.admin.client.resource.ComponentsResource) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

Response (javax.ws.rs.core.Response)3 ComponentsResource (org.keycloak.admin.client.resource.ComponentsResource)3 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Logger (org.jboss.logging.Logger)1 Test (org.junit.Test)1 ComponentResource (org.keycloak.admin.client.resource.ComponentResource)1