Our application consists of web pages that interact with backing beans and Stateless EJB services, but there is also a remote client that interacts with the Stateless EJB services.
Many of the services query the DB and then filter the result set based on the current user/caller (for example, users have permission to view only some record types); that is, they use programmatic rather than declarative security.
On the web side, my intuition would be to store the currently logged-in user in a SessionBean, but I want the Stateless EJB services to filter the result set based on the currently logged-in user so that the filtering also applies during remote client calls. I can inject a SessionBean into a Stateless EJB service, but I think SessionBeans use HTTP sessions, and as there is no HTTP session during a remote client call, I don't see how that could work.
I sense that my approach is wrong, and that I should be retrieving the "Principal" from the container; however, due to our application's development lifecycle, container-managed security is not set-up yet, but I am still tasked to implement the business logic responsible for filtering records now rather than later.
My closely-related questions:
- Can a SessionScoped bean be injected into a Stateless EJB knowing that the Statelesss EJB will be invoked by remote clients? What is the value of the SessionScoped bean in that case?
- Instead of a SessionScoped bean, should my backing beans and Stateless EJB services be retrieving the Principal from the container?
- If yes, how can I substitute a mock Principal to work on the business logic until container-managed security is set-up?
p.s. I am new to Java EE.
Technology:
- Java EE 6
- GlassFish 3.1.2.2
- "Backing bean" e.g.
javax.enterprise.context.SessionScoped
- "Stateless EJB services", e.g.
javax.ejb.Stateless
- "remote client"; i.e. some non-web clients invoking the Stateless beans directly (through EJB/RMI)
Update:
More detail on the "remote client". I'm not sure how to word this because I'm new to Java EE, but this "remote client" will not be over HTTP. Another application, let's call it application X, will receive XML messages from clients. I think they authenticate the client using certificates. Application X will transform the XML into POJOs and call my Stateless EJB services directly.
In this case, I think I'm right to say that I should not inject a SessionBean
into a Stateless
EJB service because there will be no HTTP session when the EJB service is called by Application X. Is my understanding correct?
Thank you for your patience. I am aware of my ignorance in these matters.