OpenCms中的用户注册

时间:2014-06-22 18:01:21

标签: jsp servlets opencms

我是 OpenCms 的新手,我想用java源创建一个新用户。我写了下面的代码,但它不起作用。制作新用户的正确程序是什么。

"输出错误":

  

Admin org.opencms.security.CmsSecurityException:添加用户时出错   "约翰"

源代码


<%@ page session="true" import="org.opencms.main.*, org.opencms.jsp.*,org.opencms.file.*, java.lang.String " %>
<%

    CmsJspActionElement cms = new CmsJspActionElement(pageContext,request,response);
    CmsObject cmsObject = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest());
//  CmsObject cmsObject = cms.getCmsObject();
    cmsObject.loginUser("Admin", "admin");

    session = request.getSession(false);
    if(session!=null){
        session.invalidate();
    }
    session = request.getSession(true);

    cmsObject.getRequestContext().setCurrentProject(cmsObject.readProject("Offline"));
    cmsObject.getRequestContext().setSiteRoot("/sites/default/");

    try{
        out.print("<br/>"+cmsObject.getRequestContext().getCurrentUser().getName());
        CmsUser user = cmsObject.createUser("John","123","Programmical Instructions", null);
    }catch(Exception ex){
        out.print("<br/>"+ex);
    }
%>

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

'CmsObject'类中CreateUser方法中有4个参数:

CmsUser createUser(String name, String password, String description, Map<String, Object> additionalInfos);

密码至少4个字符。这是OpenCms系统所必需的。您应该更改密码:1234

CmsUser user = cmsObject.createUser("John","1234","Programmical Instructions", null);