Search in sources :

Example 1 with UserManager

use of org.nuxeo.ecm.platform.usermanager.UserManager in project nuxeo-drive-server by nuxeo.

the class TestFileSystemItemOperations method createUser.

protected NuxeoPrincipal createUser(String userName, String password, String firstName, String lastName) {
    try (org.nuxeo.ecm.directory.Session userDir = directoryService.open("userDirectory")) {
        Map<String, Object> user = new HashMap<String, Object>();
        user.put("username", userName);
        user.put("password", password);
        user.put("firstName", firstName);
        user.put("lastName", lastName);
        userDir.createEntry(user);
    }
    // commit directory changes
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    UserManager userManager = Framework.getService(UserManager.class);
    return userManager.getPrincipal(userName);
}
Also used : HashMap(java.util.HashMap) UserManager(org.nuxeo.ecm.platform.usermanager.UserManager)

Example 2 with UserManager

use of org.nuxeo.ecm.platform.usermanager.UserManager in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveIntegrationTestsHelper method cleanUp.

public static void cleanUp(CoreSession session) {
    // Delete test users and their personal workspace if exist
    UserManager userManager = Framework.getService(UserManager.class);
    DocumentModelList testUsers = userManager.searchUsers(TEST_USER_NAME_PREFIX);
    for (DocumentModel testUser : testUsers) {
        String testUserName = (String) testUser.getPropertyValue(userManager.getUserSchemaName() + ":" + userManager.getUserIdField());
        if (userManager.getPrincipal(testUserName) != null) {
            userManager.deleteUser(testUserName);
        }
        String testUserWorkspaceName = IdUtils.generateId(testUserName, "-", false, 30);
        String testUserWorkspacePath = getDefaultDomainPath(session) + "/" + USER_WORKSPACE_PARENT_NAME + "/" + testUserWorkspaceName;
        DocumentRef testUserWorkspaceRef = new PathRef(testUserWorkspacePath);
        if (session.exists(testUserWorkspaceRef)) {
            session.removeDocument(testUserWorkspaceRef);
            session.save();
        }
    }
    // Delete test workspace if exists
    String testWorkspacePath = getDefaultDomainPath(session) + "/" + TEST_WORKSPACE_PARENT_NAME + "/" + TEST_WORKSPACE_NAME;
    DocumentRef testWorkspaceDocRef = new PathRef(testWorkspacePath);
    if (session.exists(testWorkspaceDocRef)) {
        session.removeDocument(testWorkspaceDocRef);
        session.save();
    }
    // Invalidate user profile cache
    Framework.getService(UserProfileService.class).clearCache();
}
Also used : DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) PathRef(org.nuxeo.ecm.core.api.PathRef) UserManager(org.nuxeo.ecm.platform.usermanager.UserManager) UserProfileService(org.nuxeo.ecm.user.center.profile.UserProfileService) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 3 with UserManager

use of org.nuxeo.ecm.platform.usermanager.UserManager in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveSetupIntegrationTests method createTestUsers.

protected String createTestUsers(String[] testUserNames) {
    StringBuilder testUserCredentials = new StringBuilder();
    UserManager userManager = Framework.getService(UserManager.class);
    DirectoryService directoryService = Framework.getService(DirectoryService.class);
    String userSchemaName = userManager.getUserSchemaName();
    String userNameField = directoryService.getDirectoryIdField(userManager.getUserDirectoryName());
    String passwordField = directoryService.getDirectoryPasswordField(userManager.getUserDirectoryName());
    for (int i = 0; i < testUserNames.length; i++) {
        String testUserName = testUserNames[i];
        // Generate random password
        String testUserPassword = UUID.randomUUID().toString().substring(0, 6);
        // Create test user
        DocumentModel testUserModel = userManager.getBareUserModel();
        testUserModel.setProperty(userSchemaName, userNameField, testUserName);
        testUserModel.setProperty(userSchemaName, passwordField, testUserPassword);
        if (useMembersGroup) {
            testUserModel.setProperty(userSchemaName, "groups", new String[] { "members" });
        }
        userManager.createUser(testUserModel);
        // Append test user's credentials
        testUserCredentials.append(testUserName);
        testUserCredentials.append(":");
        testUserCredentials.append(testUserPassword);
        if (i < testUserNames.length - 1) {
            testUserCredentials.append(",");
        }
    }
    return testUserCredentials.toString();
}
Also used : UserManager(org.nuxeo.ecm.platform.usermanager.UserManager) DirectoryService(org.nuxeo.ecm.directory.api.DirectoryService) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Aggregations

UserManager (org.nuxeo.ecm.platform.usermanager.UserManager)3 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)2 HashMap (java.util.HashMap)1 DocumentModelList (org.nuxeo.ecm.core.api.DocumentModelList)1 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)1 PathRef (org.nuxeo.ecm.core.api.PathRef)1 DirectoryService (org.nuxeo.ecm.directory.api.DirectoryService)1 UserProfileService (org.nuxeo.ecm.user.center.profile.UserProfileService)1