Search in sources :

Example 1 with DirectoryService

use of org.nuxeo.ecm.directory.api.DirectoryService 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

DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)1 DirectoryService (org.nuxeo.ecm.directory.api.DirectoryService)1 UserManager (org.nuxeo.ecm.platform.usermanager.UserManager)1