Exception when creating a user programmatically from a service or servlet filter
--------------------------------------------------------------------------------
Key: GTNPORTAL-798
URL:
https://jira.jboss.org/jira/browse/GTNPORTAL-798
Project: GateIn Portal
Issue Type: Bug
Security Level: Public (Everyone can see)
Components: Identity integration
Affects Versions: 3.0.0-CR01
Reporter: Tugdual Grall
Assignee: Chris Laprun
I want to create a user programmatically inside GateIn portal.
I am using the following code:
-----
private void createUserInPortal(String login, String firstname, String lastName)
throws Exception {
OrganizationService orgService = (OrganizationService)
getContainer().getComponentInstanceOfType(OrganizationService.class);
User user = orgService.getUserHandler().findUserByName(login);
// if user doesn't exist, I create it
if (user == null) {
// User user = new User
User userToCreate = orgService.getUserHandler().createUserInstance(login);
userToCreate.setPassword("gtn");
userToCreate.setFirstName(firstname);
userToCreate.setLastName(lastName);
userToCreate.setEmail("email");
// broadcast:mettre à true pour permettre le lancement des listeners
orgService.getUserHandler().createUser(userToCreate, false);
}
}
Called from a REST service or a Filter.
When I execute this code I have the following exception:
---
INFO: Cannot obtain user: tgrall;
org.picketlink.idm.common.exception.IdentityException: IdentityObjectType[USER] not
present in the store.
at
org.picketlink.idm.impl.store.hibernate.HibernateIdentityStoreImpl.getHibernateIdentityObjectType(HibernateIdentityStoreImpl.java:2401)
at
org.picketlink.idm.impl.store.hibernate.HibernateIdentityStoreImpl.findIdentityObject(HibernateIdentityStoreImpl.java:599)
at
org.picketlink.idm.impl.repository.WrapperIdentityStoreRepository.findIdentityObject(WrapperIdentityStoreRepository.java:155)
at
org.picketlink.idm.impl.api.session.managers.PersistenceManagerImpl.findUser(PersistenceManagerImpl.java:332)
at
org.exoplatform.services.organization.idm.UserDAOImpl.getPopulatedUser(UserDAOImpl.java:493)
at
org.exoplatform.services.organization.idm.UserDAOImpl.findUserByName(UserDAOImpl.java:238)
at
com.exoplatform.poc.orange.security.service.UserService.createUserInPortal(UserService.java:45)
at
com.exoplatform.poc.orange.security.service.UserService.createUser(UserService.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at
org.exoplatform.services.rest.impl.method.DefaultMethodInvoker.invokeMethod(DefaultMethodInvoker.java:140)
at
org.exoplatform.services.rest.impl.RequestDispatcher.invokeSubResourceMethod(RequestDispatcher.java:302)
at
org.exoplatform.services.rest.impl.RequestDispatcher.dispatch(RequestDispatcher.java:244)
at
org.exoplatform.services.rest.impl.RequestDispatcher.dispatch(RequestDispatcher.java:147)
at
org.exoplatform.services.rest.impl.RequestHandlerImpl.handleRequest(RequestHandlerImpl.java:136)
at org.exoplatform.services.rest.servlet.RestServlet.onService(RestServlet.java:82)
at
org.exoplatform.container.web.AbstractHttpServlet.service(AbstractHttpServlet.java:116)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.exoplatform.services.rest.servlet.RestEncodingFilter.doFilter(RestEncodingFilter.java:58)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.exoplatform.frameworks.jcr.web.ThreadLocalSessionProviderInitializedFilter.doFilter(ThreadLocalSessionProviderInitializedFilter.java:116)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.exoplatform.services.security.web.SetCurrentIdentityFilter.doFilter(SetCurrentIdentityFilter.java:76)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:613)
Caused by: org.hibernate.HibernateException: createCriteria is not valid without active
transaction
at
org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:338)
at $Proxy86.createCriteria(Unknown Source)
at
org.picketlink.idm.impl.store.hibernate.HibernateIdentityStoreImpl.getHibernateIdentityObjectType(HibernateIdentityStoreImpl.java:2380)
... 41 more
Mar 4, 2010 12:23:47 AM com.exoplatform.poc.orange.security.service.UserService
createUser
SEVERE: null
org.hibernate.HibernateException: createCriteria is not valid without active transaction
at
org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:338)
at $Proxy86.createCriteria(Unknown Source)
at
org.picketlink.idm.impl.store.hibernate.HibernateIdentityStoreImpl.getRealm(HibernateIdentityStoreImpl.java:2595)
at
org.picketlink.idm.impl.store.hibernate.HibernateIdentityStoreImpl.createIdentityObject(HibernateIdentityStoreImpl.java:479)
at
org.picketlink.idm.impl.store.hibernate.HibernateIdentityStoreImpl.createIdentityObject(HibernateIdentityStoreImpl.java:461)
at
org.picketlink.idm.impl.repository.WrapperIdentityStoreRepository.createIdentityObject(WrapperIdentityStoreRepository.java:128)
at
org.picketlink.idm.impl.api.session.managers.PersistenceManagerImpl.createUser(PersistenceManagerImpl.java:126)
at
org.exoplatform.services.organization.idm.UserDAOImpl.createUser(UserDAOImpl.java:135)
at
com.exoplatform.poc.orange.security.service.UserService.createUserInPortal(UserService.java:56)
at
com.exoplatform.poc.orange.security.service.UserService.createUser(UserService.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at
org.exoplatform.services.rest.impl.method.DefaultMethodInvoker.invokeMethod(DefaultMethodInvoker.java:140)
at
org.exoplatform.services.rest.impl.RequestDispatcher.invokeSubResourceMethod(RequestDispatcher.java:302)
at
org.exoplatform.services.rest.impl.RequestDispatcher.dispatch(RequestDispatcher.java:244)
at
org.exoplatform.services.rest.impl.RequestDispatcher.dispatch(RequestDispatcher.java:147)
at
org.exoplatform.services.rest.impl.RequestHandlerImpl.handleRequest(RequestHandlerImpl.java:136)
at org.exoplatform.services.rest.servlet.RestServlet.onService(RestServlet.java:82)
at
org.exoplatform.container.web.AbstractHttpServlet.service(AbstractHttpServlet.java:116)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.exoplatform.services.rest.servlet.RestEncodingFilter.doFilter(RestEncodingFilter.java:58)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.exoplatform.frameworks.jcr.web.ThreadLocalSessionProviderInitializedFilter.doFilter(ThreadLocalSessionProviderInitializedFilter.java:116)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.exoplatform.services.security.web.SetCurrentIdentityFilter.doFilter(SetCurrentIdentityFilter.java:76)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:613)
^C2010-03-04 00:26:08,343 org.gatein.pc.mc.PortletApplicationDeployer : Going to uninstall
war file/exoadmin (PortletApplicationDeployer.java, line 190)
----
Note: the same code is working without any issue in eXo Portal 2.5.7
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira