Example #1
0
  @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true)
  @Override
  public Collection<ExternalResource> findAllResources(final User user) {
    Set<ExternalResource> result = new HashSet<>();
    result.addAll(user.getResources());
    for (Group group : findAllGroups(user)) {
      result.addAll(group.getResources());
    }

    return result;
  }
Example #2
0
  @Override
  public void delete(final User user) {
    for (Role role : findDynRoleMemberships(user)) {
      role.getDynMembership().remove(user);
    }
    for (Group group : findDynGroupMemberships(user)) {
      group.getUDynMembership().remove(user);
    }

    entityManager().remove(user);
  }
  @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");
    }
  }