Ejemplo n.º 1
0
  private List<AccountPolicy> getAccountPolicies(final User user) {
    List<AccountPolicy> policies = new ArrayList<>();

    // add resource policies
    for (ExternalResource resource : findAllResources(user)) {
      AccountPolicy policy = resource.getAccountPolicy();
      if (policy != null) {
        policies.add(policy);
      }
    }

    // add realm policies
    for (Realm realm : realmDAO.findAncestors(user.getRealm())) {
      AccountPolicy policy = realm.getAccountPolicy();
      if (policy != null) {
        policies.add(policy);
      }
    }

    return policies;
  }
  @Test
  public void issue42() {
    PlainSchema userId = plainSchemaDAO.find("userId");

    Set<MappingItem> beforeUserIdMappings = new HashSet<>();
    for (ExternalResource res : resourceDAO.findAll()) {
      if (res.getProvision(anyTypeDAO.findUser()) != null
          && res.getProvision(anyTypeDAO.findUser()).getMapping() != null) {

        for (MappingItem mapItem :
            res.getProvision(anyTypeDAO.findUser()).getMapping().getItems()) {
          if (userId.getKey().equals(mapItem.getIntAttrName())) {
            beforeUserIdMappings.add(mapItem);
          }
        }
      }
    }

    ResourceTO resourceTO = new ResourceTO();
    resourceTO.setKey("resource-issue42");
    resourceTO.setConnector(100L);
    resourceTO.setEnforceMandatoryCondition(true);

    ProvisionTO provisionTO = new ProvisionTO();
    provisionTO.setAnyType(AnyTypeKind.USER.name());
    provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
    resourceTO.getProvisions().add(provisionTO);

    MappingTO mapping = new MappingTO();
    provisionTO.setMapping(mapping);

    MappingItemTO item = new MappingItemTO();
    item.setIntAttrName("userId");
    item.setIntMappingType(IntMappingType.UserPlainSchema);
    item.setExtAttrName("campo1");
    item.setConnObjectKey(true);
    item.setMandatoryCondition("false");
    item.setPurpose(MappingPurpose.BOTH);
    mapping.setConnObjectKeyItem(item);

    ExternalResource resource = resourceDataBinder.create(resourceTO);
    resource = resourceDAO.save(resource);
    assertNotNull(resource);
    assertNotNull(resource.getProvision(anyTypeDAO.findUser()).getMapping());
    assertEquals(1, resource.getProvision(anyTypeDAO.findUser()).getMapping().getItems().size());

    resourceDAO.flush();

    ExternalResource actual = resourceDAO.find("resource-issue42");
    assertNotNull(actual);
    assertEquals(resource, actual);

    userId = plainSchemaDAO.find("userId");

    Set<MappingItem> afterUserIdMappings = new HashSet<>();
    for (ExternalResource res : resourceDAO.findAll()) {
      if (res.getProvision(anyTypeDAO.findUser()) != null
          && res.getProvision(anyTypeDAO.findUser()).getMapping() != null) {

        for (MappingItem mapItem :
            res.getProvision(anyTypeDAO.findUser()).getMapping().getItems()) {
          if (userId.getKey().equals(mapItem.getIntAttrName())) {
            afterUserIdMappings.add(mapItem);
          }
        }
      }
    }

    assertEquals(beforeUserIdMappings.size(), afterUserIdMappings.size() - 1);
  }