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;
}
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());
}
}
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);
}
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());
}
}
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());
}
Aggregations