Recover environment properties sent to EJB

215 Views Asked by At

I have a Delegate that instanciate the corresponding Bean sending credentials (Josso Authentication) through InitialContext as shown here.

At Bean, I've tried to recover Josso Data with SessionContext, as shown below:

@Resource private SessionContext context;

The problem I'm facing is that I couldn't retrieve Josso Data at Bean scope. I've tried "context.getEnvironment()" but this method is deprecated and I didn't find any alternative.

In order to find a solution, I've tried:

context.lookup(JNDI_BEAN_NAME);
context.lookup("java:comp/env/JNDI_BEAN_NAME")
context.lookup("java:comp/env")

But the two first commands only return me the Bean itself and the last one only return me global variables.

What is the correct alternative to "context.getEnvironment()"?

1

There are 1 best solutions below

1
damat-perdigannat On

java:comp/env finds container-managed resources only and is read-only at runtime. If you want, you can expose a local interface that gets Josso credentials from the delegate.

@Local
public interface AuthenticatorLocal {
    void getJossoCredentials();
}

Otherwise, you can just use context.getCallerPrincipal().