Logging in and creating user programmatically [message #1701159] |
Thu, 09 July 2015 11:05  |
Eclipse User |
|
|
|
Greetings,
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>();
properties.put(SecurityProperties.PARTITION, "default");
properties.put(SecurityProperties.DOMAIN, "default");
((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?
|
|
|
|
|
Re: Logging in and creating user programmatically [message #1701246 is a reply to message #1701238] |
Fri, 10 July 2015 04:35  |
Eclipse User |
|
|
|
OK, I figured it out. There's a SpringServiceFactory class which implements Spring's ApplicationContextAware interface. You have to define this class as the value of the Client.ServiceFactory property in the carnot.properties. When you call the ServiceFactoryLocator for a ServiceFactory it knows it needs to return a SpringServiceFactory based on this property, and this factory has access to the application context and your service beans defined in it since it's implementing the ApplicationContextAware interface.
|
|
|
Powered by
FUDForum. Page generated in 0.07943 seconds