Java Code Examples for org.alfresco.service.cmr.security.PermissionService#setPermission()

The following examples show how to use org.alfresco.service.cmr.security.PermissionService#setPermission() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultilingualContentServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void testGetTranslationContainerPermissions() throws Exception
{
    // Grant the guest user rights to our working folder
    PermissionService permissionService = serviceRegistry.getPermissionService();
    AuthenticationComponent authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    permissionService.setPermission(
            folderNodeRef,
            AuthenticationUtil.getGuestUserName(),
            PermissionService.ALL_PERMISSIONS,
            true);
    // Get the current authentication
    AuthenticationUtil.pushAuthentication();
    try
    {
        authenticationComponent.setGuestUserAsCurrentUser();
        // Create some documents
        NodeRef chineseContentNodeRef = createContent();
        // Make a translation
        multilingualContentService.makeTranslation(chineseContentNodeRef, Locale.CHINESE);
        multilingualContentService.getTranslationContainer(chineseContentNodeRef);
    }
    finally
    {
        AuthenticationUtil.popAuthentication();
    }
}
 
Example 2
Source File: MultilingualContentServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Check whether non-admin users can take part in ML document manipulation
 */
public void testPermissions() throws Exception
{
    // Grant the guest user rights to our working folder
    PermissionService permissionService = serviceRegistry.getPermissionService();
    AuthenticationComponent authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    permissionService.setPermission(
            folderNodeRef,
            AuthenticationUtil.getGuestUserName(),
            PermissionService.ALL_PERMISSIONS,
            true);
    // Push the current authentication
    AuthenticationUtil.pushAuthentication();
    try
    {
        authenticationComponent.setGuestUserAsCurrentUser();
        // Create some documents
        NodeRef chineseContentNodeRef = createContent();
        NodeRef frenchContentNodeRef = createContent();
        // Do ML work
        multilingualContentService.makeTranslation(chineseContentNodeRef, Locale.CHINESE);
        multilingualContentService.addTranslation(frenchContentNodeRef, chineseContentNodeRef, Locale.FRENCH);
        multilingualContentService.addEmptyTranslation(chineseContentNodeRef, null, Locale.JAPANESE);
    }
    finally
    {
        AuthenticationUtil.popAuthentication();
    }
}
 
Example 3
Source File: OwnableServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setUp() throws Exception
{
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        throw new AlfrescoRuntimeException(
                "A previous tests did not clean up transaction: " +
                AlfrescoTransactionSupport.getTransactionId());
    }
    
    nodeService = (NodeService) ctx.getBean("nodeService");
    authenticationService = (MutableAuthenticationService) 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();
}
 
Example 4
Source File: ActionServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * http://issues.alfresco.com/jira/browse/ALF-5027
 */
@Test
public void testALF5027() throws Exception
{
    String userName = "bob" + GUID.generate();
    createUser(userName);
    PermissionService permissionService = (PermissionService)applicationContext.getBean("PermissionService");
    permissionService.setPermission(rootNodeRef, userName, PermissionService.COORDINATOR, true);
    
    AuthenticationUtil.setRunAsUser(userName);
    
    NodeRef myNodeRef = nodeService.createNode(
            this.rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName("{test}myTestNode" + GUID.generate()),
            ContentModel.TYPE_CONTENT).getChildRef();
    
    CheckOutCheckInService coci = (CheckOutCheckInService)applicationContext.getBean("CheckoutCheckinService");
    NodeRef workingcopy = coci.checkout(myNodeRef);
    assertNotNull(workingcopy);
    
    assertFalse(nodeService.hasAspect(myNodeRef, ContentModel.ASPECT_DUBLINCORE));
    
    Action action1 = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
    action1.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_DUBLINCORE);        
    actionService.executeAction(action1, myNodeRef);
    
    // The action should have been ignored since the node is locked
    assertFalse(nodeService.hasAspect(myNodeRef, ContentModel.ASPECT_DUBLINCORE));
    
    coci.checkin(workingcopy, null);
    actionService.executeAction(action1, myNodeRef);
    
    assertTrue(nodeService.hasAspect(myNodeRef, ContentModel.ASPECT_DUBLINCORE));
}
 
Example 5
Source File: FTPServerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    applicationContext = ApplicationContextHelper.getApplicationContext();
    
    nodeService = (NodeService)applicationContext.getBean("nodeService");
    personService = (PersonService)applicationContext.getBean("personService");
    authenticationService = (MutableAuthenticationService)applicationContext.getBean("AuthenticationService");
    authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");
    transactionService = (TransactionService)applicationContext.getBean("transactionService");
    repositoryHelper = (Repository)applicationContext.getBean("repositoryHelper");
    permissionService = (PermissionService)applicationContext.getBean("permissionService");
    ServerConfigurationAccessor fileServerConfiguration = (ServerConfigurationAccessor)applicationContext.getBean("fileServerConfiguration");
    ftpConfigSection = (FTPConfigSection) fileServerConfiguration.getConfigSection( FTPConfigSection.SectionName);
    
    assertNotNull("nodeService is null", nodeService);
    assertNotNull("reporitoryHelper is null", repositoryHelper);
    assertNotNull("personService is null", personService);
    assertNotNull("authenticationService is null", authenticationService);
    assertNotNull("authenticationComponent is null", authenticationComponent);
    
    authenticationComponent.setSystemUserAsCurrentUser();
    
    final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
    
    RetryingTransactionCallback<Void> createUsersCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable
        {
            createUser(USER_ONE, PASSWORD_ONE, -1); 
            createUser(USER_TWO, PASSWORD_TWO, -1);
            createUser(USER_THREE, PASSWORD_THREE, 30);
            return null;
        }
    };
    tran.doInTransaction(createUsersCB);
    
    RetryingTransactionCallback<Void> createTestDirCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable
        {
            {
                NodeRef userOneHome = repositoryHelper.getUserHome(personService.getPerson(USER_ONE));
                permissionService.setPermission(userOneHome, USER_TWO, PermissionService.CONTRIBUTOR, true);
                permissionService.setPermission(userOneHome, USER_TWO, PermissionService.WRITE, true);
            }
            return null;
        }
    };
    tran.doInTransaction(createTestDirCB, false, true);
}
 
Example 6
Source File: LockOwnerDynamicAuthorityTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setUp() throws Exception
{
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        throw new AlfrescoRuntimeException(
                "A previous tests did not clean up transaction: " +
                AlfrescoTransactionSupport.getTransactionId());
    }
    
    nodeService = (NodeService) ctx.getBean("nodeService");
    authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService");
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    lockService = (LockService) ctx.getBean("lockService");
    permissionService = (PermissionService) ctx.getBean("permissionService");
    authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao");

    checkOutCheckInService = (CheckOutCheckInService) ctx.getBean("checkOutCheckInService");
    ownableService = (OwnableService) ctx.getBean("ownableService");
    
    authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());

    TransactionService transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE
            .getLocalName());
    userTransaction = transactionService.getUserTransaction();
    userTransaction.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());
    if (authenticationDAO.userExists("lemur"))
    {
        authenticationService.deleteAuthentication("lemur");
    }
    authenticationService.createAuthentication("lemur", "lemur".toCharArray());
    if (authenticationDAO.userExists("frog"))
    {
        authenticationService.deleteAuthentication("frog");
    }
    authenticationService.createAuthentication("frog", "frog".toCharArray());

    dynamicAuthority = new LockOwnerDynamicAuthority();
    dynamicAuthority.setLockService(lockService);

    authenticationComponent.clearCurrentSecurityContext();
}
 
Example 7
Source File: SearchServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    nodeService = (NodeService) ctx.getBean("dbNodeService");
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService");
    authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao");
    pubSearchService = (SearchService) ctx.getBean("SearchService");
    pubPermissionService = (PermissionService) ctx.getBean("PermissionService");

    this.authenticationComponent.setSystemUserAsCurrentUser();

    TransactionService transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE
            .getLocalName());
    tx = transactionService.getUserTransaction();
    tx.begin();

    if (!authenticationDAO.userExists("andy"))
    {
        authenticationService.createAuthentication("andy", "andy".toCharArray());
    }

    if (!authenticationDAO.userExists(AuthenticationUtil.getAdminUserName()))
    {
        authenticationService.createAuthentication(AuthenticationUtil.getAdminUserName(), "admin".toCharArray());
    }

    if (!authenticationDAO.userExists("administrator"))
    {
        authenticationService.createAuthentication("administrator", "administrator".toCharArray());
    }

    StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);

    n1 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}01"),
            ContentModel.TYPE_FOLDER).getChildRef();
    pubPermissionService.setPermission(n1, "andy", "Read", true);
    n2 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}02"),
            ContentModel.TYPE_FOLDER).getChildRef();
    pubPermissionService.setPermission(n2, "andy", "Read", true);
    n3 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}03"),
            ContentModel.TYPE_FOLDER).getChildRef();
    pubPermissionService.setPermission(n3, "andy", "Read", true);
    n4 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}04"),
            ContentModel.TYPE_FOLDER).getChildRef();
    pubPermissionService.setPermission(n4, "andy", "Read", true);
    n5 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}05"),
            ContentModel.TYPE_FOLDER).getChildRef();
    pubPermissionService.setPermission(n5, "andy", "Read", true);
    nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}06"),
            ContentModel.TYPE_FOLDER).getChildRef();
    nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}07"),
            ContentModel.TYPE_FOLDER).getChildRef();
    nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}08"),
            ContentModel.TYPE_FOLDER).getChildRef();
    nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}09"),
            ContentModel.TYPE_FOLDER).getChildRef();
    nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}10"),
            ContentModel.TYPE_FOLDER).getChildRef();
}
 
Example 8
Source File: FileFolderLoaderTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setUp() throws Exception
{
    // Make sure we don't get leaked threads from other tests
    AuthenticationUtil.clearCurrentSecurityContext();
    AuthenticationUtil.pushAuthentication();

    RunAsWork<Void> setUpWork = new RunAsWork<Void>()
    {
        @Override
        public Void doWork() throws Exception
        {
            fileFolderLoader = (FileFolderLoader) ctx.getBean("FileFolderLoader");
            fileFolderService = (FileFolderService) ctx.getBean("FileFolderService");
            permissionService = (PermissionService) ctx.getBean("PermissionService");
            transactionService = (TransactionService) ctx.getBean("TransactionService");
            nodeService = (NodeService) ctx.getBean("nodeService");
            NodeRef companyHomeNodeRef = fileFolderLoader.getRepository().getCompanyHome();
            NodeRef sharedHomeNodeRef = fileFolderLoader.getRepository().getSharedHome();
            List<FileInfo> sharedHomeFileInfos = fileFolderService.getNamePath(companyHomeNodeRef, sharedHomeNodeRef);
            sharedHomePath = "/" + sharedHomeFileInfos.get(0).getName();
            
            // Create a folder that will be invisible to all normal users
            FileInfo hiddenFolderInfo = fileFolderService.create(sharedHomeNodeRef, "HideThis", ContentModel.TYPE_FOLDER);
            hiddenFolderNodeRef = hiddenFolderInfo.getNodeRef();
            hiddenFolderPath = sharedHomePath + "/HideThis";
            permissionService.setInheritParentPermissions(hiddenFolderNodeRef, false);
            
            // Create a folder that will be read-only
            FileInfo readOnlyFolderInfo = fileFolderService.create(sharedHomeNodeRef, "ReadOnlyThis", ContentModel.TYPE_FOLDER);
            readOnlyFolderNodeRef = readOnlyFolderInfo.getNodeRef();
            readOnlyFolderPath = sharedHomePath + "/ReadOnlyThis";
            permissionService.setInheritParentPermissions(readOnlyFolderNodeRef, false);
            permissionService.setPermission(readOnlyFolderNodeRef, PermissionService.ALL_AUTHORITIES, PermissionService.READ, true);
            
            // Create a folder to write to
            FileInfo writeFolderInfo = fileFolderService.create(sharedHomeNodeRef, "WriteThis", ContentModel.TYPE_FOLDER);
            writeFolderNodeRef = writeFolderInfo.getNodeRef();
            writeFolderPath = sharedHomePath + "/WriteThis";
            
            // Done
            return null;
        }
    };
    AuthenticationUtil.runAsSystem(setUpWork);
}