예제 #1
0
 /**
  * Get an ItemLocation object by an item
  *
  * @param item the item
  * @return a ItemLocation object
  */
 public static final ItemLocation getItemLocationByItem(final Item item) {
   Session session = null;
   try {
     session = item.getSession();
     String repository =
         ((ManageableRepository) session.getRepository()).getConfiguration().getName();
     String workspace = session.getWorkspace().getName();
     String path = item.getPath();
     String uuid = null;
     try {
       if (item instanceof Node) uuid = ((Node) item).getUUID();
     } catch (Exception e) {
       // Do nothing}
     }
     boolean isSystemSession = IdentityConstants.SYSTEM.equals(session.getUserID());
     return new ItemLocation(repository, workspace, path, uuid, isSystemSession);
   } catch (Exception e) {
     return null;
   }
 }
  @Override
  public boolean hasPrivileges(final String absPath, final Privilege[] privileges)
      throws PathNotFoundException, RepositoryException {

    if (supportPrivileges) {
      // if the node is created in the same session, return true
      for (Item item : session.getNewItems()) {
        if (item.getPath().equals(absPath)) {
          return true;
        }
      }

      // check privilege names
      return hasPrivilegesLegacy(absPath, privileges);
    } else {
      // check ACLs
      Set<String> privs = new HashSet<>();
      for (Privilege privilege : privileges) {
        privs.add(privilege.getName());
      }
      String mountPoint = session.getRepository().getStoreProvider().getMountPoint();
      Session securitySession =
          JCRSessionFactory.getInstance()
              .getCurrentSystemSession(session.getWorkspace().getName(), null, null);
      PathWrapper pathWrapper =
          new ExternalPathWrapperImpl(
              StringUtils.equals(absPath, "/") ? mountPoint : mountPoint + absPath,
              securitySession);
      return AccessManagerUtils.isGranted(
          pathWrapper,
          privs,
          securitySession,
          jahiaPrincipal,
          workspaceName,
          false,
          pathPermissionCache,
          compiledAcls,
          registry);
    }
  }