private List<ReportletWrapper> getReportletWrappers(final ReportTO reportTO) { return reportTO.getReportlets().stream().map(reportlet -> { ImplementationTO impl = implementationClient.read(ImplementationType.REPORTLET, reportlet); ReportletWrapper wrapper = new ReportletWrapper(false). setImplementationKey(impl.getKey()). setImplementationEngine(impl.getEngine()); if (impl.getEngine() == ImplementationEngine.JAVA) { try { ReportletConf reportletConf = MAPPER.readValue(impl.getBody(), ReportletConf.class); wrapper.setConf(reportletConf); } catch (Exception e) { LOG.error("During deserialization", e); } } return wrapper; }).filter(wrapper -> wrapper != null).collect(Collectors.toList()); }
@Override public ImplementationTO getImplementationTO(final Implementation implementation) { ImplementationTO implementationTO = new ImplementationTO(); implementationTO.setKey(implementation.getKey()); implementationTO.setEngine(implementation.getEngine()); implementationTO.setType(implementation.getType()); implementationTO.setBody(implementation.getBody()); return implementationTO; } }
@Override protected void onEvent(final AjaxRequestTarget target) { ImplementationTO impl = implementationClient.read(implementationType, conf.getModelObject()); rule.setImplementationEngine(impl.getEngine()); if (impl.getEngine() == ImplementationEngine.JAVA) { try { RuleConf ruleConf = MAPPER.readValue(impl.getBody(), RuleConf.class); rule.setConf(ruleConf); } catch (Exception e) { LOG.error("During deserialization", e); } } } });
this.viewMode = implementation.getEngine() == ImplementationEngine.GROOVY ? ViewMode.GROOVY_BODY : implementation.getType() == ImplementationType.REPORTLET || implementation.getType() == ImplementationType.ACCOUNT_RULE || implementation.getType() == ImplementationType.PASSWORD_RULE || implementation.getType() == ImplementationType.PULL_CORRELATION_RULE || implementation.getType() == ImplementationType.PUSH_CORRELATION_RULE ? ViewMode.JSON_BODY : ViewMode.JAVA_CLASS; this.create = implementation.getKey() == null; if (viewMode == ViewMode.JAVA_CLASS) { Optional<JavaImplInfo> javaClasses = SyncopeConsoleSession.get().getPlatformInfo(). getJavaImplInfo(implementation.getType()); classes = javaClasses.isPresent() ? new ArrayList<>(javaClasses.get().getClasses()) : new ArrayList<>(); } else if (viewMode == ViewMode.JSON_BODY) { switch (implementation.getType()) { case REPORTLET: classes = lookup.getReportletConfs().keySet().stream(). jsonClass.setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true); jsonClass.setVisible(viewMode == ViewMode.JSON_BODY); if (viewMode == ViewMode.JSON_BODY && StringUtils.isNotBlank(implementation.getBody())) { try { JsonNode node = MAPPER.readTree(implementation.getBody()); if (node.has("@class")) { jsonClass.setModelObject(node.get("@class").asText());
public String getImplKey() { return impl == null ? null : impl.getKey(); }
@Override public void onClick(final AjaxRequestTarget target, final ImplementationTO ignore) { try { restClient.delete(model.getObject().getType(), model.getObject().getKey()); SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED)); target.add(container); } catch (SyncopeClientException e) { LOG.error("While deleting object {}", model.getObject().getKey(), e); SyncopeConsoleSession.get().error( StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage()); } ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target); } }, ActionLink.ActionType.DELETE, StandardEntitlement.IMPLEMENTATION_DELETE, true);
@Override protected void onSubmit(final ImplementationEngine engine, final AjaxRequestTarget target) { implementation.setKey(null); implementation.setBody(null); target.add(ImplementationDirectoryPanel.this.modal.setContent(new ImplementationModalPanel( ImplementationDirectoryPanel.this.modal, implementation, pageRef))); ImplementationDirectoryPanel.this.modal.header( new StringResourceModel("any.new", Model.of(implementation))); ImplementationDirectoryPanel.this.modal.show(true); } };
this.type = type; ImplementationTO implementation = new ImplementationTO(); implementation.setType(type);
public ImplementationTO getImpl() { if (defaultRuleConf != null) { try { this.impl.setBody(OBJECT_MAPPER.writeValueAsString(defaultRuleConf)); } catch (Exception e) { LOG.error("Could not serialize {}", defaultRuleConf); } } return impl; }
public final void setImpl(final ImplementationTO impl) { this.impl = impl; if (impl != null) { this.defaultRuleConf = null; try { this.defaultRuleConf = OBJECT_MAPPER.readValue(impl.getBody(), ruleConfClass); } catch (Exception e) { LOG.debug("Could not deserialize {} as {}", impl.getBody(), ruleConfClass.getName()); } } }
@Override public void onClose(final AjaxRequestTarget target) { implementation.setEngine(null); updateResultTable(target); modal.show(false); } });
@Override protected void onEvent(final AjaxRequestTarget target) { Class<?> clazz = null; switch (implementation.getType()) { case REPORTLET: clazz = lookup.getReportletConfs().get(jsonClass.getModelObject());
@Override public void onSubmit(final AjaxRequestTarget target) { try { getItem().getCorrelationRules().clear(); model.getObject().forEach(rule -> { getItem().getCorrelationRules().put(rule.getAnyType(), rule.getImplKey()); if (rule.getImpl().getEngine() == ImplementationEngine.JAVA && rule.getDefaultRuleConf() != null) { try { implRestClient.update(rule.getImpl()); } catch (Exception e) { throw new RuntimeException(e); } } }); restClient.updatePolicy(getItem() instanceof PullPolicyTO ? PolicyType.PULL : PolicyType.PUSH, getItem()); SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED)); this.modal.close(target); } catch (Exception e) { LOG.error("While creating/updating policy", e); SyncopeConsoleSession.get().error( StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage()); } ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target); }
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidImplementation); if (implementation.getType() != null && implementation.getType() != implementationTO.getType()) { sce.getElements().add("ImplementationType cannot be changed"); throw sce; if (StringUtils.isBlank(implementationTO.getBody())) { sce.getElements().add("No actual implementation provided"); throw sce; implementation.setKey(implementationTO.getKey()); implementation.setEngine(implementationTO.getEngine()); implementation.setType(implementationTO.getType()); implementation.setBody(implementationTO.getBody());
@Override public Response create(final ImplementationTO implementationTO) { ImplementationTO created = logic.create(implementationTO); URI location = uriInfo.getAbsolutePathBuilder().path(String.valueOf(created.getKey())).build(); return Response.created(location). header(RESTHeaders.RESOURCE_KEY, created.getKey()). build(); }
@Override protected void onEvent(final AjaxRequestTarget target) { ImplementationTO impl = implementationClient.read( ImplementationType.REPORTLET, conf.getModelObject()); reportlet.setImplementationEngine(impl.getEngine()); if (impl.getEngine() == ImplementationEngine.JAVA) { try { ReportletConf conf = MAPPER.readValue(impl.getBody(), ReportletConf.class); reportlet.setConf(conf); } catch (Exception e) { LOG.error("During deserialization", e); } } } });
@Override protected Serializable onApplyInternal(final ReportletWrapper modelObject) { if (modelObject.getImplementationEngine() == ImplementationEngine.JAVA) { ImplementationTO reportlet = implementationClient.read( ImplementationType.REPORTLET, modelObject.getImplementationKey()); try { reportlet.setBody(MAPPER.writeValueAsString(modelObject.getConf())); implementationClient.update(reportlet); } catch (Exception e) { throw new RuntimeException(e); } } ReportTO reportTO = restClient.read(report); if (modelObject.isNew()) { reportTO.getReportlets().add(modelObject.getImplementationKey()); } restClient.update(reportTO); return modelObject; }
@PreAuthorize("hasRole('" + StandardEntitlement.IMPLEMENTATION_UPDATE + "')") public ImplementationTO update(final ImplementationTO implementationTO) { Implementation implementation = implementationDAO.find(implementationTO.getKey()); if (implementation == null) { LOG.error("Could not find implementation '" + implementationTO.getKey() + "'"); throw new NotFoundException(implementationTO.getKey()); } binder.update(implementation, implementationTO); implementation = implementationDAO.save(implementation); return binder.getImplementationTO(implementation); }
@Override protected Serializable onApplyInternal(final PolicyRuleWrapper modelObject) { PolicyTO policyTO = restClient.getPolicy(type, policy); ComposablePolicy composable; if (policyTO instanceof ComposablePolicy) { composable = (ComposablePolicy) policyTO; } else { throw new IllegalStateException("Non composable policy"); } if (modelObject.getImplementationEngine() == ImplementationEngine.JAVA) { ImplementationTO rule = implementationClient.read(implementationType, modelObject.getImplementationKey()); try { rule.setBody(MAPPER.writeValueAsString(modelObject.getConf())); implementationClient.update(rule); } catch (Exception e) { throw new RuntimeException(e); } } if (modelObject.isNew()) { composable.getRules().add(modelObject.getImplementationKey()); } restClient.updatePolicy(type, policyTO); return modelObject; }
@PreAuthorize("hasRole('" + StandardEntitlement.IMPLEMENTATION_CREATE + "')") public ImplementationTO create(final ImplementationTO implementationTO) { if (StringUtils.isBlank(implementationTO.getKey())) { SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing); sce.getElements().add("Implementation key"); throw sce; } Implementation implementation = implementationDAO.find(implementationTO.getKey()); if (implementation != null) { throw new DuplicateException(implementationTO.getKey()); } return binder.getImplementationTO(implementationDAO.save(binder.create(implementationTO))); }