[opencms-dev] Error deleting User

Antoni Bertran tunyafix at gmail.com
Wed May 2 16:46:45 CEST 2012


Hi I solved! the problem was that the userObject is onLine then I have to
change it

public static String deleteUser(CmsObject cmso, String[] users){

 try {
 CmsObject userObject = OpenCms.initCmsObject(cmso);
 LOG.info("Log user as Admin to delete users");
 userObject.loginUser(Dictionary.USER_ADMIN,Dictionary.PASSWORD_ADMIN);

*if ( userObject.getRequestContext().currentProject().isOnlineProject() ){*

*userObject.getRequestContext().setCurrentProject( userObject.readProject(
"Offline") );*

*    isOnline = true;*

*}*

  for(String user:users){
 userObject.deleteUser(user);
 }
 return Dictionary.DELETE_OK;
 } catch (CmsException e) {
 e.printStackTrace();
 return Dictionary.DELETE_KO;
 }

}

Regards, Antoni

2012/4/19 Antoni Bertran <tunyafix at gmail.com>

> Hi I developed a module to manage users using OpenCMS Users, everything
> works fine but deleting user it does not work in 7.5.1 (we developed in
> 7.5.3 and works but production enviroment has 7.5.1
>
>
> I get the error
>
> org.opencms.file.CmsVfsException: Error al eliminar al usuario "
> xxxx at email.com".
>         at
> org.opencms.file.CmsVfsException.createException(CmsVfsException.java:80)
>
>         at
> org.opencms.db.CmsDbContext.throwException(CmsDbContext.java:238)
>         at org.opencms.db.CmsDbContext.report(CmsDbContext.java:212)
>
>         at
> org.opencms.db.CmsSecurityManager.deleteUser(CmsSecurityManager.java:5600)
>         at
> org.opencms.db.CmsSecurityManager.deleteUser(CmsSecurityManager.java:1503)
>         at org.opencms.file.CmsObject.deleteUser(CmsObject.java:1058)
>         at
> com.tresipunt.test.register.AdminAction.deleteUser(AdminAction.java:109)
>         at
> com.tresipunt.test.register.AdminAction.processAction(AdminAction.java:96)
>         at
> org.apache.jsp.WEB_002dINF.jsp.offline.system.modules.com_tresipunt_test.elements.administrator.userList_jsp._jspService(userList_jsp.java:137)
>
>         at
> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>         at
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
>
>     at org.opencms.db.CmsDbContext.throwException(CmsDbContext.java:238)
>         at org.opencms.db.CmsDbContext.report(CmsDbContext.java:212)
>
>         at
> org.opencms.db.CmsSecurityManager.deleteUser(CmsSecurityManager.java:5600)
>         at
> org.opencms.db.CmsSecurityManager.deleteUser(CmsSecurityManager.java:1503)รง
>
>
>
> public static String deleteUser(CmsObject cmso, String[] users){
>
> try {
>  CmsObject userObject = OpenCms.initCmsObject(cmso);
>  LOG.info("Log user as Admin to delete users");
>  userObject.loginUser(Dictionary.USER_ADMIN,Dictionary.PASSWORD_ADMIN);
>  for(String user:users){
>  userObject.deleteUser(user);
>  }
>  return Dictionary.DELETE_OK;
>  } catch (CmsException e) {
>  e.printStackTrace();
>  return Dictionary.DELETE_KO;
>  }
>
> }
>
> Before call our deleteUser we do:
>
> if (cms.getRequestContext().currentProject().isOnlineProject()) {
>             cmso.loginUser("myadmin", "mypassword");
>
> cmso.getRequestContext().setCurrentProject(cmso.readProject("Offline"));
>         }
>
> Thanks in advance!!!!
>
> Regards!
> Antoni
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20120502/f9756cdd/attachment.htm>


More information about the opencms-dev mailing list