Ejemplo n.º 1
0
  @Override
  public void SetDefaultGroup(PDPGroup group) throws PAPException {

    boolean changesMade = false;
    for (PDPGroup aGroup : groups) {
      if (aGroup.getId().equals(group.getId())) {
        if (!aGroup.isDefaultGroup()) {
          // TODO - since the original code checked for type we do also.
          if (aGroup instanceof StdPDPGroup) {
            ((StdPDPGroup) aGroup).setDefault(true);
            changesMade = true;
          } else {
            throw new IllegalArgumentException(
                "Group in groups of unknown type '" + aGroup.getClass().getName() + "'");
          }
        }
      } else {
        // not the new default group
        if (aGroup.isDefaultGroup()) {
          // TODO - since the original code checked for type we do also.
          if (aGroup instanceof StdPDPGroup) {
            ((StdPDPGroup) aGroup).setDefault(false);
            changesMade = true;
          } else {
            throw new IllegalArgumentException(
                "Group in groups of unknown type '" + aGroup.getClass().getName() + "'");
          }
        }
      }
    }
    if (changesMade) {
      this.doSave();
    }
  }
Ejemplo n.º 2
0
 @Override
 public void removePolicy(PDPPolicy policy, PDPGroup group) throws PAPException {
   if (group == null) {
     throw new NullPointerException();
   }
   if (group instanceof StdPDPGroup && this.groups.contains(group)) {
     ((StdPDPGroup) group).removePolicy(policy);
     return;
   }
   logger.warn("unknown PDP Group: " + group);
   throw new PAPException("Unknown PDP Group: " + group.getId());
 }
Ejemplo n.º 3
0
 @Override
 public void publishPolicy(
     String id, String name, boolean isRoot, InputStream policy, PDPGroup group)
     throws PAPException {
   if (group == null) {
     throw new NullPointerException();
   }
   if (group instanceof StdPDPGroup && this.groups.contains(group)) {
     ((StdPDPGroup) group).publishPolicy(id, name, isRoot, policy);
     return;
   }
   logger.warn("unknown PDP Group: " + group);
   throw new PAPException("Unknown PDP Group: " + group.getId());
 }
Ejemplo n.º 4
0
  @Override
  public void updateGroup(PDPGroup group) throws PAPException {
    if (group == null || group.getId() == null) {
      throw new PAPException("Group or id is null");
    }
    if (group.getName() == null || group.getName().trim().length() == 0) {
      throw new PAPException("New name for group cannot be null or blank");
    }
    StdPDPGroup existingGroup = (StdPDPGroup) getGroup(group.getId());
    if (existingGroup == null) {
      throw new PAPException("Update found no existing group with id '" + group.getId() + "'");
    }

    // We do dramatically different things when the Name changes
    // because the Name is essentially the identity of the group (as the User knows it) so when the
    // Identity changes we have to change the group ID.
    if (group.getName().equals(existingGroup.getName())) {

      // update the disk
      try {
        ((StdPDPGroup) group).saveGroupConfiguration();
      } catch (IOException e) {
        throw new PAPException(
            "Unable to save new configuration for '" + group.getName() + "': " + e.getMessage());
      }
      // update the group in the set by simply replacing the old instance with the new one
      this.groups.remove(existingGroup);
      this.groups.add((StdPDPGroup) group);

    } else {
      // the name/identity of the group has changed
      // generate the new id
      String newId = createNewPDPGroupId(group.getName());

      // make sure no other group uses the new id
      for (PDPGroup g : groups) {
        if (g.getId().equals(newId)) {
          throw new PAPException(
              "Replacement name maps to ID '" + newId + "' which is already in use");
        }
      }
      ((StdPDPGroup) group).setId(newId);

      // rename the existing directory to the new id
      Path oldPath = existingGroup.getDirectory();
      Path newPath = Paths.get(oldPath.getParent().toString(), newId);
      ((StdPDPGroup) group).setDirectory(newPath);

      try {
        boolean success = oldPath.toFile().renameTo(newPath.toFile());
        if (!success) {
          throw new PAPException("Unable to rename directory; reason unknown");
        }
      } catch (Exception e) {
        logger.error("Move '" + oldPath + "' to '" + newPath + "': " + e.getMessage(), e);
        throw new PAPException(
            "Unable to move directory from '"
                + oldPath
                + "' to '"
                + newPath
                + "': "
                + e.getMessage());
      }
      // update the disk
      try {
        ((StdPDPGroup) group).saveGroupConfiguration();
      } catch (IOException e) {
        throw new PAPException(
            "Unable to save new configuration for '" + group.getName() + "': " + e.getMessage());
      }

      // save the new group into the Set
      groups.remove(existingGroup);
      groups.add((StdPDPGroup) group);
    }

    // perhaps only the group changed, but if the name/id changed it may look to a listener like
    // more than
    // one group
    changed();
  }