1

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()"?

gavioto
  • 1,695
  • 2
  • 17
  • 38
  • What do you think `context.getEnvironment()` used to return? It is an EJB 1.0 API that was deprecated in EJB 1.1. It was replaced with the `` elements in the ejb-jar.xml deployment descriptor – Steve C Feb 29 '16 at 13:45
  • You will not be able to recover "credentials", however you can get the authenticated identity of the user by injecting a security principal: `@Resource java.security.Principal principal` or via SessionContext.getCallerPrincipal(). – Steve C Feb 29 '16 at 13:54
  • My EJB configuration doesn't include ejb-jar.xml. About your suggestion, can I also recover password or jossoId via SessionContext? I need this to have a authenticated bean – André Luís Oliveira Feb 29 '16 at 14:14
  • I have a filter and at that time I have all this info (user, password, jossoid) and I've added these attributes at session. I need at least JossoId on my Bean. Any suggestion? – André Luís Oliveira Feb 29 '16 at 14:31
  • The security context will be propagated from your web app to your EJBs and other managed beans if you have integrated Josso correctly with your application server. – Steve C Mar 01 '16 at 12:28

1 Answers1

0

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().

damat-perdigannat
  • 5,780
  • 1
  • 17
  • 33
  • your idea guided me to an alternative solution, thanks for sharing. In fact, I had all the data I needed with a class of our fundation that gave me Josso Data. – André Luís Oliveira Mar 17 '16 at 14:29