}
}
}
private void fill(final AbstractSyncTask task, final AbstractSyncTaskTO taskTO) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSyncTask);
if (task instanceof PushTask && taskTO instanceof PushTaskTO) {
final PushTask pushTask = (PushTask) task;
final PushTaskTO pushTaskTO = (PushTaskTO) taskTO;
pushTask.setUserFilter(pushTaskTO.getUserFilter());
pushTask.setRoleFilter(pushTaskTO.getRoleFilter());
pushTask.setMatchingRule(pushTaskTO.getMatchingRule() == null
? MatchingRule.LINK : pushTaskTO.getMatchingRule());
pushTask.setUnmatchingRule(pushTaskTO.getUnmatchingRule() == null
? UnmatchingRule.ASSIGN : pushTaskTO.getUnmatchingRule());
} else if (task instanceof SyncTask && taskTO instanceof SyncTaskTO) {
final SyncTask syncTask = (SyncTask) task;
final SyncTaskTO syncTaskTO = (SyncTaskTO) taskTO;
syncTask.setMatchingRule(syncTaskTO.getMatchingRule() == null
? MatchingRule.UPDATE : syncTaskTO.getMatchingRule());
syncTask.setUnmatchingRule(syncTaskTO.getUnmatchingRule() == null
? UnmatchingRule.PROVISION : syncTaskTO.getUnmatchingRule());
// 1. validate JEXL expressions in user and role templates
if (syncTaskTO.getUserTemplate() != null) {
UserTO template = syncTaskTO.getUserTemplate();
if (StringUtils.isNotBlank(template.getUsername())
&& !JexlUtil.isExpressionValid(template.getUsername())) {
sce.getElements().add("Invalid JEXL: " + template.getUsername());
}
if (StringUtils.isNotBlank(template.getPassword())
&& !JexlUtil.isExpressionValid(template.getPassword())) {
sce.getElements().add("Invalid JEXL: " + template.getPassword());
}
checkJexl(template, sce);
for (MembershipTO memb : template.getMemberships()) {
checkJexl(memb, sce);
}
}
if (syncTaskTO.getRoleTemplate() != null) {
RoleTO template = syncTaskTO.getRoleTemplate();
if (StringUtils.isNotBlank(template.getName()) && !JexlUtil.isExpressionValid(template.getName())) {
sce.getElements().add("Invalid JEXL: " + template.getName());
}
checkJexl(template, sce);
}
if (!sce.isEmpty()) {
throw sce;
}
// 2. all JEXL expressions are valid: accept user and role templates
syncTask.setUserTemplate(syncTaskTO.getUserTemplate());