use of org.alfresco.repo.security.permissions.impl.SimplePermissionEntry in project alfresco-repository by Alfresco.
the class AbstractPermissionsDaoComponentImpl method createSimpleNodePermissionEntry.
private SimpleNodePermissionEntry createSimpleNodePermissionEntry(StoreRef storeRef) {
Acl acl = getACLDAO(storeRef).getAccessControlList(storeRef);
if (acl == null) {
// there isn't an access control list for the node - spoof a null one
SimpleNodePermissionEntry snpe = new SimpleNodePermissionEntry(null, true, Collections.<SimplePermissionEntry>emptyList());
return snpe;
} else {
AccessControlList info = aclDaoComponent.getAccessControlList(acl.getId());
ArrayList<SimplePermissionEntry> spes = new ArrayList<SimplePermissionEntry>(info.getEntries().size());
for (AccessControlEntry entry : info.getEntries()) {
SimplePermissionEntry spe = new SimplePermissionEntry(null, entry.getPermission(), entry.getAuthority(), entry.getAccessStatus(), entry.getPosition());
spes.add(spe);
}
SimpleNodePermissionEntry snpe = new SimpleNodePermissionEntry(null, acl.getInherits(), spes);
return snpe;
}
}
use of org.alfresco.repo.security.permissions.impl.SimplePermissionEntry in project alfresco-repository by Alfresco.
the class AbstractPermissionsDaoComponentImpl method createSimpleNodePermissionEntry.
// Utility methods to create simple detached objects for the outside world
// We do not pass out the hibernate objects
private SimpleNodePermissionEntry createSimpleNodePermissionEntry(NodeRef nodeRef) {
Acl acl = getACLDAO(nodeRef).getAccessControlList(nodeRef);
if (acl == null) {
// there isn't an access control list for the node - spoof a null one
SimpleNodePermissionEntry snpe = new SimpleNodePermissionEntry(nodeRef, true, Collections.<SimplePermissionEntry>emptyList());
return snpe;
} else {
AccessControlList info = aclDaoComponent.getAccessControlList(acl.getId());
SimpleNodePermissionEntry cached = info.getCachedSimpleNodePermissionEntry();
if (cached != null) {
return cached;
}
ArrayList<SimplePermissionEntry> spes = new ArrayList<SimplePermissionEntry>(info.getEntries().size());
for (AccessControlEntry entry : info.getEntries()) {
SimplePermissionEntry spe = new SimplePermissionEntry(nodeRef, entry.getPermission(), entry.getAuthority(), entry.getAccessStatus(), entry.getPosition());
spes.add(spe);
}
SimpleNodePermissionEntry snpe = new SimpleNodePermissionEntry(nodeRef, acl.getInherits(), spes);
info.setCachedSimpleNodePermissionEntry(snpe);
return snpe;
}
}
use of org.alfresco.repo.security.permissions.impl.SimplePermissionEntry in project alfresco-remote-api by Alfresco.
the class CommentsApiTest method testCommentPermissions.
/**
* MNT-9771
* @throws Exception
*/
public void testCommentPermissions() throws Exception {
authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
NodeRef contentForUserContributor = fileFolderService.create(companyHomeNodeRef, "CommentyContributor" + System.currentTimeMillis(), ContentModel.TYPE_CONTENT).getNodeRef();
permissionService.setPermission(new SimplePermissionEntry(contentForUserContributor, getPermission(PermissionService.CONTRIBUTOR), USER_TEST, AccessStatus.ALLOWED));
NodeRef contentForUserConsumer = fileFolderService.create(companyHomeNodeRef, "CommentyConsumer" + System.currentTimeMillis(), ContentModel.TYPE_CONTENT).getNodeRef();
permissionService.setPermission(new SimplePermissionEntry(contentForUserConsumer, getPermission(PermissionService.CONSUMER), USER_TEST, AccessStatus.ALLOWED));
// Contributor should be able to add comments
addComment(contentForUserContributor, USER_TEST, 200);
// Hack. Internally, the addComment starts and rolls back the next txn.
txn.commit();
// Consumer shouldn't be able to add comments see MNT-9883
addComment(contentForUserConsumer, USER_TEST, 500);
txn = transactionService.getUserTransaction();
txn.begin();
nodeService.deleteNode(contentForUserContributor);
nodeService.deleteNode(contentForUserConsumer);
txn.commit();
}
use of org.alfresco.repo.security.permissions.impl.SimplePermissionEntry in project alfresco-repository by Alfresco.
the class ACLEntryVoterTest method testBasicAllowNode.
public void testBasicAllowNode() throws Exception {
runAs("andy");
permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
Object o = new ClassWithMethods();
Method method = o.getClass().getMethod("testOneNodeRef", new Class[] { NodeRef.class });
AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_NODE.0.sys:base.Read")));
proxyFactory.setTargetSource(new SingletonTargetSource(o));
Object proxy = proxyFactory.getProxy();
method.invoke(proxy, new Object[] { rootNodeRef });
}
use of org.alfresco.repo.security.permissions.impl.SimplePermissionEntry in project alfresco-repository by Alfresco.
the class ACLEntryAfterInvocationTest method testWhenNodesCheckedExceedsTargetResultCount.
public void testWhenNodesCheckedExceedsTargetResultCount() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException {
// ALF-11709: If 'count' nodes have been checked and that number exceeds targetResultCount
// this should not stop further checks from happening, when the number of successful
// security checks ('keepValues') is less then targetResultCount. If this does not hold true,
// then in the case where the first targetResultCount checks are unsuccessful then the
// method will not return any values that should be present. For example, if user_9999 looks
// at User Homes, and there are folders user_0001 through to user_9998 being checked before user_9999's
// folder - then if targetResultCount is only 1000, user_9999 will not see any folders in User Homes
// however, they should see one folder - their own.
runAs(AuthenticationUtil.getAdminUserName());
NodeRef n1 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef();
NodeRef n2 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef();
NodeRef n3 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef();
NodeRef n4 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef();
// Set nodes n1..n3 to be unviewable by "andy" (using inherited permissions)
permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.ALL_PERMISSIONS), "andy", AccessStatus.DENIED));
// The last node n4 can be seen (override the inherited permissions)
permissionService.setPermission(new SimplePermissionEntry(n4, getPermission(PermissionService.ALL_PERMISSIONS), "andy", AccessStatus.ALLOWED));
runAs("andy");
Object o = new ClassWithMethods();
Method methodCollection = o.getClass().getMethod("echoCollection", new Class[] { Collection.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>(Arrays.asList(n1, n2, n3, n4));
// targetResultCount = 3. The first three nodes are not visible by the user, so the logic
// must not count those towards the targetResultCount cutoff.
Collection<?> answerCollection = (Collection<?>) methodCollection.invoke(proxy, new Object[] { PermissionCheckCollectionMixin.create(nodeRefList, 3, 0, 0) });
assertEquals(1, answerCollection.size());
assertEquals(n4, answerCollection.iterator().next());
}
Aggregations