Search in sources :

Example 11 with PersonService

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

the class ArchivedNodeState method create.

public static ArchivedNodeState create(NodeRef archivedNode, ServiceRegistry serviceRegistry) {
    ArchivedNodeState result = new ArchivedNodeState();
    NodeService nodeService = serviceRegistry.getNodeService();
    Map<QName, Serializable> properties = nodeService.getProperties(archivedNode);
    result.archivedNodeRef = archivedNode;
    result.archivedBy = (String) properties.get(ContentModel.PROP_ARCHIVED_BY);
    result.archivedDate = (Date) properties.get(ContentModel.PROP_ARCHIVED_DATE);
    result.name = (String) properties.get(ContentModel.PROP_NAME);
    result.title = (String) properties.get(ContentModel.PROP_TITLE);
    result.description = (String) properties.get(ContentModel.PROP_DESCRIPTION);
    QName type = nodeService.getType(archivedNode);
    result.isContentType = (type.equals(ContentModel.TYPE_CONTENT) || serviceRegistry.getDictionaryService().isSubClass(type, ContentModel.TYPE_CONTENT));
    result.nodeType = type.toPrefixString(serviceRegistry.getNamespaceService());
    PersonService personService = serviceRegistry.getPersonService();
    if (result.archivedBy != null && personService.personExists(result.archivedBy)) {
        NodeRef personNodeRef = personService.getPerson(result.archivedBy, false);
        Map<QName, Serializable> personProps = nodeService.getProperties(personNodeRef);
        result.firstName = (String) personProps.get(ContentModel.PROP_FIRSTNAME);
        result.lastName = (String) personProps.get(ContentModel.PROP_LASTNAME);
    }
    ChildAssociationRef originalParentAssoc = (ChildAssociationRef) properties.get(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC);
    if (serviceRegistry.getPermissionService().hasPermission(originalParentAssoc.getParentRef(), PermissionService.READ).equals(AccessStatus.ALLOWED) && nodeService.exists(originalParentAssoc.getParentRef())) {
        result.displayPath = PathUtil.getDisplayPath(nodeService.getPath(originalParentAssoc.getParentRef()), true);
    } else {
        result.displayPath = "";
    }
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) NodeService(org.alfresco.service.cmr.repository.NodeService) PersonService(org.alfresco.service.cmr.security.PersonService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 12 with PersonService

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

the class RunningActionRestApiTest method setUp.

@SuppressWarnings("unchecked")
@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");
    executingActionsCache = (SimpleCache<String, ExecutionDetails>) appContext.getBean("executingActionsCache");
    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) ExecutionDetails(org.alfresco.service.cmr.action.ExecutionDetails) MutableAuthenticationService(org.alfresco.service.cmr.security.MutableAuthenticationService)

Example 13 with PersonService

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

the class WorkflowModelBuilderTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    namespaceService = new NamespaceServiceMemoryImpl();
    namespaceService.registerNamespace("test", URI);
    namespaceService.registerNamespace(NamespaceService.CONTENT_MODEL_PREFIX, NamespaceService.CONTENT_MODEL_1_0_URI);
    namespaceService.registerNamespace(NamespaceService.BPM_MODEL_PREFIX, NamespaceService.BPM_MODEL_1_0_URI);
    personService = mock(PersonService.class);
    when(personService.getPerson(userName)).thenReturn(person);
    when(personService.personExists(userName)).thenReturn(true);
    nodeService = mock(NodeService.class);
    Map<QName, Serializable> personProps = new HashMap<QName, Serializable>();
    personProps.put(ContentModel.PROP_USERNAME, userName);
    personProps.put(ContentModel.PROP_FIRSTNAME, firstName);
    personProps.put(ContentModel.PROP_LASTNAME, lastName);
    when(nodeService.getProperties(person)).thenReturn(personProps);
    when(nodeService.getProperty(person, ContentModel.PROP_USERNAME)).thenReturn(userName);
    when(nodeService.getProperty(person, ContentModel.PROP_FIRSTNAME)).thenReturn(firstName);
    when(nodeService.getProperty(person, ContentModel.PROP_LASTNAME)).thenReturn(lastName);
    workflowService = mock(WorkflowService.class);
    dictionaryService = mock(DictionaryService.class);
    authenticationService = mock(AuthenticationService.class);
    builder = new WorkflowModelBuilder(namespaceService, nodeService, authenticationService, personService, workflowService, dictionaryService);
}
Also used : Serializable(java.io.Serializable) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) HashMap(java.util.HashMap) WorkflowService(org.alfresco.service.cmr.workflow.WorkflowService) QName(org.alfresco.service.namespace.QName) NamespaceServiceMemoryImpl(org.alfresco.service.namespace.NamespaceServiceMemoryImpl) PersonService(org.alfresco.service.cmr.security.PersonService) NodeService(org.alfresco.service.cmr.repository.NodeService) AuthenticationService(org.alfresco.service.cmr.security.AuthenticationService)

Example 14 with PersonService

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

the class DownloadRestApiTest method setUp.

public void setUp() {
    // Resolve required services
    authenticationService = getServer().getApplicationContext().getBean("AuthenticationService", MutableAuthenticationService.class);
    authenticationComponent = getServer().getApplicationContext().getBean("authenticationComponent", AuthenticationComponent.class);
    contentService = getServer().getApplicationContext().getBean("ContentService", ContentService.class);
    nodeService = getServer().getApplicationContext().getBean("NodeService", NodeService.class);
    personService = getServer().getApplicationContext().getBean("PersonService", PersonService.class);
    // Authenticate as user
    this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
    // if user with given user name doesn't already exist then create user
    if (this.authenticationService.authenticationExists(TEST_USERNAME) == false) {
        // create user
        this.authenticationService.createAuthentication(TEST_USERNAME, "password".toCharArray());
        // create person properties
        PropertyMap personProps = new PropertyMap();
        personProps.put(ContentModel.PROP_USERNAME, TEST_USERNAME);
        personProps.put(ContentModel.PROP_FIRSTNAME, "FirstName123");
        personProps.put(ContentModel.PROP_LASTNAME, "LastName123");
        personProps.put(ContentModel.PROP_EMAIL, "FirstName123.LastName123@email.com");
        personProps.put(ContentModel.PROP_JOBTITLE, "JobTitle123");
        personProps.put(ContentModel.PROP_JOBTITLE, "Organisation123");
        // create person node for user
        this.personService.createPerson(personProps);
    }
    Repository repositoryHelper = (Repository) getServer().getApplicationContext().getBean("repositoryHelper");
    NodeRef companyHome = repositoryHelper.getCompanyHome();
    // Create some static test content
    rootFolder = createNode(companyHome, "rootFolder", ContentModel.TYPE_FOLDER, AuthenticationUtil.getAdminUserName());
    rootFile = createNodeWithTextContent(companyHome, "rootFile", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Root file content");
    level1File = createNodeWithTextContent(rootFolder, "level1File", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Level 1 file content");
    level1Folder = createNode(rootFolder, "level1Folder", ContentModel.TYPE_FOLDER, AuthenticationUtil.getAdminUserName());
    level2File = createNodeWithTextContent(level1Folder, "level2File", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Level 2 file content");
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Repository(org.alfresco.repo.model.Repository) PropertyMap(org.alfresco.util.PropertyMap) AuthenticationComponent(org.alfresco.repo.security.authentication.AuthenticationComponent) NodeService(org.alfresco.service.cmr.repository.NodeService) PersonService(org.alfresco.service.cmr.security.PersonService) ContentService(org.alfresco.service.cmr.repository.ContentService) MutableAuthenticationService(org.alfresco.service.cmr.security.MutableAuthenticationService)

Example 15 with PersonService

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

the class BaseCustomModelApiTest method setup.

@Before
public void setup() throws Exception {
    authenticationService = applicationContext.getBean("authenticationService", MutableAuthenticationService.class);
    personService = applicationContext.getBean("personService", PersonService.class);
    customModelService = applicationContext.getBean("customModelService", CustomModelService.class);
    final AuthorityService authorityService = applicationContext.getBean("authorityService", AuthorityService.class);
    this.nonAdminUserName = createUser("nonAdminUser" + System.currentTimeMillis(), "password", null);
    this.customModelAdmin = createUser("customModelAdmin" + System.currentTimeMillis(), "password", null);
    users.add(nonAdminUserName);
    users.add(customModelAdmin);
    // Add 'customModelAdmin' user into 'ALFRESCO_MODEL_ADMINISTRATORS' group
    transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            authorityService.addAuthority(CustomModelServiceImpl.GROUP_ALFRESCO_MODEL_ADMINISTRATORS_AUTHORITY, customModelAdmin);
            return null;
        }
    });
}
Also used : CustomModelService(org.alfresco.service.cmr.dictionary.CustomModelService) PersonService(org.alfresco.service.cmr.security.PersonService) AuthorityService(org.alfresco.service.cmr.security.AuthorityService) MutableAuthenticationService(org.alfresco.service.cmr.security.MutableAuthenticationService) Before(org.junit.Before)

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