我是 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);
}
%>
答案 0 :(得分:0)
有一个模块可以做到这一点,你试试吗?
opencms 8 http://www.alkacon.com/en/modules/downloads/oamp-webuser_2.0.0.html
opencms 7 http://www.alkacon.com/en/modules/downloads/oamp-webuser-0.9.0.html
答案 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);