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);
}
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();
}
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();
}
Aggregations