Пример #1
0
 public boolean checkAccessRights(Context context) throws ProcessingException {
   CoralSession coralSession = (CoralSession) context.getAttribute(CoralSession.class);
   RequestParameters parameters = RequestParameters.getRequestParameters(context);
   try {
     NavigationNodeResource node = getCmsData(context).getNode();
     NavigationNodeResource originalNode =
         NavigationNodeResourceImpl.getNavigationNodeResource(
             coralSession, parameters.getLong("original_node_id"));
     Permission addInboundAlias =
         coralSession.getSecurity().getUniquePermission("cms.structure.add_inbound_alias");
     return node.canAddChild(coralSession, coralSession.getUserSubject())
         && coralSession.getUserSubject().hasPermission(originalNode, addInboundAlias);
   } catch (EntityDoesNotExistException e) {
     throw new ProcessingException("missing or invalid parameters", e);
   }
 }
Пример #2
0
  public void process(
      Parameters parameters,
      MVCContext mvcContext,
      TemplatingContext templatingContext,
      HttpContext httpContext,
      I18nContext i18nContext,
      CoralSession coralSession)
      throws ProcessingException {
    try {
      CmsData cmsData = cmsDataFactory.getCmsData(context);
      Parameters config = cmsData.getComponent().getConfiguration();
      CategoryQueryResource includeQuery = myDocumentsImpl.getQueryResource("include", config);
      CategoryQueryResource excludeQuery = myDocumentsImpl.getQueryResource("exclude", config);
      String whereClause = "created_by = " + coralSession.getUserSubject().getIdString();

      TableModel<DocumentNodeResource> model;
      if (includeQuery == null) {
        model = myDocumentsImpl.siteBasedModel(cmsData, i18nContext.get(), whereClause);
      } else {
        model =
            myDocumentsImpl.queryBasedModel(
                includeQuery, excludeQuery, cmsData, i18nContext.get(), whereClause);
      }

      List<TableFilter<? super DocumentNodeResource>> filters =
          myDocumentsImpl.excludeStatesFilter("expired");

      TableState state =
          tableStateManager.getState(
              context,
              this.getClass().getName()
                  + ":"
                  + cmsData.getNode().getIdString()
                  + ":"
                  + cmsData.getComponent().getInstanceName());
      if (state.isNew()) {
        state.setTreeView(false);
        state.setSortColumnName(config.get("sort_column", "creation.time"));
        state.setAscSort(config.getBoolean("sort_dir", false));
        state.setPageSize(config.getInt("page_size", 5));
      }
      templatingContext.put("table", new TableTool<DocumentNodeResource>(state, filters, model));
      templatingContext.put("documentState", new DocumentStateTool(coralSession, logger));
      templatingContext.put("header", config.get("header", ""));
      final long moreNodeId = config.getLong("more_node_id", -1l);
      if (moreNodeId != -1l) {
        templatingContext.put("moreNode", coralSession.getStore().getResource(moreNodeId));
      }
    } catch (Exception e) {
      throw new ProcessingException("internal errror", e);
    }
  }
Пример #3
0
 public boolean checkAccessRights(Context context) throws ProcessingException {
   Parameters parameters = RequestParameters.getRequestParameters(context);
   CoralSession coralSession = (CoralSession) context.getAttribute(CoralSession.class);
   try {
     long dirId = parameters.getLong("parent_id", -1);
     if (dirId == -1) {
       return true;
     } else {
       Resource resource = coralSession.getStore().getResource(dirId);
       Permission permission = coralSession.getSecurity().getUniquePermission("cms.files.write");
       return coralSession.getUserSubject().hasPermission(resource, permission);
     }
   } catch (Exception e) {
     logger.error("Subject has no rights to view this screen", e);
     return false;
   }
 }
Пример #4
0
  /** Performs the feed updates. */
  public void execute(CoralSession coralSession, String[] args) {
    // prepare for feeds updates
    deletedFeedsIds.clear();
    coralSession.getEvent().addResourceDeletionListener(this, httpFeedResourceClass);

    Calendar cal = Calendar.getInstance();
    Date now = cal.getTime();

    SiteResource[] sites = siteService.getSites(coralSession);
    for (int i = 0; i < sites.length; i++) {
      try {
        HttpFeedResource[] feeds = httpFeedService.getFeeds(coralSession, sites[i]);

        for (int j = 0; j < feeds.length; j++) {
          HttpFeedResource feed = feeds[j];

          // check if feed needs to be refreshed
          boolean makeRefresh = (feed.getFailedUpdates() > 0) || (feed.getLastUpdate() == null);
          if (!makeRefresh) {
            // calculate next update time
            cal.setTime(feed.getLastUpdate());
            cal.add(Calendar.MINUTE, feed.getInterval());
            Date nextUpdate = cal.getTime();

            makeRefresh = nextUpdate.before(now);
          }

          if (makeRefresh) {
            String content = httpFeedService.getContent(feed.getUrl());
            synchronized (feed) {
              if (!deletedFeedsIds.contains(feed.getIdObject())) {
                httpFeedService.refreshFeed(feed, content, coralSession.getUserSubject());
              }
            }
          }
        }
      } catch (HttpFeedException e) {
        log.error("Cannot get http feeds for the site '" + sites[i].getName() + "'", e);
      }
    }

    // cleanup after feed updates
    coralSession.getEvent().removeResourceDeletionListener(this, httpFeedResourceClass);
    deletedFeedsIds.clear();
  }
Пример #5
0
 public boolean checkAccessRights(Context context) throws ProcessingException {
   CoralSession coralSession = (CoralSession) context.getAttribute(CoralSession.class);
   try {
     SiteResource site = getSite();
     Role role = null;
     if (site != null) {
       CmsData cmsData = cmsDataFactory.getCmsData(context);
       if (!cmsData.isApplicationEnabled("statistics")) {
         logger.debug("Application 'statistics' not enabled in site");
         return false;
       }
       role = site.getAdministrator();
     } else {
       role = coralSession.getSecurity().getUniqueRole("cms.administrator");
     }
     return coralSession.getUserSubject().hasRole(role);
   } catch (ProcessingException e) {
     logger.error("Subject has no rights to view this screen", e);
     return false;
   }
 }
Пример #6
0
  /** Performs the action. */
  public void execute(
      Context context,
      Parameters parameters,
      MVCContext mvcContext,
      TemplatingContext templatingContext,
      HttpContext httpContext,
      CoralSession coralSession)
      throws ProcessingException {

    Subject subject = coralSession.getUserSubject();

    IndexResource index = getIndex(coralSession, parameters);
    try {
      searchService.getIndexingFacility().deleteDeleted(coralSession, index);
    } catch (SearchException e) {
      templatingContext.put("result", "exception");
      templatingContext.put("trace", new StackTrace(e));
      logger.error("problem incrementally cleaning up index '" + index.getIdString() + "'", e);
      return;
    }
    templatingContext.put("result", "cleaned_up_successfully");
  }
Пример #7
0
  /** Performs the action. */
  public void execute(
      Context context,
      Parameters parameters,
      MVCContext mvcContext,
      TemplatingContext templatingContext,
      HttpContext httpContext,
      CoralSession coralSession)
      throws ProcessingException {
    Subject subject = coralSession.getUserSubject();
    Long parentNodeId = parameters.getLong("node_id", -1L);
    Long originalNodeId = parameters.getLong("original_node_id", -1L);
    String name = parameters.get("name", "");
    String title = parameters.get("title", "");

    if (parentNodeId == -1L || originalNodeId == -1L) {
      return;
    }

    try {
      NavigationNodeResource parent =
          (NavigationNodeResource) coralSession.getStore().getResource(parentNodeId);
      DocumentNodeResource originalDocument =
          (DocumentNodeResource) coralSession.getStore().getResource(originalNodeId);
      DocumentAliasResource node =
          structureService.addDocumentAlias(
              coralSession, originalDocument, name, title, parent, subject);
      parameters.set("node_id", node.getIdString());
    } catch (Exception e) {
      templatingContext.put("result", "exception");
      logger.error("StructureException: ", e);
      templatingContext.put("trace", new StackTrace(e));
      return;
    }
    cmsDataFactory.removeCmsData(context);
    templatingContext.put("result", "added_successeditfully");
  }