Is it possible to access a stateful session bean inside a stateless bean?
My problem is that I have a session bean called User and I want to access user info inside a stateless bean...
I am trying like this:
Ejb Side:
@Stateless
public class OfferManagerBean implements OfferManagerLocal, OfferManager
{
@Resource
private SessionContext context;
@EJB
private ro.project.ejb.interfaces.User user;
public String getUsername()
{
user = (ro.project.ejb.interfaces.User) context.lookup("java:global/project/projectEJB/User!ro.project.ejb.interfaces.User");
return user.getUsername();
}
Client side
User user = (User) ctx.lookup("java:global/project/projectEJB/User!ro.project.ejb.interfaces.User");
user.setUsername("Alex");
OfferManager offerManager = (OfferManager) ctx.lookup("java:global/project/projectEJB/OfferManagerBean!ro.project.ejb.interfaces.OfferManager");
assertEquals(offerManager.getUsername(), "Alex");
The result of this test case is java.lang.AssertionError: expected:<null> but was:<Alex>
it fails.. It seems that how I am requesting the stateful bean is returning me a new instance...
- I know why this is not working. Because my test fails :P. I get a new instance..
- I want to check certain permissions of the logged in user in EJB because I don't want to count on the client side because I might do a mistake there or I will tell other developers to make a GUI for my project..
- I don't want to use Java EE Security beucause I don't know how to make the login in a RCP Application
- My main question is: How do I access a session bean (the same one the client own) inside an EJB.. is it possible? And how?
I am asking almost the same thing this guy is asking: Concept for reusable login session in rmi ejb calls
I want to do that but not with JAAS...
Thank you in advance
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…