[opencms-dev] Switch users and project programatically

Mario Jäger m.jaeger at alkacon.com
Fri Apr 1 09:18:21 CEST 2011

Hi Paul,

It is better to get an independent copy of the provided CmsObject with:

CmsObject copyCms = org.opencms.main.OpenCmsCore.initCmsObject(cms);

On this independent copy of the CmsObject you can login as the 
administrator user then and change the project. After modifying files in 
the Vfs no further actions are necessary, because you have not changed 
the current CmsObject then.

Kind Regards,

Am 30.03.2011 22:06, schrieb Paul-Inge Flakstad:
> Hi list,
> I need to modify some files in the VFS programatically in a JSP, so I do
> this:
> if (cms.getRequestContext().currentProject().isOnlineProject()) {
> cmso.loginUser("myadmin", "mypassword");
> cmso.getRequestContext().setCurrentProject(cmso.readProject("Offline"));
> }
> // Now I modify the files in the VFS
> My questions:
> 1.) Should I set the project to "Online" again, after I'm finished
> modifying the files?
> 2.) Do I also need to login the "Guest" user, to ensure regular guest
> users do not get the privileges assigned to "myadmin" user? (How do I do
> this?)
> 3.) Is the order of loginUser() and setCurrentProject() correct? (First
> login user and then set project?)
> Appreciate any help! :)
> Cheers,
> Paul
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/mailman/listinfo/opencms-dev

Mario Jäger

Visit OpenCms Days 2011 Conference and Expo
May 9 to May 10 2011 in Cologne, Germany

Alkacon Software GmbH  - The OpenCms Experts
http://www.alkacon.com - http://www.opencms.org

More information about the opencms-dev mailing list