mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merge pull request #1112 from Alfresco/feature-2.6/RM-7145_SearchQueryHasMoreItems
RM-7145 Fix for hasMoreItems
This commit is contained in:
@@ -156,6 +156,7 @@
|
|||||||
<property name="maxPermissionChecks">
|
<property name="maxPermissionChecks">
|
||||||
<value>${system.acl.maxPermissionChecks}</value>
|
<value>${system.acl.maxPermissionChecks}</value>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="authenticationUtil" ref="rm.authenticationUtil" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- Link up after method call security -->
|
<!-- Link up after method call security -->
|
||||||
|
@@ -39,10 +39,10 @@ import java.util.StringTokenizer;
|
|||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
|
||||||
import org.alfresco.repo.search.SimpleResultSetMetaData;
|
import org.alfresco.repo.search.SimpleResultSetMetaData;
|
||||||
import org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet;
|
import org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet;
|
||||||
import org.alfresco.repo.search.impl.querymodel.QueryEngineResults;
|
import org.alfresco.repo.search.impl.querymodel.QueryEngineResults;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
|
||||||
import org.alfresco.repo.security.permissions.PermissionCheckCollection;
|
import org.alfresco.repo.security.permissions.PermissionCheckCollection;
|
||||||
import org.alfresco.repo.security.permissions.PermissionCheckValue;
|
import org.alfresco.repo.security.permissions.PermissionCheckValue;
|
||||||
import org.alfresco.repo.security.permissions.PermissionCheckedCollection.PermissionCheckedCollectionMixin;
|
import org.alfresco.repo.security.permissions.PermissionCheckedCollection.PermissionCheckedCollectionMixin;
|
||||||
@@ -80,8 +80,8 @@ public class RMAfterInvocationProvider extends RMSecurityCommon
|
|||||||
|
|
||||||
private static final String AFTER_RM = "AFTER_RM";
|
private static final String AFTER_RM = "AFTER_RM";
|
||||||
|
|
||||||
|
private AuthenticationUtil authenticationUtil;
|
||||||
private int maxPermissionChecks;
|
private int maxPermissionChecks;
|
||||||
|
|
||||||
private long maxPermissionCheckTimeMillis;
|
private long maxPermissionCheckTimeMillis;
|
||||||
|
|
||||||
public boolean supports(ConfigAttribute configAttribute)
|
public boolean supports(ConfigAttribute configAttribute)
|
||||||
@@ -130,6 +130,16 @@ public class RMAfterInvocationProvider extends RMSecurityCommon
|
|||||||
this.maxPermissionCheckTimeMillis = maxPermissionCheckTimeMillis;
|
this.maxPermissionCheckTimeMillis = maxPermissionCheckTimeMillis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the authentication util
|
||||||
|
*
|
||||||
|
* @param authenticationUtil The authentication util to set
|
||||||
|
*/
|
||||||
|
public void setAuthenticationUtil(AuthenticationUtil authenticationUtil)
|
||||||
|
{
|
||||||
|
this.authenticationUtil = authenticationUtil;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public Object decide(Authentication authentication, Object object, ConfigAttributeDefinition config, Object returnedObject)
|
public Object decide(Authentication authentication, Object object, ConfigAttributeDefinition config, Object returnedObject)
|
||||||
{
|
{
|
||||||
@@ -147,7 +157,7 @@ public class RMAfterInvocationProvider extends RMSecurityCommon
|
|||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (AuthenticationUtil.isRunAsUserTheSystemUser())
|
if (authenticationUtil.isRunAsUserTheSystemUser())
|
||||||
{
|
{
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
@@ -563,6 +573,13 @@ public class RMAfterInvocationProvider extends RMSecurityCommon
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (maxSize != null)
|
||||||
|
{
|
||||||
|
LimitBy limitBy = returnedObject.length() > maxSize ? LimitBy.FINAL_SIZE : LimitBy.UNLIMITED;
|
||||||
|
filteringResultSet.setResultSetMetaData(new SimpleResultSetMetaData(limitBy,
|
||||||
|
PermissionEvaluationMode.EAGER, returnedObject.getResultSetMetaData().getSearchParameters()));
|
||||||
|
}
|
||||||
|
|
||||||
filteringResultSet.setNumberFound(returnedObject.getNumberFound());
|
filteringResultSet.setNumberFound(returnedObject.getNumberFound());
|
||||||
|
|
||||||
return filteringResultSet;
|
return filteringResultSet;
|
||||||
|
@@ -0,0 +1,178 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Records Management Module
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* -
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
* -
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* -
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
* -
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.module.org_alfresco_module_rm.capability;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.mockito.MockitoAnnotations.initMocks;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.sf.acegisecurity.Authentication;
|
||||||
|
import net.sf.acegisecurity.ConfigAttribute;
|
||||||
|
import net.sf.acegisecurity.ConfigAttributeDefinition;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
|
||||||
|
import org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet;
|
||||||
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
|
import org.alfresco.service.cmr.search.LimitBy;
|
||||||
|
import org.alfresco.service.cmr.search.ResultSet;
|
||||||
|
import org.alfresco.service.cmr.search.ResultSetMetaData;
|
||||||
|
import org.alfresco.service.cmr.search.SearchParameters;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
|
||||||
|
/** Unit tests for {@link RMAfterInvocationProvider}. */
|
||||||
|
public class RMAfterInvocationProviderUnitTest
|
||||||
|
{
|
||||||
|
private static final NodeRef NODE_A = new NodeRef("test://node/a");
|
||||||
|
|
||||||
|
/** The class under test. */
|
||||||
|
@InjectMocks
|
||||||
|
private RMAfterInvocationProvider rmAfterInvocationProvider;
|
||||||
|
@Mock
|
||||||
|
private Authentication authentication;
|
||||||
|
@Mock
|
||||||
|
Object object;
|
||||||
|
@Mock
|
||||||
|
ConfigAttributeDefinition config;
|
||||||
|
@Mock
|
||||||
|
AuthenticationUtil authenticationUtil;
|
||||||
|
@Mock
|
||||||
|
NodeService nodeService;
|
||||||
|
@Mock
|
||||||
|
ChildAssociationRef childAssocRefA;
|
||||||
|
|
||||||
|
/** Set up the mocks and common test data. */
|
||||||
|
@Before
|
||||||
|
public void setUp()
|
||||||
|
{
|
||||||
|
initMocks(this);
|
||||||
|
|
||||||
|
// Set up the nodes and associations.
|
||||||
|
when(nodeService.exists(NODE_A)).thenReturn(true);
|
||||||
|
when(childAssocRefA.getParentRef()).thenReturn(NODE_A);
|
||||||
|
|
||||||
|
// Create the config object for use by the tests.
|
||||||
|
ConfigAttribute configAttribute = mock(ConfigAttribute.class);
|
||||||
|
when(configAttribute.getAttribute()).thenReturn("AFTER_RM.test");
|
||||||
|
List<ConfigAttribute> configAttributes = asList(configAttribute);
|
||||||
|
when(config.getConfigAttributes()).thenReturn(configAttributes.iterator());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Check that when all the results fit into a page then we get a response of "UNLIMITED". */
|
||||||
|
@Test
|
||||||
|
public void testDecide_resultSet_unlimited()
|
||||||
|
{
|
||||||
|
// The returned object is a search result set.
|
||||||
|
ResultSet returnedObject = mock(ResultSet.class);
|
||||||
|
ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
|
||||||
|
when(returnedObject.getResultSetMetaData()).thenReturn(resultSetMetaData);
|
||||||
|
|
||||||
|
// Simulate a single result, and the user has access to it.
|
||||||
|
when(returnedObject.length()).thenReturn(1);
|
||||||
|
when(returnedObject.getNumberFound()).thenReturn(1L);
|
||||||
|
when(returnedObject.getNodeRef(0)).thenReturn(NODE_A);
|
||||||
|
when(returnedObject.getChildAssocRef(0)).thenReturn(childAssocRefA);
|
||||||
|
|
||||||
|
// Set the page size to 1 and skip count to 0.
|
||||||
|
SearchParameters searchParameters = mock(SearchParameters.class);
|
||||||
|
when(searchParameters.getMaxItems()).thenReturn(1);
|
||||||
|
when(searchParameters.getSkipCount()).thenReturn(0);
|
||||||
|
when(resultSetMetaData.getSearchParameters()).thenReturn(searchParameters);
|
||||||
|
|
||||||
|
// Call the method under test.
|
||||||
|
FilteringResultSet filteringResultSet = (FilteringResultSet) rmAfterInvocationProvider.decide(authentication, object, config, returnedObject);
|
||||||
|
|
||||||
|
assertEquals("Expected total of one result.", 1, filteringResultSet.getNumberFound());
|
||||||
|
assertEquals("Expected one result returned.", 1, filteringResultSet.length());
|
||||||
|
assertEquals("Expected that results were not limited by the page size.", LimitBy.UNLIMITED, filteringResultSet.getResultSetMetaData().getLimitedBy());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Check that results can skipped due to the skip count. */
|
||||||
|
@Test
|
||||||
|
public void testDecide_resultSet_skipped()
|
||||||
|
{
|
||||||
|
// The returned object is a search result set.
|
||||||
|
ResultSet returnedObject = mock(ResultSet.class);
|
||||||
|
ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
|
||||||
|
when(returnedObject.getResultSetMetaData()).thenReturn(resultSetMetaData);
|
||||||
|
|
||||||
|
// Simulate a single result that was skipped due to the skip count.
|
||||||
|
when(returnedObject.length()).thenReturn(0);
|
||||||
|
when(returnedObject.getNumberFound()).thenReturn(1L);
|
||||||
|
|
||||||
|
// Set the page size to 1 and skip count to 1 (so the result is skipped).
|
||||||
|
SearchParameters searchParameters = mock(SearchParameters.class);
|
||||||
|
when(searchParameters.getMaxItems()).thenReturn(1);
|
||||||
|
when(searchParameters.getSkipCount()).thenReturn(1);
|
||||||
|
when(resultSetMetaData.getSearchParameters()).thenReturn(searchParameters);
|
||||||
|
|
||||||
|
// Call the method under test.
|
||||||
|
FilteringResultSet filteringResultSet = (FilteringResultSet) rmAfterInvocationProvider.decide(authentication, object, config, returnedObject);
|
||||||
|
|
||||||
|
assertEquals("Expected total of one result.", 1, filteringResultSet.getNumberFound());
|
||||||
|
assertEquals("Expected no results returned.", 0, filteringResultSet.length());
|
||||||
|
assertEquals("Expected that results were not limited by the page size.", LimitBy.UNLIMITED, filteringResultSet.getResultSetMetaData().getLimitedBy());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Check that results can be limited by the page size. */
|
||||||
|
@Test
|
||||||
|
public void testDecide_resultSet_pageSize()
|
||||||
|
{
|
||||||
|
// The returned object is a search result set.
|
||||||
|
ResultSet returnedObject = mock(ResultSet.class);
|
||||||
|
ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
|
||||||
|
when(returnedObject.getResultSetMetaData()).thenReturn(resultSetMetaData);
|
||||||
|
|
||||||
|
// Simulate a single result, and the user has access to it.
|
||||||
|
when(returnedObject.length()).thenReturn(1);
|
||||||
|
when(returnedObject.getNumberFound()).thenReturn(1L);
|
||||||
|
when(returnedObject.getNodeRef(0)).thenReturn(NODE_A);
|
||||||
|
when(returnedObject.getChildAssocRef(0)).thenReturn(childAssocRefA);
|
||||||
|
|
||||||
|
// Set the page size to 0 and skip count to 0 (so the result is not in page).
|
||||||
|
SearchParameters searchParameters = mock(SearchParameters.class);
|
||||||
|
when(searchParameters.getMaxItems()).thenReturn(0);
|
||||||
|
when(searchParameters.getSkipCount()).thenReturn(0);
|
||||||
|
when(resultSetMetaData.getSearchParameters()).thenReturn(searchParameters);
|
||||||
|
|
||||||
|
// Call the method under test.
|
||||||
|
FilteringResultSet filteringResultSet = (FilteringResultSet) rmAfterInvocationProvider.decide(authentication, object, config, returnedObject);
|
||||||
|
|
||||||
|
assertEquals("Expected total of one result.", 1, filteringResultSet.getNumberFound());
|
||||||
|
assertEquals("Expected no results returned.", 0, filteringResultSet.length());
|
||||||
|
assertEquals("Expected that results were limited by page size.", LimitBy.FINAL_SIZE, filteringResultSet.getResultSetMetaData().getLimitedBy());
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user