Example #1
0
 @Override
 public CreateRequest process(CreateRequest input)
     throws PluginExecutionException, StopProcessingException {
   List<Metacard> updatedMetacardList =
       input
           .getMetacards()
           .stream()
           .filter(
               m ->
                   !HistoryMetacardImpl.getVersionHistoryMetacardType()
                       .equals(m.getMetacardType()))
           .map(
               m ->
                   new HistoryMetacardImpl(
                       m, HistoryMetacardImpl.Action.CREATED, SecurityUtils.getSubject()))
           .collect(Collectors.toList());
   updatedMetacardList.addAll(input.getMetacards());
   return new CreateRequestImpl(updatedMetacardList, input.getProperties());
 }
Example #2
0
  @Override
  public CreateRequest processPreCreate(CreateRequest input) throws StopProcessingException {
    KeyValueCollectionPermission securityPermission =
        new KeyValueCollectionPermission(CollectionPermission.CREATE_ACTION);
    List<Metacard> metacards = input.getMetacards();
    Subject subject = getSubject(input);
    Subject systemSubject = getSystemSubject();
    List<String> notPermittedIds = new ArrayList<>();
    for (Metacard metacard : metacards) {
      Attribute attr = metacard.getAttribute(Metacard.SECURITY);
      if (!checkPermissions(attr, securityPermission, subject, CollectionPermission.CREATE_ACTION)
          || !checkPermissions(
              attr, securityPermission, systemSubject, CollectionPermission.CREATE_ACTION)) {
        notPermittedIds.add(metacard.getId());
      }
    }
    if (!notPermittedIds.isEmpty()) {
      throw new StopProcessingException(
          "Metacard creation not permitted for: [ " + listToString(notPermittedIds) + " ]");
    }

    return input;
  }