コード例 #1
0
ファイル: TaskExecTest.java プロジェクト: PierreSmits/syncope
  @Test
  public void issueSYNCOPE214() {
    PropagationTask task = taskDAO.find(1L);
    assertNotNull(task);

    String faultyMessage = "A faulty message";
    faultyMessage = faultyMessage.replace('a', '\0');

    TaskExec exec = entityFactory.newEntity(TaskExec.class);
    exec.setStartDate(new Date());
    exec.setEndDate(new Date());
    exec.setStatus(PropagationTaskExecStatus.SUCCESS.name());
    exec.setMessage(faultyMessage);

    task.addExec(exec);
    exec.setTask(task);

    exec = taskExecDAO.save(exec);
    assertNotNull(exec);

    assertEquals(faultyMessage.replace('\0', '\n'), exec.getMessage());
  }
コード例 #2
0
  @Transactional(readOnly = true)
  @Override
  public void before(final PropagationTask task, final ConnectorObject beforeObj) {
    super.before(task, beforeObj);

    Provision provision = task.getResource().getProvision(anyTypeDAO.findGroup());
    if (AnyTypeKind.USER == task.getAnyTypeKind() && provision.getMapping() != null) {
      User user = userDAO.find(task.getAnyKey());
      if (user != null) {
        List<String> groupConnObjectLinks = new ArrayList<>();
        for (Group group : userDAO.findAllGroups(user)) {
          if (group.getResourceNames().contains(task.getResource().getKey())
              && StringUtils.isNotBlank(provision.getMapping().getConnObjectLink())) {

            LOG.debug("Evaluating connObjectLink for {}", group);

            JexlContext jexlContext = new MapContext();
            JexlUtils.addFieldsToContext(group, jexlContext);
            JexlUtils.addPlainAttrsToContext(group.getPlainAttrs(), jexlContext);
            JexlUtils.addDerAttrsToContext(group, jexlContext);

            String groupConnObjectLinkLink =
                JexlUtils.evaluate(provision.getMapping().getConnObjectLink(), jexlContext);
            LOG.debug("ConnObjectLink for {} is '{}'", group, groupConnObjectLinkLink);
            if (StringUtils.isNotBlank(groupConnObjectLinkLink)) {
              groupConnObjectLinks.add(groupConnObjectLinkLink);
            }
          }
        }
        LOG.debug("Group connObjectLinks to propagate for membership: {}", groupConnObjectLinks);

        Set<Attribute> attributes = new HashSet<>(task.getAttributes());

        Set<String> groups = new HashSet<>(groupConnObjectLinks);
        Attribute ldapGroups = AttributeUtil.find(getGroupMembershipAttrName(), attributes);

        if (ldapGroups != null) {
          for (Object obj : ldapGroups.getValue()) {
            groups.add(obj.toString());
          }
        }

        attributes.add(AttributeBuilder.build(getGroupMembershipAttrName(), groups));
        task.setAttributes(attributes);
      }
    } else {
      LOG.debug("Not about user, or group mapping missing for resource: not doing anything");
    }
  }