Exemplo n.º 1
0
 private boolean hasPermission(String userName, Value[] roles) throws Exception {
   IdentityRegistry identityRegistry = getApplicationComponent(IdentityRegistry.class);
   if (IdentityConstants.SYSTEM.equalsIgnoreCase(userName)) {
     return true;
   }
   Identity identity = identityRegistry.getIdentity(userName);
   if (identity == null) {
     return false;
   }
   for (int i = 0; i < roles.length; i++) {
     String role = roles[i].getString();
     if ("*".equalsIgnoreCase(role)) return true;
     MembershipEntry membershipEntry = MembershipEntry.parse(role);
     if (membershipEntry == null) return false;
     if (identity.isMemberOf(membershipEntry)) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 2
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;
   }
 }
Exemplo n.º 3
0
  /*
   * (non-Javadoc)
   * @see
   * org.exoplatform.services.wcm.search.SiteSearchService#searchSiteContents
   * (org.exoplatform.services.wcm.search.QueryCriteria,
   * org.exoplatform.services.jcr.ext.common.SessionProvider, int)
   */
  public AbstractPageList<ResultNode> searchSiteContents(
      SessionProvider sessionProvider,
      QueryCriteria queryCriteria,
      int pageSize,
      boolean isSearchContent)
      throws Exception {
    ManageableRepository currentRepository = repositoryService.getCurrentRepository();
    NodeLocation location = configurationService.getLivePortalsLocation();
    Session session = sessionProvider.getSession(location.getWorkspace(), currentRepository);
    if (queryCriteria.isSearchWebpage()) {
      session = sessionProvider.getSession("portal-system", WCMCoreUtils.getRepository());
    }
    QueryManager queryManager = session.getWorkspace().getQueryManager();
    long startTime = System.currentTimeMillis();
    Query query = createQuery(queryCriteria, queryManager);
    String suggestion = getSpellSuggestion(queryCriteria.getKeyword(), currentRepository);
    AbstractPageList<ResultNode> pageList = null;
    if (LOG.isDebugEnabled()) {
      LOG.debug("execute query: " + query.getStatement().toLowerCase());
    }
    pageList =
        PageListFactory.createPageList(
            query.getStatement(),
            session.getWorkspace().getName(),
            query.getLanguage(),
            IdentityConstants.SYSTEM.equals(session.getUserID()),
            new NodeFilter(isSearchContent, queryCriteria),
            new DataCreator(),
            pageSize,
            0,
            queryCriteria);

    long queryTime = System.currentTimeMillis() - startTime;
    pageList.setQueryTime(queryTime);
    pageList.setSpellSuggestion(suggestion);
    return pageList;
  }