Search in sources :

Example 41 with ComponentModel

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;
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) ComponentModel(org.keycloak.component.ComponentModel) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 42 with ComponentModel

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);
    }
}
Also used : ComponentValidationException(org.keycloak.component.ComponentValidationException) ComponentModel(org.keycloak.component.ComponentModel) BadRequestException(javax.ws.rs.BadRequestException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 43 with ComponentModel

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);
}
Also used : ComponentModel(org.keycloak.component.ComponentModel) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 44 with ComponentModel

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();
    }
}
Also used : ComponentValidationException(org.keycloak.component.ComponentValidationException) ComponentModel(org.keycloak.component.ComponentModel) NotFoundException(javax.ws.rs.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 45 with ComponentModel

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));
}
Also used : ComponentModel(org.keycloak.component.ComponentModel) NotFoundException(javax.ws.rs.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Aggregations

ComponentModel (org.keycloak.component.ComponentModel)155 RealmModel (org.keycloak.models.RealmModel)74 Test (org.junit.Test)52 LDAPStorageProvider (org.keycloak.storage.ldap.LDAPStorageProvider)46 LDAPObject (org.keycloak.storage.ldap.idm.model.LDAPObject)34 UserModel (org.keycloak.models.UserModel)29 HashMap (java.util.HashMap)22 UserStorageProviderModel (org.keycloak.storage.UserStorageProviderModel)22 GroupModel (org.keycloak.models.GroupModel)21 MultivaluedHashMap (org.keycloak.common.util.MultivaluedHashMap)18 SynchronizationResult (org.keycloak.storage.user.SynchronizationResult)18 ComponentValidationException (org.keycloak.component.ComponentValidationException)16 UserStorageProvider (org.keycloak.storage.UserStorageProvider)16 LDAPStorageMapper (org.keycloak.storage.ldap.mappers.LDAPStorageMapper)15 GroupLDAPStorageMapper (org.keycloak.storage.ldap.mappers.membership.group.GroupLDAPStorageMapper)15 Path (javax.ws.rs.Path)14 DeclarativeUserProfileProvider (org.keycloak.userprofile.DeclarativeUserProfileProvider)13 ModelException (org.keycloak.models.ModelException)11 UPAttribute (org.keycloak.userprofile.config.UPAttribute)11 UPConfig (org.keycloak.userprofile.config.UPConfig)11