Ejemplo n.º 1
0
  @Override
  public void authorizeAction(
      Context c, EPerson e, DSpaceObject o, int action, boolean useInheritance)
      throws AuthorizeException, SQLException {
    if (o == null) {
      // action can be -1 due to a null entry
      String actionText;

      if (action == -1) {
        actionText = "null";
      } else {
        actionText = Constants.actionText[action];
      }

      UUID userid;

      if (e == null) {
        userid = null;
      } else {
        userid = e.getID();
      }

      throw new AuthorizeException(
          "Authorization attempted on null DSpace object " + actionText + " by user " + userid);
    }

    if (!authorize(c, o, action, e, useInheritance)) {
      // denied, assemble and throw exception
      int otype = o.getType();
      UUID oid = o.getID();
      UUID userid;

      if (e == null) {
        userid = null;
      } else {
        userid = e.getID();
      }

      //            AuthorizeException j = new AuthorizeException("Denied");
      //            j.printStackTrace();
      // action can be -1 due to a null entry
      String actionText;

      if (action == -1) {
        actionText = "null";
      } else {
        actionText = Constants.actionText[action];
      }

      throw new AuthorizeException(
          "Authorization denied for action "
              + actionText
              + " on "
              + Constants.typeText[otype]
              + ":"
              + oid
              + " by user "
              + userid,
          o,
          action);
    }
  }