Changing a user's groups programatically
From OpenCms Wiki
(Difference between revisions)
m (formatting) |
|||
Line 2: | Line 2: | ||
− | CmsObject cmsAdminObj = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest()); | + | CmsObject cmsAdminObj = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest()); |
− | cmsAdminObj.loginUser(webAdminUser,webAdminPassword); | + | cmsAdminObj.loginUser(webAdminUser,webAdminPassword); |
− | cmsAdminObj.removeUserFromGroup(user, oldGroup); | + | cmsAdminObj.removeUserFromGroup(user, oldGroup); |
− | cmsAdminObj.addUserToGroup(user, newGroup); | + | cmsAdminObj.addUserToGroup(user, newGroup); |
You don't have to logout the admin user, it will happen when the object is destroyed. | You don't have to logout the admin user, it will happen when the object is destroyed. |
Latest revision as of 17:28, 13 June 2007
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.