0

I want to get my current loggin User in my EJB Container. I built an CDI - EJB Webapplication with Shiro for Security.

My problem is now, in my EJB Class the sessionContext is everytime "anonymous"

@Resource
private SessionContext sessionContext;

String userEmail = sessionContext.getCallerPrincipal().getName();

I don´t know, set Shiro this automaticly or should I set sessionContext? Can anybody help me?

The problem is the connection from CDI ---> EJB or why is it "anonymous"

internet
  • 385
  • 1
  • 8
  • 27

1 Answers1

0

@Resource is not context-aware. You want to use @Inject instead.

Sym-Sym
  • 3,578
  • 1
  • 29
  • 30
  • @Inject does not work (in my glassfish4 instance). Getting `[glassfish 4.0] [SEVERE] [] [javax.enterprise.system.core] [tid: _ThreadID=57 _ThreadName=admin-listener(4)] [timeMillis: 1399386171108] [levelValue: 1000] [[ Exception while loading the app : CDI deployment failure:WELD-001408 Unsatisfied dependencies for type [SessionContext] with qualifiers [@Default] at injection point [[BackedAnnotatedField] @Inject private de.gfz.rz.idm.services.intern.impl.AccountServiceIntranetBean.sessionContext]` – Robert Kornmesser May 07 '14 at 07:15
  • Is your project EE6 or EE7? – Sym-Sym May 12 '14 at 14:32
  • EE7 - currently running on the newest promotion build of GF 4.0.1 (build 5) – Robert Kornmesser May 19 '14 at 13:02