Search in sources :

Example 1 with FilteringResultSet

use of org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet in project alfresco-remote-api by Alfresco.

the class SearchSQLApiWebscript method execute.

@Override
public void execute(WebScriptRequest webScriptRequest, WebScriptResponse res) throws IOException {
    try {
        // Turn JSON into a Java object representation
        SearchSQLQuery searchQuery = extractJsonContent(webScriptRequest, assistant.getJsonHelper(), SearchSQLQuery.class);
        SearchParameters sparams = buildSearchParameters(searchQuery);
        ResultSet results = searchService.query(sparams);
        FilteringResultSet frs = (FilteringResultSet) results;
        SolrSQLJSONResultSet ssjr = (SolrSQLJSONResultSet) frs.getUnFilteredResultSet();
        // When solr format is requested pass the solr output directly.
        if (searchQuery.getFormat().equalsIgnoreCase("solr")) {
            res.getWriter().write(ssjr.getSolrResponse());
        } else {
            CollectionWithPagingInfo<TupleList> nodes = resultMapper.toCollectionWithPagingInfo(ssjr.getDocs(), searchQuery);
            renderJsonResponse(res, nodes, assistant.getJsonHelper());
        }
        setResponse(res, DEFAULT_SUCCESS);
    } catch (Exception exception) {
        renderException(exception, res, assistant);
    }
}
Also used : FilteringResultSet(org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet) TupleList(org.alfresco.rest.api.search.model.TupleList) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) SolrSQLJSONResultSet(org.alfresco.repo.search.impl.solr.SolrSQLJSONResultSet) ResultSet(org.alfresco.service.cmr.search.ResultSet) FilteringResultSet(org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet) SolrSQLJSONResultSet(org.alfresco.repo.search.impl.solr.SolrSQLJSONResultSet) SearchSQLQuery(org.alfresco.rest.api.search.model.SearchSQLQuery) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 2 with FilteringResultSet

use of org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet in project records-management by Alfresco.

the class RMAfterInvocationProvider method decide.

private ResultSet decide(Authentication authentication, Object object, ConfigAttributeDefinition config, ResultSet returnedObject) {
    if (returnedObject == null) {
        return null;
    }
    class RMFilteringResultSet extends FilteringResultSet {

        private long numberFound;

        public RMFilteringResultSet(ResultSet unfiltered, BitSet inclusionMask) {
            super(unfiltered, inclusionMask);
        }

        @Override
        public long getNumberFound() {
            return numberFound;
        }

        private void setNumberFound(long numberFound) {
            this.numberFound = numberFound;
        }
    }
    BitSet inclusionMask = new BitSet(returnedObject.length());
    RMFilteringResultSet filteringResultSet = new RMFilteringResultSet(returnedObject, inclusionMask);
    List<ConfigAttributeDefintion> supportedDefinitions = extractSupportedDefinitions(config);
    Integer maxSize = null;
    if (returnedObject.getResultSetMetaData().getSearchParameters().getMaxItems() >= 0) {
        maxSize = Integer.valueOf(returnedObject.getResultSetMetaData().getSearchParameters().getMaxItems());
    }
    if ((maxSize == null) && (returnedObject.getResultSetMetaData().getSearchParameters().getLimitBy() == LimitBy.FINAL_SIZE)) {
        maxSize = Integer.valueOf(returnedObject.getResultSetMetaData().getSearchParameters().getLimit());
    }
    // Allow for skip
    if ((maxSize != null) && (returnedObject.getResultSetMetaData().getSearchParameters().getSkipCount() >= 0)) {
        maxSize = Integer.valueOf(maxSize + returnedObject.getResultSetMetaData().getSearchParameters().getSkipCount());
    }
    if (supportedDefinitions.size() == 0) {
        if (maxSize == null) {
            return returnedObject;
        } else if (returnedObject.length() > maxSize.intValue()) {
            for (int i = 0; i < maxSize.intValue(); i++) {
                inclusionMask.set(i, true);
            }
            filteringResultSet.setResultSetMetaData(new SimpleResultSetMetaData(returnedObject.getResultSetMetaData().getLimitedBy(), PermissionEvaluationMode.EAGER, returnedObject.getResultSetMetaData().getSearchParameters()));
            return filteringResultSet;
        } else {
            for (int i = 0; i < returnedObject.length(); i++) {
                inclusionMask.set(i, true);
            }
            filteringResultSet.setResultSetMetaData(new SimpleResultSetMetaData(returnedObject.getResultSetMetaData().getLimitedBy(), PermissionEvaluationMode.EAGER, returnedObject.getResultSetMetaData().getSearchParameters()));
            return filteringResultSet;
        }
    }
    // record the start time
    long startTimeMillis = System.currentTimeMillis();
    // set the default, unlimited resultset type
    filteringResultSet.setResultSetMetaData(new SimpleResultSetMetaData(returnedObject.getResultSetMetaData().getLimitedBy(), PermissionEvaluationMode.EAGER, returnedObject.getResultSetMetaData().getSearchParameters()));
    for (int i = 0; i < returnedObject.length(); i++) {
        long currentTimeMillis = System.currentTimeMillis();
        // All permission checks must pass
        inclusionMask.set(i, true);
        if (!nodeService.exists(returnedObject.getNodeRef(i))) {
            inclusionMask.set(i, false);
        } else {
            int parentCheckRead = checkRead(returnedObject.getChildAssocRef(i).getParentRef());
            int childCheckRead = checkRead(returnedObject.getNodeRef(i));
            for (ConfigAttributeDefintion cad : supportedDefinitions) {
                NodeRef testNodeRef = returnedObject.getNodeRef(i);
                int checkRead = childCheckRead;
                if (cad.parent) {
                    testNodeRef = returnedObject.getChildAssocRef(i).getParentRef();
                    checkRead = parentCheckRead;
                }
                if (isUnfiltered(testNodeRef)) {
                    continue;
                }
                if (inclusionMask.get(i) && (testNodeRef != null) && (checkRead != AccessDecisionVoter.ACCESS_GRANTED)) {
                    inclusionMask.set(i, false);
                }
            }
        }
        // Bug out if we are limiting by size
        if ((maxSize != null) && (filteringResultSet.length() > maxSize.intValue())) {
            // Remove the last match to fix the correct size
            inclusionMask.set(i, false);
            filteringResultSet.setResultSetMetaData(new SimpleResultSetMetaData(LimitBy.FINAL_SIZE, PermissionEvaluationMode.EAGER, returnedObject.getResultSetMetaData().getSearchParameters()));
            break;
        }
    }
    filteringResultSet.setNumberFound(returnedObject.getNumberFound());
    return filteringResultSet;
}
Also used : FilteringResultSet(org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SimpleResultSetMetaData(org.alfresco.repo.search.SimpleResultSetMetaData) PagingLuceneResultSet(org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet) ResultSet(org.alfresco.service.cmr.search.ResultSet) FilteringResultSet(org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet) BitSet(java.util.BitSet)

Aggregations

FilteringResultSet (org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet)2 ResultSet (org.alfresco.service.cmr.search.ResultSet)2 IOException (java.io.IOException)1 BitSet (java.util.BitSet)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 SimpleResultSetMetaData (org.alfresco.repo.search.SimpleResultSetMetaData)1 PagingLuceneResultSet (org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet)1 SolrSQLJSONResultSet (org.alfresco.repo.search.impl.solr.SolrSQLJSONResultSet)1 SearchSQLQuery (org.alfresco.rest.api.search.model.SearchSQLQuery)1 TupleList (org.alfresco.rest.api.search.model.TupleList)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)1