use of org.keycloak.component.ComponentModel in project keycloak by keycloak.
the class ComponentResource method getComponent.
@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
@NoCache
public ComponentRepresentation getComponent(@PathParam("id") String id) {
auth.realm().requireViewRealm();
ComponentModel model = realm.getComponent(id);
if (model == null) {
throw new NotFoundException("Could not find component");
}
ComponentRepresentation rep = ModelToRepresentation.toRepresentation(session, model, false);
return rep;
}
use of org.keycloak.component.ComponentModel in project keycloak by keycloak.
the class ComponentResource method create.
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response create(ComponentRepresentation rep) {
auth.realm().requireManageRealm();
try {
ComponentModel model = RepresentationToModel.toModel(session, rep);
if (model.getParentId() == null)
model.setParentId(realm.getId());
model = realm.addComponentModel(model);
adminEvent.operation(OperationType.CREATE).resourcePath(session.getContext().getUri(), model.getId()).representation(StripSecretsUtils.strip(session, rep)).success();
return Response.created(session.getContext().getUri().getAbsolutePathBuilder().path(model.getId()).build()).build();
} catch (ComponentValidationException e) {
return localizedErrorResponse(e);
} catch (IllegalArgumentException e) {
throw new BadRequestException(e);
}
}
use of org.keycloak.component.ComponentModel in project keycloak by keycloak.
the class ComponentResource method removeComponent.
@DELETE
@Path("{id}")
public void removeComponent(@PathParam("id") String id) {
auth.realm().requireManageRealm();
ComponentModel model = realm.getComponent(id);
if (model == null) {
throw new NotFoundException("Could not find component");
}
adminEvent.operation(OperationType.DELETE).resourcePath(session.getContext().getUri()).success();
realm.removeComponent(model);
}
use of org.keycloak.component.ComponentModel in project keycloak by keycloak.
the class ComponentResource method updateComponent.
@PUT
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)
public Response updateComponent(@PathParam("id") String id, ComponentRepresentation rep) {
auth.realm().requireManageRealm();
try {
ComponentModel model = realm.getComponent(id);
if (model == null) {
throw new NotFoundException("Could not find component");
}
RepresentationToModel.updateComponent(session, rep, model, false);
adminEvent.operation(OperationType.UPDATE).resourcePath(session.getContext().getUri()).representation(StripSecretsUtils.strip(session, rep)).success();
realm.updateComponent(model);
return Response.noContent().build();
} catch (ComponentValidationException e) {
return localizedErrorResponse(e);
} catch (IllegalArgumentException e) {
throw new BadRequestException();
}
}
use of org.keycloak.component.ComponentModel in project keycloak by keycloak.
the class ComponentResource method getSubcomponentConfig.
/**
* List of subcomponent types that are available to configure for a particular parent component.
*
* @param parentId
* @param subtype
* @return
*/
@GET
@Path("{id}/sub-component-types")
@Produces(MediaType.APPLICATION_JSON)
@NoCache
public Stream<ComponentTypeRepresentation> getSubcomponentConfig(@PathParam("id") String parentId, @QueryParam("type") String subtype) {
auth.realm().requireViewRealm();
ComponentModel parent = realm.getComponent(parentId);
if (parent == null) {
throw new NotFoundException("Could not find parent component");
}
if (subtype == null) {
throw new BadRequestException("must specify a subtype");
}
Class<? extends Provider> providerClass;
try {
providerClass = (Class<? extends Provider>) Class.forName(subtype);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
return session.getKeycloakSessionFactory().getProviderFactoriesStream(providerClass).filter(ComponentFactory.class::isInstance).map(factory -> toComponentTypeRepresentation(factory, parent));
}
Aggregations