Search in sources :

Example 1 with SimplePermissionEntry

use of org.alfresco.repo.security.permissions.impl.SimplePermissionEntry in project alfresco-repository by Alfresco.

the class ExtendedPermissionServiceTest method testDeletePermissions.

public void testDeletePermissions() {
    authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
    personService.getPerson("andy");
    authenticationComponent.clearCurrentSecurityContext();
    runAs("andy");
    assertFalse(permissionService.hasPermission(rootNodeRef, getPermission(PermissionService.READ)) == AccessStatus.ALLOWED);
    permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "GROUP_test", AccessStatus.ALLOWED));
    assertFalse(permissionService.hasPermission(rootNodeRef, getPermission(PermissionService.READ)) == AccessStatus.ALLOWED);
    runAs("admin");
    authorityService.createAuthority(AuthorityType.GROUP, "test");
    authorityService.addAuthority("GROUP_test", "andy");
    runAs("andy");
    assertTrue(permissionService.hasPermission(rootNodeRef, getPermission(PermissionService.READ)) == AccessStatus.ALLOWED);
    permissionService.deletePermissions("GROUP_test");
    assertFalse(permissionService.hasPermission(rootNodeRef, getPermission(PermissionService.READ)) == AccessStatus.ALLOWED);
    // At the store level
    permissionService.clearPermission(testStoreRef, "GROUP_test");
    permissionService.deletePermission(testStoreRef, "GROUP_test", PermissionService.READ);
}
Also used : SimplePermissionEntry(org.alfresco.repo.security.permissions.impl.SimplePermissionEntry)

Example 2 with SimplePermissionEntry

use of org.alfresco.repo.security.permissions.impl.SimplePermissionEntry in project alfresco-repository by Alfresco.

the class ACLEntryAfterInvocationTest method testBasicDenyInvalidNodeRef.

public void testBasicDenyInvalidNodeRef() 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_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 });
    assertEquals("Value passed out must be valid", rootNodeRef, answer);
    NodeRef invalidNodeRef = new NodeRef("workspace://SpacesStore/noodle");
    answer = method.invoke(proxy, new Object[] { invalidNodeRef });
    method.invoke(proxy, new Object[] { invalidNodeRef });
    assertEquals("Value passed out must be equal", invalidNodeRef, answer);
}
Also used : SingletonTargetSource(org.springframework.aop.target.SingletonTargetSource) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ProxyFactory(org.springframework.aop.framework.ProxyFactory) GlobalAdvisorAdapterRegistry(org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry) AdvisorAdapterRegistry(org.springframework.aop.framework.adapter.AdvisorAdapterRegistry) SimplePermissionEntry(org.alfresco.repo.security.permissions.impl.SimplePermissionEntry) Method(java.lang.reflect.Method) MethodInterceptor(org.aopalliance.intercept.MethodInterceptor)

Example 3 with SimplePermissionEntry

use of org.alfresco.repo.security.permissions.impl.SimplePermissionEntry in project alfresco-repository by Alfresco.

the class ACLEntryAfterInvocationTest method testBasicFilterInvalidNodeRefs.

@SuppressWarnings("unchecked")
public void testBasicFilterInvalidNodeRefs() throws Exception {
    runAs("andy");
    Object o = new ClassWithMethods();
    Method method = 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();
    permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
    List<Object> answer = (List<Object>) method.invoke(proxy, new Object[] { Collections.singletonList(rootNodeRef) });
    assertEquals("Collection must be intact", 1, answer.size());
    NodeRef invalidNodeRef = new NodeRef("workspace://SpacesStore/noodle");
    answer = (List<Object>) method.invoke(proxy, new Object[] { Collections.singletonList(invalidNodeRef) });
    assertEquals("Invalid NodeRef should not have been filtered out", 1, answer.size());
}
Also used : SingletonTargetSource(org.springframework.aop.target.SingletonTargetSource) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ProxyFactory(org.springframework.aop.framework.ProxyFactory) GlobalAdvisorAdapterRegistry(org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry) AdvisorAdapterRegistry(org.springframework.aop.framework.adapter.AdvisorAdapterRegistry) SimplePermissionEntry(org.alfresco.repo.security.permissions.impl.SimplePermissionEntry) ArrayList(java.util.ArrayList) List(java.util.List) Method(java.lang.reflect.Method) MethodInterceptor(org.aopalliance.intercept.MethodInterceptor)

Example 4 with SimplePermissionEntry

use of org.alfresco.repo.security.permissions.impl.SimplePermissionEntry in project alfresco-repository by Alfresco.

the class ACLEntryAfterInvocationTest method testBasicAllowChildAssociationRef2.

public void testBasicAllowChildAssociationRef2() 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_PARENT.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));
}
Also used : SingletonTargetSource(org.springframework.aop.target.SingletonTargetSource) ProxyFactory(org.springframework.aop.framework.ProxyFactory) GlobalAdvisorAdapterRegistry(org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry) AdvisorAdapterRegistry(org.springframework.aop.framework.adapter.AdvisorAdapterRegistry) SimplePermissionEntry(org.alfresco.repo.security.permissions.impl.SimplePermissionEntry) Method(java.lang.reflect.Method) MethodInterceptor(org.aopalliance.intercept.MethodInterceptor)

Example 5 with SimplePermissionEntry

use of org.alfresco.repo.security.permissions.impl.SimplePermissionEntry in project alfresco-repository by Alfresco.

the class ACLEntryAfterInvocationTest method testBasicAllowNodePair.

public void testBasicAllowNodePair() throws Exception {
    runAs("andy");
    Object o = new ClassWithMethods();
    Method method = o.getClass().getMethod("echoNodePair", new Class[] { NodeRef.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));
    Pair<Long, NodeRef> rootNodePair = new Pair<Long, NodeRef>(Long.valueOf(1), rootNodeRef);
    Object answer = method.invoke(proxy, new Object[] { rootNodeRef });
    assertEquals(rootNodePair, answer);
}
Also used : SingletonTargetSource(org.springframework.aop.target.SingletonTargetSource) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ProxyFactory(org.springframework.aop.framework.ProxyFactory) GlobalAdvisorAdapterRegistry(org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry) AdvisorAdapterRegistry(org.springframework.aop.framework.adapter.AdvisorAdapterRegistry) SimplePermissionEntry(org.alfresco.repo.security.permissions.impl.SimplePermissionEntry) Method(java.lang.reflect.Method) MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) Pair(org.alfresco.util.Pair)

Aggregations

SimplePermissionEntry (org.alfresco.repo.security.permissions.impl.SimplePermissionEntry)32 Method (java.lang.reflect.Method)26 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)26 ProxyFactory (org.springframework.aop.framework.ProxyFactory)26 AdvisorAdapterRegistry (org.springframework.aop.framework.adapter.AdvisorAdapterRegistry)26 GlobalAdvisorAdapterRegistry (org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry)26 SingletonTargetSource (org.springframework.aop.target.SingletonTargetSource)26 InvocationTargetException (java.lang.reflect.InvocationTargetException)10 NodeRef (org.alfresco.service.cmr.repository.NodeRef)8 ArrayList (java.util.ArrayList)6 Collection (java.util.Collection)3 SimpleNodePermissionEntry (org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry)3 HashSet (java.util.HashSet)2 ChildAssocRefResultSet (org.alfresco.repo.search.results.ChildAssocRefResultSet)2 AccessControlEntry (org.alfresco.repo.security.permissions.AccessControlEntry)2 AccessControlList (org.alfresco.repo.security.permissions.AccessControlList)2 SimpleAccessControlEntry (org.alfresco.repo.security.permissions.SimpleAccessControlEntry)2 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)2 ResultSet (org.alfresco.service.cmr.search.ResultSet)2 LinkedList (java.util.LinkedList)1