[opencms-dev] Adding a user to a group from a sub-OU

Thomas Adamek adamek at webtrio.de
Tue Apr 8 16:33:39 CEST 2008


Hello,

I would like to develop a registration form for a web site in OpenCms 7.0.4
which creates users in a organizational unit "Press". The user itself is
created sucessfully using the following lines:

====

CmsObject cms =
OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest());

HashMap userInfo = new HashMap();
userInfo.put("IS_PRESS_USER", "true");

CmsUser newUser = cms.createUser("/Press/" + username.trim(),
password.trim(), "Created in press area", userInfo);

cms.loginUser("<user_with_management_role>", "<my_password_for_admin>");

newUser.setEmail(email.trim());
newUser.setFirstname(firstname.trim());
newUser.setLastname(lastname.trim());
newUser.setAddress(address.trim());
newUser.setCity(city.trim());
newUser.setZipcode(zipcode.trim());
newUser.setCountry(country.trim());
newUser.setDescription("Created in press area");
newUser.setEnabled(false);
newUser.setManaged(true);

cms.writeUser(newUser);

====

The code works so far, the user is created in the OU "Press" until I try to
add it programmatically to the group "Pressuser" in the OU "Press":

====

cms.addUserToGroup(username.trim(), "/Press/Pressuser");

====

This line fails with  a CmsException and the message

====

org.opencms.db.CmsDbEntryNotFoundException: Error adding user
"<newusername>" to group "/Presseverteiler/Presse".

====

The group "Pressuser" exists in the OU "Press"

I tried different variants, group name without the OU prefix, with a
beginning slash, without but it does not work. I also tried to assign full
administrator rights to the <user_with_management_role>, without success.

Any idea?

Thank you!

Nice regards
Thomas Adamek




More information about the opencms-dev mailing list