}
private void createUsers(OrganizationService service) throws Exception {
printInfo(" Init User Data");
List<?> users = config_.getUser();
MembershipHandler mhandler = service.getMembershipHandler();
for (int i = 0; i < users.size(); i++) {
OrganizationConfig.User data = (OrganizationConfig.User) users.get(i);
User user = service.getUserHandler().createUserInstance(data.getUserName());
user.setPassword(data.getPassword());
user.setFirstName(data.getFirstName());
user.setLastName(data.getLastName());
user.setEmail(data.getEmail());
user.setDisplayName(data.getDisplayName());
// Check root user and JCR flag
if ("root".equals(user.getUserName()) && !PortalSetupService.isSetup()) {
user.setPassword(PortalSetupService.rootPassword());
}
if (service.getUserHandler().findUserByName(data.getUserName()) == null) {
service.getUserHandler().createUser(user, true);
printInfo(" Created user " + data.getUserName());
} else {
printInfo(" User " + data.getUserName() + " already exists, ignoring the entry");
}
String groups = data.getGroups();
String[] entry = groups.split(",");
for (int j = 0; j < entry.length; j++) {
String[] temp = entry[j].trim().split(":");
String membership = temp[0];
String groupId = temp[1];
if (mhandler.findMembershipByUserGroupAndType(data.getUserName(), groupId, membership) == null) {
Group group = service.getGroupHandler().findGroupById(groupId);
MembershipType mt = service.getMembershipTypeHandler().createMembershipTypeInstance();
mt.setName(membership);
mhandler.linkMembership(user, group, mt, true);
printInfo(" Created membership " + data.getUserName() + ", " + groupId + ", " + membership);
} else {
printInfo(" Ignored membership " + data.getUserName() + ", " + groupId + ", " + membership);
}
}