private void setTemplates(final RealmTO realmTO, final Realm realm) { // validate JEXL expressions from templates and proceed if fine templateUtils.check(realmTO.getTemplates(), ClientExceptionType.InvalidRealm); realmTO.getTemplates().forEach((key, template) -> { AnyType type = anyTypeDAO.find(key); if (type == null) { LOG.debug("Invalid AnyType {} specified, ignoring...", key); } else { AnyTemplateRealm anyTemplate = realm.getTemplate(type).orElse(null); if (anyTemplate == null) { anyTemplate = entityFactory.newEntity(AnyTemplateRealm.class); anyTemplate.setAnyType(type); anyTemplate.setRealm(realm); realm.add(anyTemplate); } anyTemplate.set(template); } }); // remove all templates not contained in the TO realm.getTemplates(). removeIf(template -> !realmTO.getTemplates().containsKey(template.getAnyType().getKey())); }
protected Pair<TO, List<LogicActions>> beforeCreate(final TO input) { Realm realm = realmDAO.findByFullPath(input.getRealm()); if (realm == null) { SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRealm); sce.getElements().add(input.getRealm()); throw sce; } AnyType anyType = input instanceof UserTO ? anyTypeDAO.findUser() : input instanceof GroupTO ? anyTypeDAO.findGroup() : anyTypeDAO.find(input.getType()); if (anyType == null) { SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidAnyType); sce.getElements().add(input.getType()); throw sce; } TO any = input; templateUtils.apply(any, realm.getTemplate(anyType)); List<LogicActions> actions = getActions(realm); for (LogicActions action : actions) { any = action.beforeCreate(any); } LOG.debug("Input: {}\nOutput: {}\n", input, any); return ImmutablePair.of(any, actions); }