1 Reply Latest reply on Jul 1, 2009 11:51 AM by Juan Ignacio Sánchez Lara

    web:authentication-filter closes (Hibernate) Session

    Juan Ignacio Sánchez Lara Apprentice

      I'm trying to secure a web service with basic auth.
      My (working) service is mapped at web.xml this way:
      <servlet>
          <servlet-name>Web Service</servlet-name>
          <servlet-class>org.home.project.webservice.MyWebServiceFacadeImpl</servlet-class>
      </servlet>

      <servlet-mapping>
          <servlet-name>Web Service</servlet-name>
          <url-pattern>/myws</url-pattern>
      </servlet-mapping>

      In order to add http basic authentication I added the following filter at components.xml:
      <web:authentication-filter url-pattern="/myws" auth-type="basic" />
      I'm testing it with soapUI and if I don't enter user and pass it will throw an authorization error code, so it's working. In fact, my server uses my authenticator in order to retrieve current user, so it's ok.


      The problem comes later: the web service queries the database, but when it tries to do the query it throws the following exception:



      11:04:10,307 ERROR [SOAPFaultHelperJAXWS] SOAP request exception
      org.hibernate.SessionException: Session is closed!
           at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:49)
           at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1621)
           at org.jboss.seam.persistence.HibernateSessionProxy.createQuery(HibernateSessionProxy.java:140)
           at org.jboss.seam.framework.HibernateEntityQuery.createQuery(HibernateEntityQuery.java:141)
           at org.jboss.seam.framework.HibernateEntityQuery.initResultList(HibernateEntityQuery.java:53)
           at org.jboss.seam.framework.HibernateEntityQuery.getResultList(HibernateEntityQuery.java:45)
           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:585)
           at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
           at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
           at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:95)
           at org.jboss.seam.util.Work.workInTransaction(Work.java:47)
           at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:89)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
           at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
           at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
           at org.home.project.session.DataList_$$_javassist_4.getResultList(DataList_$$_javassist_4.java)
           at org.home.project.webservice.webservice.MyWebServiceFacadeImpl.retrieveData(MyWebServiceFacadeImpl.java:50)


      As you see, session is closed. If you put a breakpoint at SessionImpl.close and you can see it's called after authentication, before the query, so it's obvious it will fail. How can I tell Seam not to close the session?


      My web service is implemented as chapter 24 suggests: a @Stateless @WebService which obtains Seam component with Component.getInstance.


      Thanks in advance,