Search in sources :

Example 1 with Session

use of org.nuxeo.ecm.directory.Session in project nuxeo-drive-server by nuxeo.

the class AbstractChangeFinderTestCase method init.

@Before
public void init() throws Exception {
    // Enable deletion listener because the tear down disables it
    eventServiceAdmin.setListenerEnabledFlag("nuxeoDriveFileSystemDeletionListener", true);
    lastEventLogId = 0;
    lastSyncActiveRootDefinitions = "";
    Framework.getProperties().put("org.nuxeo.drive.document.change.limit", "20");
    // Create test users
    try (Session userDir = directoryService.open("userDirectory")) {
        Map<String, Object> user1 = new HashMap<>();
        user1.put("username", "user1");
        user1.put("groups", Arrays.asList(new String[] { "members" }));
        userDir.createEntry(user1);
    }
    user1Session = coreFeature.openCoreSession("user1");
    commitAndWaitForAsyncCompletion();
    folder1 = session.createDocument(session.createDocumentModel("/", "folder1", "Folder"));
    folder2 = session.createDocument(session.createDocumentModel("/", "folder2", "Folder"));
    folder3 = session.createDocument(session.createDocumentModel("/", "folder3", "Folder"));
    setPermissions(folder1, new ACE("user1", SecurityConstants.READ_WRITE));
    setPermissions(folder2, new ACE("user1", SecurityConstants.READ_WRITE));
    commitAndWaitForAsyncCompletion();
}
Also used : ACE(org.nuxeo.ecm.core.api.security.ACE) HashMap(java.util.HashMap) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) Session(org.nuxeo.ecm.directory.Session) CoreSession(org.nuxeo.ecm.core.api.CoreSession) Before(org.junit.Before)

Example 2 with Session

use of org.nuxeo.ecm.directory.Session in project nuxeo-drive-server by nuxeo.

the class TestNuxeoDriveManager method createUserSessionsAndFolders.

@Before
public void createUserSessionsAndFolders() throws Exception {
    try (Session userDir = directoryService.open("userDirectory")) {
        if (userDir.getEntry("user1") != null) {
            userDir.deleteEntry("user1");
        }
        Map<String, Object> user1 = new HashMap<>();
        user1.put("username", "user1");
        user1.put("groups", Arrays.asList(new String[] { "members" }));
        userDir.createEntry(user1);
        if (userDir.getEntry("user2") != null) {
            userDir.deleteEntry("user2");
        }
        Map<String, Object> user2 = new HashMap<>();
        user2.put("username", "user2");
        user2.put("groups", Arrays.asList(new String[] { "members" }));
        userDir.createEntry(user2);
    }
    workspace_1 = session.createDocument(session.createDocumentModel("/default-domain/workspaces", "workspace-1", "Workspace"));
    folder_1_1 = session.createDocument(session.createDocumentModel("/default-domain/workspaces/workspace-1", "folder-1-1", "Folder"));
    workspace_2 = session.createDocument(session.createDocumentModel("/default-domain/workspaces", "workspace-2", "Workspace"));
    folder_2_1 = session.createDocument(session.createDocumentModel("/default-domain/workspaces/workspace-2", "folder-2-1", "Folder"));
    setPermissions(workspace_1, new ACE("members", SecurityConstants.READ));
    setPermissions(workspace_2, new ACE("members", SecurityConstants.READ_WRITE));
    user1Session = coreFeature.openCoreSession(userManager.getPrincipal("user1"));
    user2Session = coreFeature.openCoreSession(userManager.getPrincipal("user2"));
    user1Workspace = userWorkspaceService.getCurrentUserPersonalWorkspace(user1Session, user1Session.getDocument(new PathRef("/default-domain"))).getRef();
    user2Workspace = userWorkspaceService.getCurrentUserPersonalWorkspace(user2Session, user2Session.getDocument(new PathRef("/default-domain"))).getRef();
}
Also used : ACE(org.nuxeo.ecm.core.api.security.ACE) HashMap(java.util.HashMap) PathRef(org.nuxeo.ecm.core.api.PathRef) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) Session(org.nuxeo.ecm.directory.Session) CoreSession(org.nuxeo.ecm.core.api.CoreSession) Before(org.junit.Before)

Example 3 with Session

use of org.nuxeo.ecm.directory.Session in project nuxeo-drive-server by nuxeo.

the class TestNuxeoDriveManager method closeSessionsAndDeleteUsers.

@After
public void closeSessionsAndDeleteUsers() throws Exception {
    if (user1Session != null) {
        ((CloseableCoreSession) user1Session).close();
    }
    if (user2Session != null) {
        ((CloseableCoreSession) user2Session).close();
    }
    try (Session usersDir = directoryService.open("userDirectory")) {
        usersDir.deleteEntry("user1");
        usersDir.deleteEntry("user2");
    }
    // Simulate root deletion to cleanup the cache between the tests
    nuxeoDriveManager.handleFolderDeletion((IdRef) doc("/").getRef());
}
Also used : CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) Session(org.nuxeo.ecm.directory.Session) CoreSession(org.nuxeo.ecm.core.api.CoreSession) After(org.junit.After)

Example 4 with Session

use of org.nuxeo.ecm.directory.Session in project nuxeo-drive-server by nuxeo.

the class TestPermissionHierarchyFileSystemChanges method createUser.

protected void createUser(String userName, String password) {
    try (Session userDir = directoryService.open("userDirectory")) {
        Map<String, Object> user = new HashMap<String, Object>();
        user.put("username", userName);
        user.put("password", password);
        userDir.createEntry(user);
    }
}
Also used : HashMap(java.util.HashMap) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) Session(org.nuxeo.ecm.directory.Session) CoreSession(org.nuxeo.ecm.core.api.CoreSession)

Aggregations

CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)4 CoreSession (org.nuxeo.ecm.core.api.CoreSession)4 Session (org.nuxeo.ecm.directory.Session)4 HashMap (java.util.HashMap)3 Before (org.junit.Before)2 ACE (org.nuxeo.ecm.core.api.security.ACE)2 After (org.junit.After)1 PathRef (org.nuxeo.ecm.core.api.PathRef)1