@Override public ComponentModel addComponentModel(ComponentModel model) { model = importComponentModel(model); ComponentUtil.notifyCreated(session, this, model); return model; }
@Override public void removeComponents(String parentId) { Predicate<ComponentEntity> sameParent = c -> Objects.equals(parentId, c.getParentId()); getEntity().getComponents().stream() .filter(sameParent) .map(this::entityToModel) .forEach((ComponentModel c) -> { session.users().preRemove(this, c); ComponentUtil.notifyPreRemove(session, this, c); }); getEntity().getComponents().removeIf(sameParent); }
@Override public void updateComponent(ComponentModel model) { ComponentUtil.getComponentFactory(session, model).validateConfiguration(session, this, model); ComponentModel old = null; for (ComponentEntity entity : realm.getComponentEntities()) { if (entity.getId().equals(model.getId())) { old = entityToModel(entity); updateComponentEntity(entity, model); break; } } if (old == null) return; updateRealm(); ComponentUtil.notifyUpdated(session, this, old, model); }
@Override public ComponentModel importComponentModel(ComponentModel model) { ComponentFactory componentFactory = null; try { componentFactory = ComponentUtil.getComponentFactory(session, model); if (componentFactory == null && System.getProperty(COMPONENT_PROVIDER_EXISTS_DISABLED) == null) { throw new IllegalArgumentException("Invalid component type"); } componentFactory.validateConfiguration(session, this, model); } catch (Exception e) { if (System.getProperty(COMPONENT_PROVIDER_EXISTS_DISABLED) == null) { throw e; } } ComponentEntity entity = new ComponentEntity(); if (model.getId() == null) { entity.setId(KeycloakModelUtils.generateId()); } else { entity.setId(model.getId()); } updateComponentEntity(entity, model); model.setId(entity.getId()); if (model.getParentId() == null) { entity.setParentId(this.getId()); model.setParentId(this.getId()); } realm.getComponentEntities().add(entity); updateRealm(); return model; }
@Override public void updateComponent(ComponentModel component) { ComponentUtil.getComponentFactory(session, component).validateConfiguration(session, this, component); ComponentEntity c = em.find(ComponentEntity.class, component.getId()); if (c == null) return; ComponentModel old = entityToModel(c); c.setName(component.getName()); c.setProviderId(component.getProviderId()); c.setProviderType(component.getProviderType()); c.setParentId(component.getParentId()); c.setSubType(component.getSubType()); setConfig(component, c); ComponentUtil.notifyUpdated(session, this, old, component); }
ComponentFactory componentFactory = null; try { componentFactory = ComponentUtil.getComponentFactory(session, model); if (componentFactory == null && System.getProperty(COMPONENT_PROVIDER_EXISTS_DISABLED) == null) { throw new IllegalArgumentException("Invalid component type");
@Override public ComponentModel addComponentModel(ComponentModel model) { model = importComponentModel(model); ComponentUtil.notifyCreated(session, this, model); return model; }
@Override public void removeComponent(ComponentModel component) { ComponentEntity c = em.find(ComponentEntity.class, component.getId()); if (c == null) return; session.users().preRemove(this, component); ComponentUtil.notifyPreRemove(session, this, component); removeComponents(component.getId()); getEntity().getComponents().remove(c); }