Changing a user's groups programatically

From OpenCms Wiki
(Difference between revisions)
Jump to: navigation, search
(how to modify a user programatically)
 
m (formatting)
 
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
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.
+
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);
+
CmsObject cmsAdminObj = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest());
 +
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 18: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.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox