|Logging in and creating user programmatically [message #1701159]
||Thu, 09 July 2015 15:05
| Tam Gom
Registered: July 2011
I would like to embed Stardust into my Spring-based web application. I created the tables for Stardust in my database and I'm trying to create a new user through the UserService interface in code.
userService.createUser(request.getUsername(), null, null, null, request.getPassword(), null, null, null);
The above code results in an AccessForbiddenException with the following error code: AUTHx00101 - Not logged in.
The UserService interface doesn't have a login method but I looked up the UserServiceBean class and it has it. I logged into the default domain and partition with the default (motu) user with the code below:
Map<String, String> properties = new HashMap<String, String>();
((UserServiceBean) userService).login("motu", "motu", properties);
The login method returns a LoggedInUser object for the motu account. Now if after this I call the UserService.createUser(...) method I get the same error code what I described above. I also tried to call the UserService.startSession(...) method after login but that didn't work either.
What is the proper way to do this? Do I really have to authenticate myself in code to perform a user creation operation? Having to cast the interface to a concrete class doesn't seem right to me, the other option would be to cast it to ManagedService I guess but that doesn't feel right either. What am I missing here?
Powered by FUDForum
. Page generated in 0.02017 seconds