Search in sources :

Example 46 with AccessPermission

use of org.alfresco.service.cmr.security.AccessPermission in project alfresco-repository by Alfresco.

the class SiteServiceImplTest method containsConsumerPermission.

private boolean containsConsumerPermission(final String groupName, SiteInfo unconfiguredSite) {
    boolean result = false;
    Set<AccessPermission> perms = permissionService.getAllSetPermissions(unconfiguredSite.getNodeRef());
    for (AccessPermission p : perms) {
        if (p.getAuthority().equals(groupName) && p.getPermission().equals(SiteModel.SITE_CONSUMER)) {
            result = true;
        }
    }
    return result;
}
Also used : AccessPermission(org.alfresco.service.cmr.security.AccessPermission)

Example 47 with AccessPermission

use of org.alfresco.service.cmr.security.AccessPermission in project alfresco-repository by Alfresco.

the class SiteServiceImplTest method validatePermissionsOnRelocatedNode.

private void validatePermissionsOnRelocatedNode(SiteInfo fromSite, SiteInfo toSite, NodeRef relocatedNode, Map<String, String> expectedPermissions) {
    Set<AccessPermission> permissions = permissionService.getAllSetPermissions(relocatedNode);
    // None of the 'from' site permissions should be there.
    for (String sitePermission : SiteModel.STANDARD_PERMISSIONS) {
        String siteRoleGroup = siteServiceImpl.getSiteRoleGroup(fromSite.getShortName(), sitePermission, true);
        AccessPermission ap = getPermission(permissions, siteRoleGroup);
        assertNull("Permission " + siteRoleGroup + " was unexpectedly present", ap);
    }
    // All of the 'to' site permissions should be there.
    for (String authority : expectedPermissions.keySet()) {
        AccessPermission ap = getPermission(permissions, authority);
        assertNotNull("Permission " + authority + " missing", ap);
        assertEquals(authority, ap.getAuthority());
        assertEquals("Wrong permission for " + authority, expectedPermissions.get(authority), ap.getPermission());
        assertTrue(ap.isInherited());
    }
}
Also used : AccessPermission(org.alfresco.service.cmr.security.AccessPermission) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString)

Example 48 with AccessPermission

use of org.alfresco.service.cmr.security.AccessPermission in project alfresco-repository by Alfresco.

the class MultiTDemoTest method checkTestAuthoritiesPresence.

private void checkTestAuthoritiesPresence(final String[] uniqueGroupNames, final String userName, final boolean shouldPresent) {
    String tenantDomain = tenantService.getUserDomain(userName);
    // Check that created permissions are not visible to tenant 2
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Object>() {

        public Object doWork() throws Exception {
            NodeRef personNodeRef = personService.getPerson(userName);
            NodeRef homeSpaceRef = (NodeRef) nodeService.getProperty(personNodeRef, ContentModel.PROP_HOMEFOLDER);
            Set<AccessPermission> perms = permissionService.getAllSetPermissions(homeSpaceRef);
            Set<String> auths = authorityService.getAllAuthorities(AuthorityType.GROUP);
            for (int i = 0; i < uniqueGroupNames.length; i++) {
                AccessPermission toCheck = new AccessPermissionImpl("Consumer", AccessStatus.ALLOWED, "GROUP_" + uniqueGroupNames[i], 0);
                if (shouldPresent) {
                    assertTrue(auths.contains("GROUP_" + uniqueGroupNames[i]));
                    assertTrue(perms.contains(toCheck));
                } else {
                    assertTrue(!auths.contains("GROUP_" + uniqueGroupNames[i]));
                    assertTrue(!perms.contains(toCheck));
                }
            }
            return null;
        }
    }, userName, tenantDomain);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResultSet(org.alfresco.service.cmr.search.ResultSet) Set(java.util.Set) HashSet(java.util.HashSet) AccessPermission(org.alfresco.service.cmr.security.AccessPermission) AccessPermissionImpl(org.alfresco.repo.security.permissions.impl.AccessPermissionImpl) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 49 with AccessPermission

use of org.alfresco.service.cmr.security.AccessPermission in project alfresco-repository by Alfresco.

the class PermissionServiceTest method testPositionInformation.

/**
 * This will break when merged forward
 */
public void testPositionInformation() {
    if (aclDaoComponent.getDefaultProperties().getAclType() == ACLType.DEFINING) {
        runAs(AuthenticationUtil.getAdminUserName());
        NodeRef one = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef();
        NodeRef two = nodeService.createNode(one, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}two"), ContentModel.TYPE_FOLDER).getChildRef();
        NodeRef three = nodeService.createNode(two, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}three"), ContentModel.TYPE_FOLDER).getChildRef();
        NodeRef four = nodeService.createNode(three, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}three"), ContentModel.TYPE_FOLDER).getChildRef();
        permissionService.setPermission(one, "andy", PermissionService.ALL_PERMISSIONS, true);
        permissionService.setPermission(two, "bob", PermissionService.ALL_PERMISSIONS, true);
        permissionService.setPermission(three, "carol", PermissionService.ALL_PERMISSIONS, true);
        Set<AccessPermission> set = permissionService.getAllSetPermissions(one);
        assertEquals(1, set.size());
        for (AccessPermission ap : set) {
            if (ap.getAuthority().equals("andy")) {
                assertFalse(ap.isInherited());
                assertEquals(0, ap.getPosition());
            }
        }
        set = permissionService.getAllSetPermissions(two);
        assertEquals(2, set.size());
        for (AccessPermission ap : set) {
            if (ap.getAuthority().equals("andy")) {
                assertTrue(ap.isInherited());
                assertEquals(2, ap.getPosition());
            }
            if (ap.getAuthority().equals("bob")) {
                assertFalse(ap.isInherited());
                assertEquals(0, ap.getPosition());
            }
        }
        set = permissionService.getAllSetPermissions(three);
        assertEquals(3, set.size());
        for (AccessPermission ap : set) {
            if (ap.getAuthority().equals("andy")) {
                assertTrue(ap.isInherited());
                assertEquals(4, ap.getPosition());
            }
            if (ap.getAuthority().equals("bob")) {
                assertTrue(ap.isInherited());
                assertEquals(2, ap.getPosition());
            }
            if (ap.getAuthority().equals("carol")) {
                assertFalse(ap.isInherited());
                assertEquals(0, ap.getPosition());
            }
        }
        set = permissionService.getAllSetPermissions(four);
        assertEquals(3, set.size());
        for (AccessPermission ap : set) {
            if (ap.getAuthority().equals("andy")) {
                assertTrue(ap.isInherited());
                assertEquals(5, ap.getPosition());
            }
            if (ap.getAuthority().equals("bob")) {
                assertTrue(ap.isInherited());
                assertEquals(3, ap.getPosition());
            }
            if (ap.getAuthority().equals("carol")) {
                assertTrue(ap.isInherited());
                assertEquals(1, ap.getPosition());
            }
        }
    } else {
        runAs(AuthenticationUtil.getAdminUserName());
        NodeRef one = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef();
        NodeRef two = nodeService.createNode(one, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}two"), ContentModel.TYPE_FOLDER).getChildRef();
        NodeRef three = nodeService.createNode(two, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}three"), ContentModel.TYPE_FOLDER).getChildRef();
        NodeRef four = nodeService.createNode(three, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}three"), ContentModel.TYPE_FOLDER).getChildRef();
        permissionService.setPermission(one, "andy", PermissionService.ALL_PERMISSIONS, true);
        permissionService.setPermission(two, "bob", PermissionService.ALL_PERMISSIONS, true);
        permissionService.setPermission(three, "carol", PermissionService.ALL_PERMISSIONS, true);
        Set<AccessPermission> set = permissionService.getAllSetPermissions(one);
        assertEquals(1, set.size());
        for (AccessPermission ap : set) {
            if (ap.getAuthority().equals("andy")) {
                assertFalse(ap.isInherited());
                assertEquals(0, ap.getPosition());
            }
        }
        set = permissionService.getAllSetPermissions(two);
        assertEquals(1, set.size());
        for (AccessPermission ap : set) {
            if (ap.getAuthority().equals("bob")) {
                assertFalse(ap.isInherited());
                assertEquals(0, ap.getPosition());
            }
        }
        set = permissionService.getAllSetPermissions(three);
        assertEquals(1, set.size());
        for (AccessPermission ap : set) {
            if (ap.getAuthority().equals("carol")) {
                assertFalse(ap.isInherited());
                assertEquals(0, ap.getPosition());
            }
        }
        set = permissionService.getAllSetPermissions(four);
        assertEquals(0, set.size());
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AccessPermission(org.alfresco.service.cmr.security.AccessPermission)

Example 50 with AccessPermission

use of org.alfresco.service.cmr.security.AccessPermission in project alfresco-repository by Alfresco.

the class PermissionServiceTest method testGetAllSetPermissions.

public void testGetAllSetPermissions() {
    runAs("andy");
    permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.DELETE), "andy", AccessStatus.ALLOWED));
    permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.DELETE), "GROUP_GREEN", AccessStatus.ALLOWED));
    permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
    permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "GROUP_RED", AccessStatus.ALLOWED));
    permissionService.setPermission(new SimplePermissionEntry(systemNodeRef, getPermission(PermissionService.DELETE), "andy", AccessStatus.DENIED));
    permissionService.setPermission(new SimplePermissionEntry(systemNodeRef, getPermission(PermissionService.DELETE), "GROUP_GREEN", AccessStatus.DENIED));
    NodeRef current = systemNodeRef;
    Set<AccessPermission> setPermissions = new HashSet<AccessPermission>();
    while (current != null) {
        Set<AccessPermission> morePermissions = permissionService.getAllSetPermissions(current);
        for (AccessPermission toTest : morePermissions) {
            if (toTest.getAuthorityType() == AuthorityType.GROUP) {
                boolean add = true;
                for (AccessPermission existing : setPermissions) {
                    if (add && existing.getAuthority().equals(toTest.getAuthority()) && existing.getPermission().equals(toTest.getPermission())) {
                        add = false;
                    }
                }
                if (add) {
                    setPermissions.add(toTest);
                }
            }
        }
        if (permissionService.getInheritParentPermissions(current)) {
            current = nodeService.getPrimaryParent(current).getParentRef();
        } else {
            current = null;
        }
    }
    assertEquals(2, setPermissions.size());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AccessPermission(org.alfresco.service.cmr.security.AccessPermission) HashSet(java.util.HashSet)

Aggregations

AccessPermission (org.alfresco.service.cmr.security.AccessPermission)52 NodeRef (org.alfresco.service.cmr.repository.NodeRef)21 ArrayList (java.util.ArrayList)15 HashSet (java.util.HashSet)14 HashMap (java.util.HashMap)13 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)7 Test (org.junit.Test)7 Serializable (java.io.Serializable)5 List (java.util.List)5 Map (java.util.Map)5 Set (java.util.Set)5 AccessPermissionImpl (org.alfresco.repo.security.permissions.impl.AccessPermissionImpl)5 AccessStatus (org.alfresco.service.cmr.security.AccessStatus)5 QName (org.alfresco.service.namespace.QName)5 LinkedHashSet (java.util.LinkedHashSet)4 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)4 FacesContext (javax.faces.context.FacesContext)3 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)3 FilterPropString (org.alfresco.repo.node.getchildren.FilterPropString)3 PermissionReference (org.alfresco.repo.security.permissions.PermissionReference)3