mirror of
				https://github.com/Alfresco/alfresco-community-repo.git
				synced 2025-10-22 15:12:38 +00:00 
			
		
		
		
	11008: FileFolderService no longer uses Lucene
   11014: Fixed ETWOTWO-569: Regression after ContentStoreCleaner overhaul
   11021: Fixed HibernateSessionHelperTest
   11028: Fixed unit test's expected values
   11035: Made cm:auditable optional and fixed 64K limit on property list sizes
   11038: IncompleteNodeTagger handles aspects that are not in the dictionary
   11039: Added tests to ensure that QName caching is case-insensitive
   11040: Fixed use of mixed-case QNames for aspects
   11044: Allow background AND in-transaction indexing to be disabled at the same time.
   11046: Removed Lucene use from RegistryServiceImpl
   11050: Removal of Lucene usage
          - ML services finding root using XPath moved to path query
          - RepoStore now uses simple path query
          - Remove unused imports on PersonServiceImpl
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@11215 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
		
	
		
			
				
	
	
		
			247 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			247 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| /*
 | |
|  * Copyright (C) 2005-2007 Alfresco Software Limited.
 | |
|  *
 | |
|  * This program is free software; you can redistribute it and/or
 | |
|  * modify it under the terms of the GNU General Public License
 | |
|  * as published by the Free Software Foundation; either version 2
 | |
|  * of the License, or (at your option) any later version.
 | |
| 
 | |
|  * This program is distributed in the hope that it will be useful,
 | |
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | |
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | |
|  * GNU General Public License for more details.
 | |
| 
 | |
|  * You should have received a copy of the GNU General Public License
 | |
|  * along with this program; if not, write to the Free Software
 | |
|  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 | |
| 
 | |
|  * As a special exception to the terms and conditions of version 2.0 of 
 | |
|  * the GPL, you may redistribute this Program in connection with Free/Libre 
 | |
|  * and Open Source Software ("FLOSS") applications as described in Alfresco's 
 | |
|  * FLOSS exception.  You should have recieved a copy of the text describing 
 | |
|  * the FLOSS exception, and it is also available here: 
 | |
|  * http://www.alfresco.com/legal/licensing"
 | |
|  */
 | |
| package org.alfresco.repo.ownable.impl;
 | |
| 
 | |
| import java.io.Serializable;
 | |
| import java.util.HashMap;
 | |
| 
 | |
| import javax.transaction.UserTransaction;
 | |
| 
 | |
| import junit.framework.TestCase;
 | |
| 
 | |
| import org.alfresco.model.ContentModel;
 | |
| import org.alfresco.repo.security.authentication.AuthenticationComponent;
 | |
| import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
 | |
| import org.alfresco.repo.security.permissions.dynamic.OwnerDynamicAuthority;
 | |
| import org.alfresco.service.ServiceRegistry;
 | |
| import org.alfresco.service.cmr.repository.NodeRef;
 | |
| import org.alfresco.service.cmr.repository.NodeService;
 | |
| import org.alfresco.service.cmr.repository.StoreRef;
 | |
| import org.alfresco.service.cmr.security.AccessStatus;
 | |
| import org.alfresco.service.cmr.security.AuthenticationService;
 | |
| import org.alfresco.service.cmr.security.OwnableService;
 | |
| import org.alfresco.service.cmr.security.PermissionService;
 | |
| import org.alfresco.service.namespace.QName;
 | |
| import org.alfresco.service.transaction.TransactionService;
 | |
| import org.alfresco.util.ApplicationContextHelper;
 | |
| import org.springframework.context.ApplicationContext;
 | |
| 
 | |
| public class OwnableServiceTest extends TestCase
 | |
| {
 | |
|     private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
 | |
| 
 | |
|     private NodeService nodeService;
 | |
| 
 | |
|     private AuthenticationService authenticationService;
 | |
|     
 | |
|     private AuthenticationComponent authenticationComponent;
 | |
|     
 | |
|     private MutableAuthenticationDao authenticationDAO;
 | |
| 
 | |
|     private OwnableService ownableService;
 | |
| 
 | |
|     private NodeRef rootNodeRef;
 | |
| 
 | |
|     private UserTransaction txn;
 | |
|     
 | |
|     private PermissionService permissionService;
 | |
|     
 | |
|     private OwnerDynamicAuthority dynamicAuthority;
 | |
|     
 | |
|     public OwnableServiceTest()
 | |
|     {
 | |
|         super();
 | |
|     }
 | |
| 
 | |
|     public OwnableServiceTest(String arg0)
 | |
|     {
 | |
|         super(arg0);
 | |
|     }
 | |
|     
 | |
|     public void setUp() throws Exception
 | |
|     {
 | |
|         nodeService = (NodeService) ctx.getBean("nodeService");
 | |
|         authenticationService = (AuthenticationService) ctx.getBean("authenticationService");
 | |
|         authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
 | |
|         ownableService = (OwnableService) ctx.getBean("ownableService");
 | |
|         permissionService = (PermissionService) ctx.getBean("permissionService");
 | |
|     
 | |
|         authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
 | |
|         authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao");
 | |
|         
 | |
|         
 | |
|         TransactionService transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE.getLocalName());
 | |
|         txn = transactionService.getUserTransaction();
 | |
|         txn.begin();
 | |
|         
 | |
|         StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
 | |
|         rootNodeRef = nodeService.getRootNode(storeRef);
 | |
|         permissionService.setPermission(rootNodeRef, PermissionService.ALL_AUTHORITIES, PermissionService.ADD_CHILDREN, true);
 | |
|         
 | |
|         if(authenticationDAO.userExists("andy"))
 | |
|         {
 | |
|             authenticationService.deleteAuthentication("andy");
 | |
|         }
 | |
|         authenticationService.createAuthentication("andy", "andy".toCharArray());
 | |
|         
 | |
|         dynamicAuthority = new OwnerDynamicAuthority();
 | |
|         dynamicAuthority.setOwnableService(ownableService);
 | |
|        
 | |
|         authenticationComponent.clearCurrentSecurityContext();
 | |
|     }
 | |
|     
 | |
|     @Override
 | |
|     protected void tearDown() throws Exception
 | |
|     {
 | |
|         try
 | |
|         {
 | |
|             authenticationComponent.clearCurrentSecurityContext();
 | |
|             txn.rollback();
 | |
|         }
 | |
|         catch (Throwable e)
 | |
|         {
 | |
|             // don't absorb any exceptions going past
 | |
|         }
 | |
|         super.tearDown();
 | |
|     }
 | |
|     
 | |
|     public void testSetup()
 | |
|     {
 | |
|         assertNotNull(nodeService);
 | |
|         assertNotNull(authenticationService);
 | |
|         assertNotNull(ownableService);
 | |
|     }
 | |
|     
 | |
|     public void testUnSet()
 | |
|     {
 | |
|         assertNull(ownableService.getOwner(rootNodeRef));
 | |
|         assertFalse(ownableService.hasOwner(rootNodeRef));
 | |
|     }
 | |
|     
 | |
|     public void testCMObject()
 | |
|     {
 | |
|         authenticationService.authenticate("andy", "andy".toCharArray());
 | |
|         NodeRef testNode = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, ContentModel.TYPE_PERSON, ContentModel.TYPE_CMOBJECT, null).getChildRef();
 | |
|         permissionService.setPermission(rootNodeRef, "andy", PermissionService.TAKE_OWNERSHIP, true);
 | |
|         assertEquals("andy", ownableService.getOwner(testNode));
 | |
|         assertTrue(ownableService.hasOwner(testNode));
 | |
|         assertTrue(nodeService.hasAspect(testNode, ContentModel.ASPECT_AUDITABLE));
 | |
|         assertFalse(nodeService.hasAspect(testNode, ContentModel.ASPECT_OWNABLE));
 | |
|         assertTrue(dynamicAuthority.hasAuthority(testNode, "andy"));
 | |
|         
 | |
|         assertEquals("andy", ownableService.getOwner(testNode));
 | |
|         
 | |
| //        nodeService.setProperty(testNode, ContentModel.PROP_CREATOR, "woof");
 | |
| //        assertEquals("woof", ownableService.getOwner(testNode));
 | |
| //        
 | |
| //        nodeService.setProperty(testNode, ContentModel.PROP_CREATOR, "andy");
 | |
| //        assertEquals("andy", ownableService.getOwner(testNode));
 | |
| //        
 | |
|         permissionService.setInheritParentPermissions(testNode, false);
 | |
|         
 | |
|         
 | |
|         assertEquals(AccessStatus.DENIED, permissionService.hasPermission(rootNodeRef, PermissionService.TAKE_OWNERSHIP));
 | |
|         assertEquals(AccessStatus.DENIED, permissionService.hasPermission(rootNodeRef, PermissionService.SET_OWNER));
 | |
|         assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(testNode, PermissionService.TAKE_OWNERSHIP));
 | |
|         assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(testNode, PermissionService.SET_OWNER));
 | |
|         
 | |
|         permissionService.setPermission(rootNodeRef, "andy", PermissionService.WRITE_PROPERTIES, true);
 | |
|         
 | |
|         assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(rootNodeRef, PermissionService.TAKE_OWNERSHIP));
 | |
|         assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(rootNodeRef, PermissionService.SET_OWNER));
 | |
|         assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(testNode, PermissionService.TAKE_OWNERSHIP));
 | |
|         assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(testNode, PermissionService.SET_OWNER));
 | |
|         
 | |
|        
 | |
|         
 | |
|         ownableService.setOwner(testNode, "woof");
 | |
|         assertEquals("woof", ownableService.getOwner(testNode));
 | |
|         assertTrue(dynamicAuthority.hasAuthority(testNode, "woof"));
 | |
|         assertEquals(AccessStatus.DENIED, permissionService.hasPermission(testNode, PermissionService.TAKE_OWNERSHIP));
 | |
|         assertEquals(AccessStatus.DENIED, permissionService.hasPermission(testNode, PermissionService.SET_OWNER));
 | |
|         
 | |
|         
 | |
|         ownableService.setOwner(testNode, "muppet");
 | |
|         assertEquals("muppet", ownableService.getOwner(testNode));
 | |
|         assertTrue(dynamicAuthority.hasAuthority(testNode, "muppet"));
 | |
|         assertEquals(AccessStatus.DENIED, permissionService.hasPermission(testNode, PermissionService.TAKE_OWNERSHIP));
 | |
|         assertEquals(AccessStatus.DENIED, permissionService.hasPermission(testNode, PermissionService.SET_OWNER));
 | |
|         
 | |
|         
 | |
|         ownableService.takeOwnership(testNode);
 | |
|         assertEquals("andy", ownableService.getOwner(testNode));
 | |
|         assertTrue(dynamicAuthority.hasAuthority(testNode, "andy"));
 | |
|         assertTrue(nodeService.hasAspect(testNode, ContentModel.ASPECT_AUDITABLE));
 | |
|         assertTrue(nodeService.hasAspect(testNode, ContentModel.ASPECT_OWNABLE));
 | |
|       
 | |
|         assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(rootNodeRef, PermissionService.TAKE_OWNERSHIP));
 | |
|         assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(rootNodeRef, PermissionService.SET_OWNER));
 | |
|         assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(testNode, PermissionService.TAKE_OWNERSHIP));
 | |
|         assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(testNode, PermissionService.SET_OWNER));
 | |
|         
 | |
|         nodeService.setProperty(testNode, ContentModel.PROP_OWNER, "muppet");
 | |
|         assertEquals("muppet", ownableService.getOwner(testNode));
 | |
|         nodeService.removeAspect(testNode, ContentModel.ASPECT_OWNABLE);
 | |
|         assertEquals("andy", ownableService.getOwner(testNode));
 | |
|         
 | |
|         HashMap<QName, Serializable> aspectProperties = new HashMap<QName, Serializable>();
 | |
|         aspectProperties.put(ContentModel.PROP_OWNER, "muppet");
 | |
|         nodeService.addAspect(testNode, ContentModel.ASPECT_OWNABLE, aspectProperties);
 | |
|         assertEquals("muppet", ownableService.getOwner(testNode));
 | |
|         
 | |
|        
 | |
|     }
 | |
|     
 | |
|     public void testContainer()
 | |
|     {  
 | |
|         authenticationService.authenticate("andy", "andy".toCharArray());
 | |
|         NodeRef testNode = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, ContentModel.TYPE_PERSON, ContentModel.TYPE_CONTAINER, null).getChildRef();
 | |
|         assertNull(ownableService.getOwner(testNode));
 | |
|         assertFalse(ownableService.hasOwner(testNode));
 | |
|         assertFalse(nodeService.hasAspect(testNode, ContentModel.ASPECT_AUDITABLE));
 | |
|         assertFalse(nodeService.hasAspect(testNode, ContentModel.ASPECT_OWNABLE));
 | |
|         assertFalse(dynamicAuthority.hasAuthority(testNode, "andy"));
 | |
|         
 | |
|         assertFalse(permissionService.hasPermission(testNode, PermissionService.READ) == AccessStatus.ALLOWED);
 | |
|         assertFalse(permissionService.hasPermission(testNode, permissionService.getAllPermission()) == AccessStatus.ALLOWED);
 | |
|         
 | |
|         permissionService.setPermission(rootNodeRef, permissionService.getOwnerAuthority(), permissionService.getAllPermission(), true);
 | |
|         
 | |
|         ownableService.setOwner(testNode, "muppet");
 | |
|         assertEquals("muppet", ownableService.getOwner(testNode));
 | |
|         ownableService.takeOwnership(testNode);
 | |
|         assertEquals("andy", ownableService.getOwner(testNode));
 | |
|         assertFalse(nodeService.hasAspect(testNode, ContentModel.ASPECT_AUDITABLE));
 | |
|         assertTrue(nodeService.hasAspect(testNode, ContentModel.ASPECT_OWNABLE));
 | |
|         assertTrue(dynamicAuthority.hasAuthority(testNode, "andy"));
 | |
|         
 | |
|         assertTrue(permissionService.hasPermission(testNode, PermissionService.READ) == AccessStatus.ALLOWED);
 | |
|         assertTrue(permissionService.hasPermission(testNode, permissionService.getAllPermission())== AccessStatus.ALLOWED);
 | |
|         
 | |
|         
 | |
|     }
 | |
|     
 | |
| }
 |