[opencms-dev] Login as Admin and "login back" as the previous user

De Gea García, Alfonso adegea at chs.mma.es
Tue Jan 22 10:23:57 CET 2008


Hello Célio.

 

Have you take a look at the method?

 

CmsRequestContext.switchUser (CmsUser user, CmsProject project, java.lang.String ofFqn)

"Switches the user in the context, required after a login"

 

Maybe this is what you are looking for.

 

Kind regards.

 

  _____  

De: karl adenener [mailto:adenener at hotmail.com] 
Enviado el: martes, 15 de enero de 2008 16:22
Para: The OpenCms mailing list
Asunto: Re: [opencms-dev] Login as Admin and "login back" as the previous user

 

Dear Célio.

I was searching long time for an good solution of this problem, I found only a bad workaround.

My solution
- normal login with cmso.loginUser ("name", password) and - do something ...

- CmsObject cmsoa = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest());
      and login as an admin => cmsoa.loginUser("Admin", password); 
- get the context =>getRequestContext().setSiteRoot(OpenCms.getSiteManager().getDefaultSite().getSiteRoot());
- get the right project
=>getRequestContext().setCurrentProject(cmsoa.readProject("Offline"));

- do something with admin rights

- login (or logout) as an guest, cmsoa.loginUser("Guest", password); and do not use this cmsoa-Object anymore.

- now you have only the original rights.

I am also interested in an more "nice" solution. I hope this is, what do you was looking for.


greetings
Aden

  _____  

Date: Mon, 14 Jan 2008 23:48:39 -0300
From: celiofariajr at gmail.com
To: opencms-dev at opencms.org
Subject: [opencms-dev] Login as Admin and "login back" as the previous user

Hi all,

I am trying to programatically create a scheduled job and write some "acceptance" files (for the users to agree with the site Terms of Use). In order to do that, I have to login as Admin, because common users 1 - do not have the permission to schedule jobs and 2- cannot create files into the "acceptance" files directory (which is located inside my module). 

The problem is, when I logout the Admin after do the writing and/or scheduling, the session is lost and the OpenCms current user is now "Guest" (or at least I think so). 

I was wondering if there is an elegant way to log as Admin, do some tasks and "login back" as the previous user... 

Another solution would be giving the users permission to schedule jobs, but the role that allows this also gives them other permissions I don´t want them to have.

Someone having the same problem? Any clues on other solutions? 

TIA,

Célio.

 

  _____  

Kostenlos bloggen + eigene Homepage + Fotospeicher = MSN Spaces Hier klicken!  <http://clk.atdmt.com/GBL/go/mcrsddsp0020000048gbl/direct/01/> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20080122/a0694bae/attachment.htm>


More information about the opencms-dev mailing list