use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class ReadPermissionTest method testQueryReadPermission.
public void testQueryReadPermission() {
buildNodes();
SearchParameters sp;
ResultSet results;
runAs("1000");
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);
results.setBulkFetch(false);
assertEquals(1000 * COUNT, results.length());
results.close();
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);
results.setBulkFetch(false);
assertEquals(1000 * COUNT, results.length());
results.close();
runAs("100");
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);
results.setBulkFetch(false);
assertEquals(100 * COUNT, results.length());
results.close();
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);
results.setBulkFetch(false);
assertEquals(100 * COUNT, results.length());
results.close();
runAs("10");
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);
results.setBulkFetch(false);
assertEquals(10 * COUNT, results.length());
results.close();
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);
results.setBulkFetch(false);
assertEquals(10 * COUNT, results.length());
results.close();
// test user member of group with read permission can read
runAs("10_1");
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);
results.setBulkFetch(false);
assertEquals(10 * COUNT, results.length());
results.close();
runAs("1");
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);
results.setBulkFetch(false);
assertEquals(COUNT, results.length());
results.close();
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);
results.setBulkFetch(false);
assertEquals(COUNT, results.length());
results.close();
runAs("01");
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);
results.setBulkFetch(false);
assertEquals(c01.count(), results.length());
results.close();
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);
results.setBulkFetch(false);
assertEquals(c01.count(), results.length());
results.close();
runAs("001");
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);
results.setBulkFetch(false);
assertEquals(c001.count(), results.length());
results.close();
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);
results.setBulkFetch(false);
assertEquals(c001.count(), results.length());
results.close();
runAs("0001");
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);
results.setBulkFetch(false);
assertEquals(c0001.count(), results.length());
results.close();
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);
results.setBulkFetch(false);
assertEquals(c0001.count(), results.length());
results.close();
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class ReadPermissionTest method testChangePermissions.
public void testChangePermissions() {
SearchParameters sp;
ResultSet results;
NodeRef[] nodes = build1000Nodes("1001", 4, false);
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(1000, length);
for (int i = 0; i < 4; i++) {
permissionService.deletePermission(nodes[i], "1001", PermissionService.READ);
}
// setPermission(nodes[0], "10", permission, allow)
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);
length = results.length();
results.close();
assertEquals(1000 - 4, length);
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class ReadPermissionTest method testAdminCanRead.
// public void testDynamicAuthority() throws Exception
// {
// SearchParameters sp;
// ResultSet results;
//
// buildNodes("1001", null, 10, false);
//
// 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(10, length);
// }
public void testAdminCanRead() {
runAs("Web1");
buildNodes("1001", "Read", 10, true);
SearchParameters sp;
ResultSet results;
runAs("admin");
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);
results.setBulkFetch(false);
assertEquals(10, results.length());
results.close();
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class ACLEntryAfterInvocationTest method testBasicAllowNullResultSet.
public void testBasicAllowNullResultSet() throws Exception {
runAs("andy");
Object o = new ClassWithMethods();
Method methodResultSet = o.getClass().getMethod("echoResultSet", new Class[] { ResultSet.class });
Method methodCollection = o.getClass().getMethod("echoCollection", new Class[] { Collection.class });
Method methodArray = o.getClass().getMethod("echoArray", new Class[] { Object[].class });
AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_NODE.sys:base.Read")));
proxyFactory.setTargetSource(new SingletonTargetSource(o));
Object proxy = proxyFactory.getProxy();
List<NodeRef> nodeRefList = new ArrayList<NodeRef>();
NodeRef[] nodeRefArray = new NodeRef[0];
Set<NodeRef> nodeRefSet = new HashSet<NodeRef>();
List<ChildAssociationRef> carList = new ArrayList<ChildAssociationRef>();
ChildAssociationRef[] carArray = new ChildAssociationRef[0];
Set<ChildAssociationRef> carSet = new HashSet<ChildAssociationRef>();
ChildAssocRefResultSet rsIn = new ChildAssocRefResultSet(nodeService, nodeRefList, false);
assertEquals(0, rsIn.length());
ResultSet answerResultSet = (ResultSet) methodResultSet.invoke(proxy, new Object[] { rsIn });
assertEquals(0, answerResultSet.length());
Collection answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { nodeRefList });
assertEquals(0, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { nodeRefSet });
assertEquals(0, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { carList });
assertEquals(0, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { carSet });
assertEquals(0, answerCollection.size());
Object[] answerArray = (Object[]) methodArray.invoke(proxy, new Object[] { nodeRefArray });
assertEquals(0, answerArray.length);
answerArray = (Object[]) methodArray.invoke(proxy, new Object[] { carArray });
assertEquals(0, answerArray.length);
assertEquals(0, rsIn.length());
answerResultSet = (ResultSet) methodResultSet.invoke(proxy, new Object[] { null });
assertNull(answerResultSet);
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { null });
assertNull(answerCollection);
answerArray = (Object[]) methodArray.invoke(proxy, new Object[] { null });
assertNull(answerArray);
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class ACLEntryAfterInvocationTest method testResultSetFilterNone2.
public void testResultSetFilterNone2() throws Exception {
runAs(AuthenticationUtil.getAdminUserName());
NodeRef n1 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef();
runAs("andy");
Object o = new ClassWithMethods();
Method methodResultSet = o.getClass().getMethod("echoResultSet", new Class[] { ResultSet.class });
Method methodCollection = o.getClass().getMethod("echoCollection", new Class[] { Collection.class });
Method methodArray = o.getClass().getMethod("echoArray", new Class[] { Object[].class });
AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_PARENT.sys:base.Read")));
proxyFactory.setTargetSource(new SingletonTargetSource(o));
Object proxy = proxyFactory.getProxy();
List<NodeRef> nodeRefList = new ArrayList<NodeRef>();
nodeRefList.add(rootNodeRef);
nodeRefList.add(systemNodeRef);
nodeRefList.add(n1);
nodeRefList.add(n1);
List<Object> mixedRefList = new ArrayList<Object>();
mixedRefList.add(rootNodeRef);
mixedRefList.add(systemNodeRef);
mixedRefList.add(n1);
mixedRefList.add(n1);
mixedRefList.add(rootNodeRef.getStoreRef());
NodeRef[] nodeRefArray = nodeRefList.toArray(new NodeRef[] {});
Set<NodeRef> nodeRefSet = new HashSet<NodeRef>();
nodeRefSet.addAll(nodeRefList);
Set<Object> mixedRefSet = new HashSet<Object>();
mixedRefSet.addAll(mixedRefList);
List<ChildAssociationRef> carList = new ArrayList<ChildAssociationRef>();
carList.add(nodeService.getPrimaryParent(rootNodeRef));
carList.add(nodeService.getPrimaryParent(systemNodeRef));
carList.add(nodeService.getPrimaryParent(n1));
carList.add(nodeService.getPrimaryParent(n1));
ChildAssociationRef[] carArray = carList.toArray(new ChildAssociationRef[] {});
Set<ChildAssociationRef> carSet = new HashSet<ChildAssociationRef>();
carSet.addAll(carList);
ChildAssocRefResultSet rsIn = new ChildAssocRefResultSet(nodeService, nodeRefList, false);
permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
assertEquals(4, rsIn.length());
ResultSet answerResultSet = (ResultSet) methodResultSet.invoke(proxy, new Object[] { rsIn });
assertEquals(4, answerResultSet.length());
Collection answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { nodeRefList });
assertEquals(4, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { mixedRefList });
assertEquals(5, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { nodeRefSet });
assertEquals(3, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { mixedRefSet });
assertEquals(4, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { carList });
assertEquals(4, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { carSet });
assertEquals(3, answerCollection.size());
Object[] answerArray = (Object[]) methodArray.invoke(proxy, new Object[] { nodeRefArray });
assertEquals(4, answerArray.length);
answerArray = (Object[]) methodArray.invoke(proxy, new Object[] { carArray });
assertEquals(4, answerArray.length);
permissionService.setPermission(new SimplePermissionEntry(n1, getPermission(PermissionService.READ), "andy", AccessStatus.DENIED));
assertEquals(4, rsIn.length());
answerResultSet = (ResultSet) methodResultSet.invoke(proxy, new Object[] { rsIn });
assertEquals(4, answerResultSet.length());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { nodeRefList });
assertEquals(4, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { mixedRefList });
assertEquals(5, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { nodeRefSet });
assertEquals(3, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { mixedRefSet });
assertEquals(4, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { carList });
assertEquals(4, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { carSet });
assertEquals(3, answerCollection.size());
answerArray = (Object[]) methodArray.invoke(proxy, new Object[] { nodeRefArray });
assertEquals(4, answerArray.length);
answerArray = (Object[]) methodArray.invoke(proxy, new Object[] { carArray });
assertEquals(4, answerArray.length);
permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.DENIED));
assertEquals(4, rsIn.length());
answerResultSet = (ResultSet) methodResultSet.invoke(proxy, new Object[] { rsIn });
assertEquals(1, answerResultSet.length());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { nodeRefList });
assertEquals(1, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { mixedRefList });
assertEquals(2, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { nodeRefSet });
assertEquals(1, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { mixedRefSet });
assertEquals(2, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { carList });
assertEquals(1, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { carSet });
assertEquals(1, answerCollection.size());
answerArray = (Object[]) methodArray.invoke(proxy, new Object[] { nodeRefArray });
assertEquals(1, answerArray.length);
answerArray = (Object[]) methodArray.invoke(proxy, new Object[] { carArray });
assertEquals(1, answerArray.length);
}
Aggregations