Search in sources :

Example 6 with SimplePermissionEntry

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

the class ACLEntryVoterTest method testBasicAllowStore.

public void testBasicAllowStore() throws Exception {
    runAs("andy");
    permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
    Object o = new ClassWithMethods();
    Method method = o.getClass().getMethod("testOneStoreRef", new Class[] { StoreRef.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.getStoreRef() });
}
Also used : SingletonTargetSource(org.springframework.aop.target.SingletonTargetSource) ProxyFactory(org.springframework.aop.framework.ProxyFactory) SimplePermissionEntry(org.alfresco.repo.security.permissions.impl.SimplePermissionEntry) GlobalAdvisorAdapterRegistry(org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry) AdvisorAdapterRegistry(org.springframework.aop.framework.adapter.AdvisorAdapterRegistry) Method(java.lang.reflect.Method) MethodInterceptor(org.aopalliance.intercept.MethodInterceptor)

Example 7 with SimplePermissionEntry

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

the class ACLEntryVoterTest method testMultiNodeMethodsArg0.

public void testMultiNodeMethodsArg0() throws Exception {
    runAs("andy");
    Object o = new ClassWithMethods();
    Method method = o.getClass().getMethod("testManyNodeRef", new Class[] { NodeRef.class, NodeRef.class, NodeRef.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[] { null, null, null, null });
    try {
        method.invoke(proxy, new Object[] { rootNodeRef, null, null, null });
        assertNotNull(null);
    } catch (InvocationTargetException e) {
    }
    permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
    method.invoke(proxy, new Object[] { rootNodeRef, null, null, null });
}
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) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 8 with SimplePermissionEntry

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

the class ACLEntryVoterTest method testDenyParentAssocNode.

public void testDenyParentAssocNode() throws Exception {
    runAs("andy");
    permissionService.setPermission(new SimplePermissionEntry(systemNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
    Object o = new ClassWithMethods();
    Method method = o.getClass().getMethod("testOneChildAssociationRef", new Class[] { ChildAssociationRef.class });
    AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_PARENT.0.sys:base.Read")));
    proxyFactory.setTargetSource(new SingletonTargetSource(o));
    Object proxy = proxyFactory.getProxy();
    try {
        method.invoke(proxy, new Object[] { nodeService.getPrimaryParent(systemNodeRef) });
        assertNotNull(null);
    } catch (InvocationTargetException e) {
    }
}
Also used : SingletonTargetSource(org.springframework.aop.target.SingletonTargetSource) ProxyFactory(org.springframework.aop.framework.ProxyFactory) SimplePermissionEntry(org.alfresco.repo.security.permissions.impl.SimplePermissionEntry) GlobalAdvisorAdapterRegistry(org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry) AdvisorAdapterRegistry(org.springframework.aop.framework.adapter.AdvisorAdapterRegistry) Method(java.lang.reflect.Method) MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 9 with SimplePermissionEntry

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

the class ACLEntryVoterTest method testBasicAllow.

public void testBasicAllow() 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_ALLOW")));
    proxyFactory.setTargetSource(new SingletonTargetSource(o));
    Object proxy = proxyFactory.getProxy();
    method.invoke(proxy, new Object[] { rootNodeRef });
}
Also used : SingletonTargetSource(org.springframework.aop.target.SingletonTargetSource) ProxyFactory(org.springframework.aop.framework.ProxyFactory) SimplePermissionEntry(org.alfresco.repo.security.permissions.impl.SimplePermissionEntry) GlobalAdvisorAdapterRegistry(org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry) AdvisorAdapterRegistry(org.springframework.aop.framework.adapter.AdvisorAdapterRegistry) Method(java.lang.reflect.Method) MethodInterceptor(org.aopalliance.intercept.MethodInterceptor)

Example 10 with SimplePermissionEntry

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

the class GetSetPermissionsMethod method execute.

private NodePermissionEntry execute(Reference reference, Set<String> toAllow, Set<String> toDeny) {
    NodeRef rNodeRef = reference.toNodeRef();
    List<PermissionEntry> permissions = new LinkedList<>();
    for (String permission : toAllow) {
        PermissionReference permissionReference = PermissionReferenceImpl.getPermissionReference(userPermissions.getPermissionTypeQName(), permission);
        permissions.add(new SimplePermissionEntry(rNodeRef, permissionReference, authority, AccessStatus.ALLOWED));
    }
    for (String permission : toDeny) {
        PermissionReference permissionReference = PermissionReferenceImpl.getPermissionReference(userPermissions.getPermissionTypeQName(), permission);
        permissions.add(new SimplePermissionEntry(rNodeRef, permissionReference, authority, AccessStatus.DENIED));
    }
    return new SimpleNodePermissionEntry(rNodeRef, false, permissions);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) SimpleNodePermissionEntry(org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry) PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) PermissionEntry(org.alfresco.repo.security.permissions.PermissionEntry) SimplePermissionEntry(org.alfresco.repo.security.permissions.impl.SimplePermissionEntry) NodePermissionEntry(org.alfresco.repo.security.permissions.NodePermissionEntry) SimpleNodePermissionEntry(org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry) SimplePermissionEntry(org.alfresco.repo.security.permissions.impl.SimplePermissionEntry) LinkedList(java.util.LinkedList)

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