Changing a user's groups programatically

From OpenCms Wiki
Revision as of 17:28, 13 June 2007 by Pam (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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