Search in sources :

Example 91 with ResultSet

use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.

the class EmailServiceImpl method getUsername.

/**
 * Authenticate in Alfresco repository by sender's e-mail address.
 *
 * @param from Sender's email address
 * @return User name or null if the user does not exist.
 * @throws EmailMessageException Exception will be thrown if authentication is failed.
 */
private String getUsername(String from) {
    String userName = null;
    if (from == null || from.length() == 0) {
        return null;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("getUsername from: " + from);
    }
    StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
    String query = "TYPE:cm\\:person AND =@cm\\:email:\"" + from + "\"";
    ResultSet resultSet = searchService.query(storeRef, SearchService.LANGUAGE_FTS_ALFRESCO, query);
    try {
        if (resultSet == null || resultSet.length() == 0) {
            return null;
        }
        if (resultSet.length() > 1) {
            if (logger.isWarnEnabled()) {
                logger.warn("found more as one result for email '" + from + "'. The first will be used");
            }
        }
        NodeRef userNode = resultSet.getNodeRef(0);
        if (nodeService.exists(userNode)) {
            userName = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(userNode, ContentModel.PROP_USERNAME));
            if (logger.isDebugEnabled()) {
                logger.debug("found username: " + userName);
            }
        } else {
            // The Lucene index returned a dead result
            throw new EmailMessageException(ERR_UNKNOWN_SOURCE_ADDRESS, from);
        }
    } finally {
        if (resultSet != null) {
            resultSet.close();
        }
    }
    return userName;
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResultSet(org.alfresco.service.cmr.search.ResultSet) EmailMessageException(org.alfresco.service.cmr.email.EmailMessageException)

Example 92 with ResultSet

use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.

the class ACLEntryAfterInvocationProvider method decide.

@SuppressWarnings("rawtypes")
public Object decide(Authentication authentication, Object object, ConfigAttributeDefinition config, Object returnedObject) throws AccessDeniedException {
    if (log.isDebugEnabled() && object instanceof MethodInvocation) {
        MethodInvocation mi = (MethodInvocation) object;
        log.debug("Method: " + mi.getMethod().toString());
    }
    try {
        if (AuthenticationUtil.isRunAsUserTheSystemUser()) {
            if (log.isDebugEnabled()) {
                log.debug("Allowing system user access");
            }
            return returnedObject;
        } else if (returnedObject == null) {
            if (log.isDebugEnabled()) {
                log.debug("Allowing null object access");
            }
            return null;
        } else if (PermissionCheckedValue.class.isAssignableFrom(returnedObject.getClass())) {
            // The security provider was not already present
            return decide(authentication, object, config, (PermissionCheckedValue) returnedObject);
        } else if (PermissionCheckValue.class.isAssignableFrom(returnedObject.getClass())) {
            return decide(authentication, object, config, (PermissionCheckValue) returnedObject);
        } else if (StoreRef.class.isAssignableFrom(returnedObject.getClass())) {
            return decide(authentication, object, config, nodeService.getRootNode((StoreRef) returnedObject)).getStoreRef();
        } else if (NodeRef.class.isAssignableFrom(returnedObject.getClass())) {
            return decide(authentication, object, config, (NodeRef) returnedObject);
        } else if (Pair.class.isAssignableFrom(returnedObject.getClass())) {
            return decide(authentication, object, config, (Pair) returnedObject);
        } else if (ChildAssociationRef.class.isAssignableFrom(returnedObject.getClass())) {
            return decide(authentication, object, config, (ChildAssociationRef) returnedObject);
        } else if (SolrJSONResultSet.class.isAssignableFrom(returnedObject.getClass()) && (!anyDenyDenies || (!postProcessDenies && ((SolrJSONResultSet) returnedObject).getProcessedDenies()))) {
            return returnedObject;
        } else if (CMISResultSet.class.isAssignableFrom(returnedObject.getClass())) {
            return returnedObject;
        } else if (PagingLuceneResultSet.class.isAssignableFrom(returnedObject.getClass())) {
            return decide(authentication, object, config, (PagingLuceneResultSet) returnedObject);
        } else if (ResultSet.class.isAssignableFrom(returnedObject.getClass())) {
            return decide(authentication, object, config, (ResultSet) returnedObject);
        } else if (QueryEngineResults.class.isAssignableFrom(returnedObject.getClass())) {
            return decide(authentication, object, config, (QueryEngineResults) returnedObject);
        } else if (Collection.class.isAssignableFrom(returnedObject.getClass())) {
            return decide(authentication, object, config, (Collection) returnedObject);
        } else if (returnedObject.getClass().isArray()) {
            return decide(authentication, object, config, (Object[]) returnedObject);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Uncontrolled object - access allowed for " + object.getClass().getName());
            }
            return returnedObject;
        }
    } catch (AccessDeniedException ade) {
        if (log.isDebugEnabled()) {
            log.debug("Access denied");
            ade.printStackTrace();
        }
        throw ade;
    } catch (RuntimeException re) {
        if (log.isDebugEnabled()) {
            log.debug("Access denied by runtime exception");
            re.printStackTrace();
        }
        throw re;
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) PermissionCheckValue(org.alfresco.repo.security.permissions.PermissionCheckValue) AccessDeniedException(net.sf.acegisecurity.AccessDeniedException) PagingLuceneResultSet(org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet) ResultSet(org.alfresco.service.cmr.search.ResultSet) CMISResultSet(org.alfresco.opencmis.search.CMISResultSet) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) Collection(java.util.Collection) PermissionCheckCollection(org.alfresco.repo.security.permissions.PermissionCheckCollection) MethodInvocation(org.aopalliance.intercept.MethodInvocation) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) CMISResultSet(org.alfresco.opencmis.search.CMISResultSet)

Example 93 with ResultSet

use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.

the class VirtualQueryImpl method perform.

@Override
public PagingResults<Reference> perform(ActualEnvironment environment, VirtualQueryConstraint constraint, PagingRequest pagingRequest, Reference parentReference) throws VirtualizationException {
    VirtualQueryConstraint theConstraint = constraint;
    if (pagingRequest != null) {
        theConstraint = new PagingRequestConstraint(theConstraint, pagingRequest);
    }
    SearchParameters searchParameters = theConstraint.apply(environment, this);
    ResultSet result = environment.query(searchParameters);
    if (logger.isDebugEnabled()) {
        logger.debug("Constrained query " + searchParameters + " resulted in " + result.length() + " rows.");
    }
    return asPagingResults(environment, pagingRequest, result, parentReference);
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) ResultSet(org.alfresco.service.cmr.search.ResultSet) EmptyResultSet(org.alfresco.repo.search.EmptyResultSet)

Example 94 with ResultSet

use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.

the class ReadPermissionTest method testNodeOwner.

public void testNodeOwner() {
    SearchParameters sp;
    ResultSet results;
    buildOwnedNodes("1001", 0);
    runAs(AuthenticationUtil.getAdminUserName());
    runAs("1001");
    sp = new SearchParameters();
    sp.addStore(rootNodeRef.getStoreRef());
    sp.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp.setQuery("PATH:\"//*\"");
    sp.setMaxItems(Integer.MAX_VALUE);
    sp.setMaxPermissionChecks(Integer.MAX_VALUE);
    sp.setMaxPermissionCheckTimeMillis(Integer.MAX_VALUE);
    results = serviceRegistry.getSearchService().query(sp);
    int length = results.length();
    results.close();
    // folder + children
    assertEquals(1001, length);
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) ResultSet(org.alfresco.service.cmr.search.ResultSet)

Example 95 with ResultSet

use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.

the class ReadPermissionTest method testNoRead.

public void testNoRead() {
    SearchParameters sp;
    ResultSet results;
    build1000Nodes("1001", PermissionService.WRITE, true);
    runAs("1001");
    sp = new SearchParameters();
    sp.addStore(rootNodeRef.getStoreRef());
    sp.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp.setQuery("TYPE:\"cm:content\"");
    sp.setMaxItems(Integer.MAX_VALUE);
    sp.setMaxPermissionChecks(Integer.MAX_VALUE);
    sp.setMaxPermissionCheckTimeMillis(Integer.MAX_VALUE);
    results = serviceRegistry.getSearchService().query(sp);
    int length = results.length();
    results.close();
    assertEquals(0, length);
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) ResultSet(org.alfresco.service.cmr.search.ResultSet)

Aggregations

ResultSet (org.alfresco.service.cmr.search.ResultSet)112 NodeRef (org.alfresco.service.cmr.repository.NodeRef)57 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)49 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)22 SolrJSONResultSet (org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)20 Test (org.junit.Test)20 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)17 QName (org.alfresco.service.namespace.QName)16 StoreRef (org.alfresco.service.cmr.repository.StoreRef)14 ResultSetRow (org.alfresco.service.cmr.search.ResultSetRow)14 HashSet (java.util.HashSet)13 EmptyResultSet (org.alfresco.repo.search.EmptyResultSet)13 SearchService (org.alfresco.service.cmr.search.SearchService)13 NodeService (org.alfresco.service.cmr.repository.NodeService)12 IOException (java.io.IOException)11 List (java.util.List)11 SearchRequestContext (org.alfresco.rest.api.search.context.SearchRequestContext)11 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)10 PagingLuceneResultSet (org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet)10