Changing a user's groups programatically

From OpenCms Wiki
Jump to: navigation, search

There are times when you might want to modify a given user, when that user is NOT logged in. You need admin access to do this, however you don't want to give the current user (or guest user) admin priviledges. You can do this by creating a new CmsObject as guest and then logging it in as admin. The current user will not get admin priviledges, only the new CmsObject will.


CmsObject cmsAdminObj = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest());
cmsAdminObj.loginUser(webAdminUser,webAdminPassword);
cmsAdminObj.removeUserFromGroup(user, oldGroup);
cmsAdminObj.addUserToGroup(user, newGroup);

You don't have to logout the admin user, it will happen when the object is destroyed.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox