use of org.alfresco.repo.security.permissions.impl.SimplePermissionEntry in project alfresco-repository by Alfresco.
the class ACLEntryAfterInvocationTest method testBasicAllowChildAssociationRef1.
public void testBasicAllowChildAssociationRef1() throws Exception {
runAs("andy");
Object o = new ClassWithMethods();
Method method = o.getClass().getMethod("echoChildAssocRef", new Class[] { ChildAssociationRef.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();
permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
Object answer = method.invoke(proxy, new Object[] { nodeService.getPrimaryParent(rootNodeRef) });
assertEquals(answer, nodeService.getPrimaryParent(rootNodeRef));
answer = method.invoke(proxy, new Object[] { nodeService.getPrimaryParent(systemNodeRef) });
assertEquals(answer, nodeService.getPrimaryParent(systemNodeRef));
}
use of org.alfresco.repo.security.permissions.impl.SimplePermissionEntry in project alfresco-repository by Alfresco.
the class ACLEntryAfterInvocationTest method testBasicAllowNodeParent.
public void testBasicAllowNodeParent() throws Exception {
runAs("andy");
Object o = new ClassWithMethods();
Method method = o.getClass().getMethod("echoNodeRef", new Class[] { NodeRef.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();
Object answer = method.invoke(proxy, new Object[] { rootNodeRef });
assertEquals(answer, rootNodeRef);
try {
answer = method.invoke(proxy, new Object[] { systemNodeRef });
assertNotNull(answer);
} catch (InvocationTargetException e) {
}
permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
answer = method.invoke(proxy, new Object[] { systemNodeRef });
assertEquals(answer, systemNodeRef);
}
use of org.alfresco.repo.security.permissions.impl.SimplePermissionEntry 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);
}
use of org.alfresco.repo.security.permissions.impl.SimplePermissionEntry in project alfresco-repository by Alfresco.
the class ACLEntryAfterInvocationTest method testBasicAllowStore.
public void testBasicAllowStore() throws Exception {
runAs("andy");
Object o = new ClassWithMethods();
Method method = o.getClass().getMethod("echoStoreRef", new Class[] { StoreRef.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();
permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
Object answer = method.invoke(proxy, new Object[] { rootNodeRef.getStoreRef() });
assertEquals(answer, rootNodeRef.getStoreRef());
}
use of org.alfresco.repo.security.permissions.impl.SimplePermissionEntry in project alfresco-repository by Alfresco.
the class ACLEntryAfterInvocationTest method testResultSetFilterNone1.
public void testResultSetFilterNone1() 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_NODE.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);
// Check cut-offs
answerCollection = (Collection<?>) methodCollection.invoke(proxy, new Object[] { PermissionCheckCollectionMixin.create(new ArrayList<NodeRef>(nodeRefList), 1, 0, 0) });
assertEquals(1, answerCollection.size());
answerCollection = (Collection<?>) methodCollection.invoke(proxy, new Object[] { PermissionCheckCollectionMixin.create(new ArrayList<NodeRef>(nodeRefList), 5, 0, 2) });
assertEquals(2, answerCollection.size());
answerCollection = (Collection<?>) methodCollection.invoke(proxy, new Object[] { PermissionCheckCollectionMixin.create(new ArrayList<NodeRef>(nodeRefList), 5, 1, 0) });
// Only 1ms to do the check
assertTrue("Too many results: " + answerCollection.size(), answerCollection.size() < 5);
permissionService.setPermission(new SimplePermissionEntry(n1, getPermission(PermissionService.READ), "andy", AccessStatus.DENIED));
assertEquals(4, rsIn.length());
answerResultSet = (ResultSet) methodResultSet.invoke(proxy, new Object[] { rsIn });
assertEquals(2, answerResultSet.length());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { nodeRefList });
assertEquals(2, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { mixedRefList });
assertEquals(3, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { nodeRefSet });
assertEquals(2, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { mixedRefSet });
assertEquals(3, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { carList });
assertEquals(2, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { carSet });
assertEquals(2, answerCollection.size());
answerArray = (Object[]) methodArray.invoke(proxy, new Object[] { nodeRefArray });
assertEquals(2, answerArray.length);
answerArray = (Object[]) methodArray.invoke(proxy, new Object[] { carArray });
assertEquals(2, 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(0, answerResultSet.length());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { nodeRefList });
assertEquals(0, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { mixedRefList });
assertEquals(0, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { nodeRefSet });
assertEquals(0, answerCollection.size());
answerCollection = (Collection) methodCollection.invoke(proxy, new Object[] { mixedRefSet });
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());
answerArray = (Object[]) methodArray.invoke(proxy, new Object[] { nodeRefArray });
assertEquals(0, answerArray.length);
answerArray = (Object[]) methodArray.invoke(proxy, new Object[] { carArray });
assertEquals(0, answerArray.length);
}
Aggregations