You are not logged in.
Pages: 1
Dear all,
I would like to ask you how to add member into group via groovy.
Grateful if you could share the document or groovy to me, please.
Thank you
Regards,
David
Offline
There is a simple Script you can use... we need to put this into our example repository
... the formatting of the groovy GSTRING (this tripple-quoted string """ ) is a bit strange... it's \n (new line) separated... and doesn't like empty lines
import net.datenwerke.security.service.usermanager.UserManagerService;
import net.datenwerke.security.service.usermanager.entities.User;
import net.datenwerke.security.service.usermanager.UserPropertiesService;
import net.datenwerke.security.service.usermanager.entities.OrganisationalUnit;
import net.datenwerke.security.service.usermanager.entities.AbstractUserManagerNode;
import net.datenwerke.security.service.usermanager.entities.Group;
//import net.datenwerke.rs.terminal.service.terminal.TerminalService;
UserManagerService userManagerService = GLOBALS.getRsService(UserManagerService.class);
UserPropertiesService userPropertiesService = GLOBALS.getRsService(UserPropertiesService.class);
// FIRST. LAST. USER. EMAIL OU
def USER_CSV_STRING = """FIRSTNAME;LASTNAME;USERNAME;EMAIL;OU
FIRSTNAME2;LASTNAME2;USERNAME2;EMAIL2;OU"""
/* load service */
//def userService = GLOBALS.getInstance(UserManagerService.class);
//def terminal = GLOBALS.getInstance(TerminalService.class);
USER_CSV_STRING.split("\n").each{ u ->
def us = u.split(";")
/* create user */
def user = new User();
user.setUsername(us[2]);
user.setFirstname(us[0]);
user.setLastname(us[1]);
user.setEmail(us[3]);
/* Assigning apikey */
//userPropertiesService.setPropertyValue(user, "apikey", "xxxxxx");
/* Adding the Users to OU */
User users = userManagerService.getUserByName(user.getUsername());
List<OrganisationalUnit> ouList = userManagerService.getOUsByName(us[4]);
user.setParent(ouList[0])
/* persist user */
//userManagerService.persist(targetNode);
try{
userManagerService.persist(user);
}catch ( Exception ex ) {
tout.println("persisting $user failed: $ex")
}
}
return "added new user";
Softwareentwickler bei Infofabrik
Offline
Pages: 1