Search in sources :

Example 1 with PersonService

use of org.alfresco.service.cmr.security.PersonService in project alfresco-remote-api by Alfresco.

the class AbstractWorkflowRestApiTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    ApplicationContext appContext = getServer().getApplicationContext();
    namespaceService = (NamespaceService) appContext.getBean("NamespaceService");
    workflowService = (WorkflowService) appContext.getBean("WorkflowService");
    MutableAuthenticationService authenticationService = (MutableAuthenticationService) appContext.getBean("AuthenticationService");
    PersonService personService = (PersonService) appContext.getBean("PersonService");
    SearchService searchService = (SearchService) appContext.getBean("SearchService");
    FileFolderService fileFolderService = (FileFolderService) appContext.getBean("FileFolderService");
    nodeService = (NodeService) appContext.getBean("NodeService");
    // for the purposes of the tests make sure workflow engine is enabled/visible.
    WorkflowAdminServiceImpl workflowAdminService = (WorkflowAdminServiceImpl) appContext.getBean("workflowAdminService");
    this.wfTestHelper = new WorkflowTestHelper(workflowAdminService, getEngine(), true);
    AuthorityService authorityService = (AuthorityService) appContext.getBean("AuthorityService");
    personManager = new TestPersonManager(authenticationService, personService, nodeService);
    groupManager = new TestGroupManager(authorityService);
    authenticationComponent = (AuthenticationComponent) appContext.getBean("authenticationComponent");
    dictionaryService = (DictionaryService) appContext.getBean("dictionaryService");
    personManager.createPerson(USER1);
    personManager.createPerson(USER2);
    personManager.createPerson(USER3);
    authenticationComponent.setSystemUserAsCurrentUser();
    groupManager.addUserToGroup(GROUP, USER2);
    packageRef = workflowService.createPackage(null);
    NodeRef companyHome = searchService.selectNodes(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE), COMPANY_HOME, null, namespaceService, false).get(0);
    contentNodeRef = fileFolderService.create(companyHome, TEST_CONTENT + System.currentTimeMillis(), ContentModel.TYPE_CONTENT).getNodeRef();
    authenticationComponent.clearCurrentSecurityContext();
}
Also used : TestPersonManager(org.alfresco.repo.security.person.TestPersonManager) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ApplicationContext(org.springframework.context.ApplicationContext) PersonService(org.alfresco.service.cmr.security.PersonService) SearchService(org.alfresco.service.cmr.search.SearchService) AuthorityService(org.alfresco.service.cmr.security.AuthorityService) WorkflowAdminServiceImpl(org.alfresco.repo.workflow.WorkflowAdminServiceImpl) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) MutableAuthenticationService(org.alfresco.service.cmr.security.MutableAuthenticationService) WorkflowTestHelper(org.alfresco.repo.workflow.WorkflowTestHelper) TestGroupManager(org.alfresco.repo.security.person.TestGroupManager)

Example 2 with PersonService

use of org.alfresco.service.cmr.security.PersonService in project alfresco-remote-api by Alfresco.

the class PutMethodTest method setUp.

@Before
public void setUp() throws Exception {
    searchService = ctx.getBean("SearchService", SearchService.class);
    fileFolderService = ctx.getBean("FileFolderService", FileFolderService.class);
    nodeService = ctx.getBean("NodeService", NodeService.class);
    transactionService = ctx.getBean("transactionService", TransactionService.class);
    webDAVHelper = ctx.getBean("webDAVHelper", WebDAVHelper.class);
    authenticationService = ctx.getBean("authenticationService", MutableAuthenticationService.class);
    personService = ctx.getBean("PersonService", PersonService.class);
    lockService = ctx.getBean("LockService", LockService.class);
    contentService = ctx.getBean("contentService", ContentService.class);
    checkOutCheckInService = ctx.getBean("CheckOutCheckInService", CheckOutCheckInService.class);
    permissionService = ctx.getBean("PermissionService", PermissionService.class);
    namespaceService = ctx.getBean("namespaceService", NamespaceService.class);
    actionService = ctx.getBean("ActionService", ActionService.class);
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
    companyHomeNodeRef = repositoryHelper.getCompanyHome();
    txn = transactionService.getUserTransaction();
    txn.begin();
    createUser(USER1_NAME);
    createUser(USER2_NAME);
    InputStream testDataIS = getClass().getClassLoader().getResourceAsStream(TEST_DATA_FILE_NAME);
    InputStream davLockInfoAdminIS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_ADMIN);
    InputStream davLockInfoUser2IS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_USER2);
    testDataFile = IOUtils.toByteArray(testDataIS);
    davLockInfoAdminFile = IOUtils.toByteArray(davLockInfoAdminIS);
    davLockInfoUser2File = IOUtils.toByteArray(davLockInfoUser2IS);
    testDataIS.close();
    davLockInfoAdminIS.close();
    davLockInfoUser2IS.close();
    // Create a test file with versionable aspect and content
    Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
    versionableDocName = "doc-" + GUID.generate();
    properties.put(ContentModel.PROP_NAME, versionableDocName);
    versionableDoc = nodeService.createNode(companyHomeNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(ContentModel.USER_MODEL_URI, versionableDocName), ContentModel.TYPE_CONTENT, properties).getChildRef();
    contentService.getWriter(versionableDoc, ContentModel.PROP_CONTENT, true).putContent("WebDAVTestContent");
    nodeService.addAspect(versionableDoc, ContentModel.ASPECT_VERSIONABLE, null);
    txn.commit();
    txn = transactionService.getUserTransaction();
    txn.begin();
}
Also used : Serializable(java.io.Serializable) TransactionService(org.alfresco.service.transaction.TransactionService) LockService(org.alfresco.service.cmr.lock.LockService) HashMap(java.util.HashMap) InputStream(java.io.InputStream) QName(org.alfresco.service.namespace.QName) NodeService(org.alfresco.service.cmr.repository.NodeService) PersonService(org.alfresco.service.cmr.security.PersonService) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) ContentService(org.alfresco.service.cmr.repository.ContentService) MutableAuthenticationService(org.alfresco.service.cmr.security.MutableAuthenticationService) PermissionService(org.alfresco.service.cmr.security.PermissionService) CheckOutCheckInService(org.alfresco.service.cmr.coci.CheckOutCheckInService) NamespaceService(org.alfresco.service.namespace.NamespaceService) SearchService(org.alfresco.service.cmr.search.SearchService) ActionService(org.alfresco.service.cmr.action.ActionService) Before(org.junit.Before)

Example 3 with PersonService

use of org.alfresco.service.cmr.security.PersonService in project alfresco-remote-api by Alfresco.

the class AbstractBaseApiTest method setup.

@Override
@Before
public void setup() throws Exception {
    jacksonUtil = new JacksonUtil(applicationContext.getBean("jsonHelper", JacksonHelper.class));
    if (networkOne == null) {
        // note: populateTestData/createTestData will be called (which currently creates 2 tenants, 9 users per tenant, 10 sites per tenant, ...)
        networkOne = getTestFixture().getRandomNetwork();
    }
    // userOneN1 = networkN1.createUser();
    // userTwoN1 = networkN1.createUser();
    String tenantDomain = networkOne.getId();
    if (!TenantService.DEFAULT_DOMAIN.equals(tenantDomain)) {
        networkAdmin = DEFAULT_ADMIN + "@" + tenantDomain;
    }
    // to enable admin access via test calls - eg. via PublicApiClient -> AbstractTestApi -> findUserByUserName
    getOrCreateUser(networkAdmin, "admin", networkOne);
    setRequestContext(networkOne.getId(), networkAdmin, DEFAULT_ADMIN_PWD);
    // note: createUser currently relies on repoService
    user1 = createUser("user1-" + RUNID, "user1Password", networkOne);
    user2 = createUser("user2-" + RUNID, "user2Password", networkOne);
    // used-by teardown to cleanup
    authenticationService = applicationContext.getBean("authenticationService", MutableAuthenticationService.class);
    personService = applicationContext.getBean("personService", PersonService.class);
    users.add(user1);
    users.add(user2);
    setRequestContext(networkOne.getId(), user1, null);
    tSiteId = createSite("TestSite A - " + RUNID, SiteVisibility.PRIVATE).getId();
    tDocLibNodeId = getSiteContainerNodeId(tSiteId, "documentLibrary");
    setRequestContext(null, null, null);
}
Also used : JacksonUtil(org.alfresco.rest.api.tests.util.JacksonUtil) PersonService(org.alfresco.service.cmr.security.PersonService) RestApiUtil.toJsonAsString(org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsString) MutableAuthenticationService(org.alfresco.service.cmr.security.MutableAuthenticationService) Before(org.junit.Before)

Example 4 with PersonService

use of org.alfresco.service.cmr.security.PersonService in project alfresco-remote-api by Alfresco.

the class ReplicationRestApiTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    ApplicationContext appContext = getServer().getApplicationContext();
    nodeService = (NodeService) appContext.getBean("NodeService");
    replicationService = (ReplicationService) appContext.getBean("ReplicationService");
    actionTrackingService = (ActionTrackingService) appContext.getBean("actionTrackingService");
    repositoryHelper = (Repository) appContext.getBean("repositoryHelper");
    transactionService = (TransactionService) appContext.getBean("transactionService");
    MutableAuthenticationService authenticationService = (MutableAuthenticationService) appContext.getBean("AuthenticationService");
    PersonService personService = (PersonService) appContext.getBean("PersonService");
    personManager = new TestPersonManager(authenticationService, personService, nodeService);
    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    personManager.createPerson(USER_NORMAL);
    // Ensure we start with no replication definitions
    // (eg another test left them behind)
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    for (ReplicationDefinition rd : replicationService.loadReplicationDefinitions()) {
        replicationService.deleteReplicationDefinition(rd);
    }
    txn.commit();
    // Grab a reference to the data dictionary
    dataDictionary = nodeService.getChildByName(repositoryHelper.getCompanyHome(), ContentModel.ASSOC_CONTAINS, "Data Dictionary");
    AuthenticationUtil.clearCurrentSecurityContext();
}
Also used : TestPersonManager(org.alfresco.repo.security.person.TestPersonManager) UserTransaction(javax.transaction.UserTransaction) ApplicationContext(org.springframework.context.ApplicationContext) ReplicationDefinition(org.alfresco.service.cmr.replication.ReplicationDefinition) PersonService(org.alfresco.service.cmr.security.PersonService) MutableAuthenticationService(org.alfresco.service.cmr.security.MutableAuthenticationService)

Example 5 with PersonService

use of org.alfresco.service.cmr.security.PersonService in project alfresco-remote-api by Alfresco.

the class Invites method getPersonIfAllowed.

private TemplateNode getPersonIfAllowed(final String userName) {
    final PersonService personService = serviceRegistry.getPersonService();
    NodeRef inviterRef = AuthenticationUtil.runAs(new RunAsWork<NodeRef>() {

        public NodeRef doWork() throws Exception {
            if (!personService.personExists(userName)) {
                return null;
            }
            return personService.getPerson(userName, false);
        }
    }, AuthenticationUtil.getSystemUserName());
    if (inviterRef != null && serviceRegistry.getPermissionService().hasPermission(inviterRef, PermissionService.READ_PROPERTIES).equals(AccessStatus.ALLOWED)) {
        return new TemplateNode(inviterRef, serviceRegistry, null);
    }
    return null;
}
Also used : TemplateNode(org.alfresco.repo.template.TemplateNode) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PersonService(org.alfresco.service.cmr.security.PersonService) WebScriptException(org.springframework.extensions.webscripts.WebScriptException)

Aggregations

PersonService (org.alfresco.service.cmr.security.PersonService)16 NodeRef (org.alfresco.service.cmr.repository.NodeRef)8 NodeService (org.alfresco.service.cmr.repository.NodeService)7 MutableAuthenticationService (org.alfresco.service.cmr.security.MutableAuthenticationService)7 Before (org.junit.Before)4 Serializable (java.io.Serializable)3 TestPersonManager (org.alfresco.repo.security.person.TestPersonManager)3 QName (org.alfresco.service.namespace.QName)3 ApplicationContext (org.springframework.context.ApplicationContext)3 HashMap (java.util.HashMap)2 UserTransaction (javax.transaction.UserTransaction)2 TemplateNode (org.alfresco.repo.template.TemplateNode)2 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)2 ReplicationDefinition (org.alfresco.service.cmr.replication.ReplicationDefinition)2 ContentService (org.alfresco.service.cmr.repository.ContentService)2 SearchService (org.alfresco.service.cmr.search.SearchService)2 AuthenticationService (org.alfresco.service.cmr.security.AuthenticationService)2 AuthorityService (org.alfresco.service.cmr.security.AuthorityService)2 User (org.alfresco.web.bean.repository.User)2 InputStream (java.io.InputStream)1