Package org.damour.base.client.objects

Examples of org.damour.base.client.objects.PermissibleObject


    user.setUsername("mdamour1976");
    session.save(user);

    // create 100 files which have global read = true
    for (int i = 0; i < 1; i++) {
      PermissibleObject parent = new PermissibleObject();
      parent.setName("globalRead:true " + i);
      parent.setOwner(user);
      parent.setGlobalRead(true);
      session.save(parent);

      for (int k = 0; k < 4; k++) {
        PermissibleObject childLevelOne = new PermissibleObject();
        childLevelOne.setName("globalRead:true " + i);
        childLevelOne.setOwner(user);
        childLevelOne.setGlobalRead(true);
        childLevelOne.setParent(parent);
        session.save(childLevelOne);

        for (int z = 0; z < 3; z++) {
          PermissibleObject childLevelTwo = new PermissibleObject();
          childLevelTwo.setName("globalRead:true " + z);
          childLevelTwo.setOwner(user);
          childLevelTwo.setGlobalRead(true);
          childLevelTwo.setParent(childLevelOne);
          session.save(childLevelTwo);

          for (int zz = 0; zz < 2; zz++) {
            PermissibleObject childLevelThree = new PermissibleObject();
            childLevelThree.setName("globalRead:true " + zz);
            childLevelThree.setOwner(user);
            childLevelThree.setGlobalRead(true);
            childLevelThree.setParent(childLevelTwo);
            session.save(childLevelThree);
          }

        }
      }
View Full Code Here


    List<Tag> tags = TagHelper.getTags(session);
    for (Tag tag : tags) {
      TagMembership tagMem = new TagMembership();
      tagMem.setTag(tag);
      PermissibleObject obj = new PermissibleObject();
      obj.setName("tagMembership aware");
      session.save(obj);
      tagMem.setPermissibleObject(obj);
      session.save(tagMem);
      System.out.println(tag.getName());
    }
View Full Code Here

    List<Tag> tags = TagHelper.getTags(session);
    for (Tag tag : tags) {
      Transaction tx = session.beginTransaction();
      TagMembership tagMem = new TagMembership();
      tagMem.setTag(tag);
      PermissibleObject obj = new PermissibleObject();
      obj.setName("tagMembership aware");
      session.save(obj);
      tagMem.setPermissibleObject(obj);
      session.save(tagMem);
      tx.commit();
View Full Code Here

    Tag tag = createTag("to-be-deleted-parent", "desc1", null);
    Tag tag2 = createTag("to-be-deleted-child", "desc2", tag);

    TagMembership tagMem = new TagMembership();
    tagMem.setTag(tag);
    PermissibleObject obj = new PermissibleObject();
    obj.setName("tags for this should not exist");
    session.save(obj);
    tagMem.setPermissibleObject(obj);
    session.save(tagMem);
    session.save(tag);
    session.save(tag2);
View Full Code Here

          return;
        }
        repositoryCallback.fileUploaded(id);
      }
    };
    PermissibleObject parentFolder = null;
    if (permissibleObject instanceof File) {
      parentFolder = permissibleObject.getParent();
    } else if (permissibleObject instanceof Folder) {
      parentFolder = (Folder) permissibleObject;
    }
View Full Code Here

  public PermissibleObject getNextUnratedPermissibleObject(String objectType) throws SimpleMessageException {
    if (StringUtils.isEmpty(objectType)) {
      throw new SimpleMessageException("Type not supplied.");
    }
    PermissibleObject object = null;
    User authUser = getAuthenticatedUser(session.get());
    object = RatingHelper.getNextUnratedPermissibleObject(session.get(), objectType, authUser, getVoterGUID());
    return object;
  }
View Full Code Here

      throw new SimpleMessageException("PermissibleObject not supplied with comment.");
    }
    User authUser = getAuthenticatedUser(session.get());
    Transaction tx = session.get().beginTransaction();
    try {
      PermissibleObject parentPermissibleObject = (PermissibleObject) session.get().load(PermissibleObject.class, comment.getParent().getId());
      parentPermissibleObject.setNumComments(parentPermissibleObject.getNumComments() + 1);
      comment.setParent(parentPermissibleObject);
      if (!SecurityHelper.doesUserHavePermission(session.get(), authUser, comment.getParent(), PERM.READ)) {
        throw new SimpleMessageException("User is not authorized to make comments on this content.");
      }
      if (!comment.getParent().isAllowComments()) {
View Full Code Here

    if (id == null) {
      throw new SimpleMessageException("Id not supplied.");
    }
    User authUser = getAuthenticatedUser(session.get());
    try {
      PermissibleObject permissibleObject = (PermissibleObject) session.get().load(PermissibleObject.class, id);
      if (!SecurityHelper.doesUserHavePermission(session.get(), authUser, permissibleObject, PERM.READ)) {
        throw new SimpleMessageException("User is not authorized to get this content.");
      }
      return permissibleObject;
    } catch (Throwable t) {
View Full Code Here

      }
      if (!SecurityHelper.doesUserHavePermission(session.get(), authUser, permissibleObject.getParent(), PERM.CREATE_CHILD)) {
        throw new SimpleMessageException("User is not authorized to write to parent folder.");
      }
      if (permissibleObject.getId() != null) {
        PermissibleObject hibNewObject = (PermissibleObject) session.get().load(PermissibleObject.class, permissibleObject.getId());
        if (hibNewObject != null) {
          if (!SecurityHelper.doesUserHavePermission(session.get(), authUser, hibNewObject, PERM.WRITE)) {
            throw new SimpleMessageException("User is not authorized to overwrite object.");
          }
          List<Field> fields = ReflectionCache.getFields(permissibleObject.getClass());
          for (Field field : fields) {
            try {
              field.set(hibNewObject, field.get(permissibleObject));
            } catch (Exception e) {
              e.printStackTrace();
              Logger.log(e);
            }
          }

          permissibleObject = hibNewObject;
        }
      }

      List<Field> fields = ReflectionCache.getFields(permissibleObject.getClass());
      for (Field field : fields) {
        try {
          // do not update parent permission only our 'owned' objects
          if (!"parent".equals(field.getName())) {
            Object obj = field.get(permissibleObject);
            if (obj instanceof PermissibleObject) {
              PermissibleObject childObj = (PermissibleObject) obj;
              PermissibleObject hibChild = (PermissibleObject) session.get().load(PermissibleObject.class, childObj.getId());
              hibChild.setGlobalRead(permissibleObject.isGlobalRead());
              hibChild.setGlobalWrite(permissibleObject.isGlobalWrite());
              hibChild.setGlobalExecute(permissibleObject.isGlobalExecute());
              hibChild.setGlobalCreateChild(permissibleObject.isGlobalCreateChild());
              field.set(permissibleObject, hibChild);
            }
          }
        } catch (Exception e) {
          Logger.log(e);
View Full Code Here

      throw new SimpleMessageException("User is not authenticated.");
    }
    Transaction tx = session.get().beginTransaction();
    try {
      User newOwner = ((User) session.get().load(User.class, permissibleObject.getOwner().getId()));
      PermissibleObject hibPermissibleObject = ((PermissibleObject) session.get().load(PermissibleObject.class, permissibleObject.getId()));
      if (!authUser.isAdministrator() && !hibPermissibleObject.getOwner().equals(authUser)) {
        throw new SimpleMessageException("User is not authorized to update this object.");
      }
      // update fields (for example, image has child permissibles)
      List<Field> fields = ReflectionCache.getFields(hibPermissibleObject.getClass());
      for (Field field : fields) {
        try {
          if (!field.getName().equals("parent") && PermissibleObject.class.isAssignableFrom(field.getType())) {
            Object obj = field.get(hibPermissibleObject);
            if (obj == null) {
              field.set(hibPermissibleObject, field.get(permissibleObject));
              obj = field.get(hibPermissibleObject);
              if (obj != null) {
                PermissibleObject hibSubObj = ((PermissibleObject) session.get().load(PermissibleObject.class, ((PermissibleObject) obj).getId()));
                obj = hibSubObj;
              }
            }
            if (obj != null) {
              PermissibleObject childObj = (PermissibleObject) obj;
              childObj.setGlobalRead(hibPermissibleObject.isGlobalRead());
              childObj.setGlobalWrite(hibPermissibleObject.isGlobalWrite());
              childObj.setGlobalExecute(hibPermissibleObject.isGlobalExecute());
              childObj.setGlobalCreateChild(hibPermissibleObject.isGlobalCreateChild());
              session.get().save(childObj);
            }
          }
          if (!field.getName().equals("parent")) {
            try {
View Full Code Here

TOP

Related Classes of org.damour.base.client.objects.PermissibleObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.