1

The context is the following :

An client application uses a stateless session bean in order to login on an EJB server application. If the login is successful, the client should get a stateful session bean in order to perform some transactions on his personal data. However, I would want that the login method returns a new instance of this stateful session bean such that a client should not be able to manually call this session bean and perform transactions without being authenticated. Is it possible ?

In my stateless bean I have the following code :

@Resource 
private SessionContext context;
...

public StatefulBeanRemote login(username, password) {
  if (ok) {
    StatefulBeanRemote bean = (StatefulBeanRemote) context.lookup("StatefulBeanRemote");
    return bean; 
  }

The lookup always fail. I don't know what I am doing wrong...

Emanuel
  • 155
  • 2
  • 11

1 Answers1

0

The lookup you're performing is the same as:

new InitialContext().lookup("java:comp/env/StatefulBeanRemote");

Have you defined an EJB reference to StatefulBeanRemote? Perhaps that is all you need:

@EJB(name="StatefulBeanRemote", beanInterface=StatefulBeanRemote.class)
public class MyClass {
    @Resource
    private SessionContext context;
    ...
}
Brett Kail
  • 33,593
  • 2
  • 85
  • 90