Synyx GmbH & Co. KG Homepage Welcome Guest   | Login
  Search  
  Index  | Recent Threads  | Who's Online  | User List  | Register  | Search  | Help  | RSS feeds
OpenCms 7.0.4 Live-CD available!

Synyx created an OpenCms 7.0.4 Live CD, based on SLAX Linux, which is now available.

If you want to order a free CD copy, please write, including your postal address, to



Quick Go »
Thread Status: Normal
Total posts in this thread: 7
[Add To My Favorites] [Watch this Thread] [Post new Thread]
Author
Previous Thread This topic has been viewed 144 times and has 6 replies Next Thread
Male frafra
Stranger



Joined: Jul 15, 2010
Posts: 14
Status: Offline

Add a new User to DB Reply to this Post
Reply with Quote

Hello.
The USER_ID into DB for guest, admin and export isn't an autoincrement but a code like this 46769c87-e4de-362c-8e3e-4f1d811c3267.

I want to generate this code for my users and I don't know how to do.

I search online and I found the method AddUser() in the classCmsDbAccess.

I Have a nullpointer exception.

Someone can help me? Can you write me how to do it? Another question is if I can user a simple USER_ID autoincrement Opencms can give me problem?

Sorry for my english.

my code:

CmsJspActionElement cms = new CmsJspActionElement(pageContext,request, response);
CmsRequestContext requestContext= cms.getRequestContext();
CmsDbContext dbContext= new CmsDbContext (requestContext);

String configPath = pageContext.getServletContext().getRealPath("/") + "WEB-INF/config/";
CmsConfigurationManager configurationManager = new CmsConfigurationManager(configPath);

Map conf = configurationManager.getConfiguration();
String dbName = conf.get(CmsDbPool.KEY_DATABASE_NAME).toString().toLowerCase();

CmsDbAccess dbAccess=new CmsDbAccess(configurationManager.getConfiguration());
[Jul 26, 2010 10:55:10 AM] Show Printable Version of Post        Hidden to Guest [Link] Report threatening or abusive post: please login first  Go to top 
Male frafra
Stranger



Joined: Jul 15, 2010
Posts: 14
Status: Offline

Re: Add a new User to DB Reply to this Post
Reply with Quote

sorry.
the last rows is a my mistake.

String poolUrl = conf.get("db.cos.pool").toString();
CmsDbAccess dbAccess=new CmsDbAccess(poolUrl);

can you help me? it's a nullpointer exception. ( for variable "conf")
[Jul 26, 2010 11:08:57 AM] Show Printable Version of Post        Hidden to Guest [Link] Report threatening or abusive post: please login first  Go to top 
Male Flo
Advanced Member
Member's Avatar


Joined: May 7, 2004
Posts: 456
Status: Offline
Re: Add a new User to DB Reply to this Post
Reply with Quote

Hi,

you shouldn't add content to the databases of OpenCms manually.

Always use the methods provided in CmsObject, in this case createUser().

Nevertheless, the ids are created by the clas CmsUUID but normally you don't need this.

Regards
Florian
----------------------------------------
/**
* Florian Hopf
* Synyx GmbH & Co. KG
*/
[Jul 26, 2010 11:17:50 AM] Show Printable Version of Post        http://www.synyx.de [Link] Report threatening or abusive post: please login first  Go to top 
Male frafra
Stranger



Joined: Jul 15, 2010
Posts: 14
Status: Offline

Re: Add a new User to DB Reply to this Post
Reply with Quote

thank you flo.
Can you help me with code?
I don't found any axamples online
[Jul 26, 2010 11:51:57 AM] Show Printable Version of Post        Hidden to Guest [Link] Report threatening or abusive post: please login first  Go to top 
Male frafra
Stranger



Joined: Jul 15, 2010
Posts: 14
Status: Offline

Re: Add a new User to DB Reply to this Post
Reply with Quote

I have written this code for create user:

CmsDefaultUsers defaultUsers = new CmsDefaultUsers();
CmsObject obj = OpenCms.initCmsObject(defaultUsers.getUserGuest());
String userFqn = "test";
String password = "789456123";
String description = "hello hello";

String configPath = pageContext.getServletContext().getRealPath("/") + "WEB-INF/config/";
CmsConfigurationManager configurationManager = new CmsConfigurationManager(configPath);

//Map conf = configurationManager.getConfiguration();

Map additionalInfos= configurationManager.getConfiguration();
obj.createUser(userFqn,password,description ,additionalInfos);

btu i have this response:

Error org.opencms.security.CmsRoleViolationException: Error adding the user "farfarfarafafar".
Reason: Error adding the user "test".
Reason: The user "Guest" does not have access to the required "Account manager" role for organizational unit "".
[Jul 26, 2010 12:42:49 PM] Show Printable Version of Post        Hidden to Guest [Link] Report threatening or abusive post: please login first  Go to top 
Male frafra
Stranger



Joined: Jul 15, 2010
Posts: 14
Status: Offline

Re: Add a new User to DB Reply to this Post
Reply with Quote

maybe I didin't undestand.

The code USER_ID with OU is only for user that has a role in opencms?
I can insert a normal user into db manually? With a normal Sql code (INSERT INTO.......)??

can you explain me it?

regards
thank you.
Fra
[Jul 26, 2010 12:57:42 PM] Show Printable Version of Post        Hidden to Guest [Link] Report threatening or abusive post: please login first  Go to top 
Male frafra
Stranger



Joined: Jul 15, 2010
Posts: 14
Status: Offline

Re: Add a new User to DB Reply to this Post
Reply with Quote

I resolve it!

this is my code

CmsJspActionElement cms = new CmsJspActionElement(pageContext,request, response);

CmsDefaultUsers defaultUsers = new CmsDefaultUsers();
CmsObject obj = OpenCms.initCmsObject(defaultUsers.getUserGuest());
String username = "frafra";
String password = "xxxxxxx";
String description = "Mr.frafra number one";
String group = "Guests";
CmsUser user = obj.addWebUser(username, password, group, "Web User", new Hashtable() );
obj.writeWebUser(user);
[Jul 26, 2010 3:12:06 PM] Show Printable Version of Post        Hidden to Guest [Link] Report threatening or abusive post: please login first  Go to top 
[Show Printable Version of Thread] [Post new Thread]