views:

174

answers:

2

Hello,

I have an existing application written in SEAM that uses SEAM Security (http://docs.jboss.org/seam/2.1.1.GA/reference/en-US/html/security.html). In a stateless EJB, I might find something like this:

@In
Identity identity;

... 

if(identity.hasRole("admin"))
  throw new AuthException();

As far as I understand, Seam injects the Identity object from the SessionContext of the servlet that invokes the EJB (this happens "behind the scenes", since Seam doesn't really use servlets) and removes it after the call. Is this correct?

Is it now possible to access this EJB from another servlet (in this case, that servlet is the server side of a GWT application)? Do I have to "inject" the correct Identity instance? If I don't do anything, Seam injects an instance, but doesn't correctly correlate the sessions and instances of Identity (so the instances of Identity are shared between sessions and sometimes calls get new instances etc.).

Any help and pointers are very welcome - thanks!

Technology: EJB3, Seam 2.1.2. The servlets are actually the server-side of a GWT app, although I don't think this matters much. I'm using JBoss 5.

A: 

Your question is incredibly hard to follow and I'm not sure I understood everything. Anyway, I'll assume you are using Stateless Session Beans (since you said I could use stateful beans) which, by definition, are stateless. So how can Mary get authenticated as Joe after a call to a stateless session bean? This can't be, it doesn't make any sense.

PS: You should maybe rephrase your question and try to clearly distinguish concepts such as the HTTP Session, Session Beans (stateless, stateful?), SessionContext.

Pascal Thivent
Hello Pascal, thx - tried to simplify the question. Yes, SLSBs are used (I hinted that in the first sentence). I guess the state is managed by Seam in the session context and injected and outjected of the SLSBs when they are called. Wrong? If I have misused any concepts, please let me know :-)
wilth
+2  A: 

Seam injects the Identity object from the SessionContext of the servlet that invokes the EJB and removes it after the call. Is this correct ?

Yes, but do not forget you must enable EJB Seam interceptor See here how to

...

Is it now possible to access ANY EJB from another servlet

Yes, you can use its Global JNDI (Vendor dependent) to retrieve it. See here how you can set up and retrieve your EJB @State less / ful bean. If you have a fully-supported JEE app server, You can retrieve it through annotations.

Do I have to "inject" the correct Identity instance ?

You do not have to worry about it. Seam EJB interceptor Takes care of it. Go ahead.

UPDATE

but in the EJB, two different instances of Identity are injected. I'm guessing the Session context that Seam is using is not correctly linked to the Session context of the servlet ? Any ideas ?

Well, Identity component itself does not implement equals method which, by default, uses default equals implementation by using equals comparison (==). I do not know whether, for each EJB call, you have always a fresh Identity component (Maybe it explains why you have "Two different instances")

If your Servlet's share The same context, you can enable IdentityFilter as a way to wrap your Identity assigned role by using isUserInRole method. Here goes its funcionality:

A filter that provides integration between Servlet Security and the Seam identity component. This integration is accomplished by wrapping the HttpServletRequest with an HttpServletRequestWrapper implementation that delegates security-related calls to the Seam identity component.

If use use @Identity component, it is enabled by default

So instead of inject your EJB (And its @In-jected @Identity) and use

identity.hasRole("admin");

You can use

request.hasUserInRole("admin");

And maybe you want to see Setting and reading the Conversation ID And Seam and GWT

More

The ContextFilter (not enabled by default) opens access to the Seam container and its context variables to non-JSF servlets, such as Struts, Spring MVC, and Direct Web Remoting (DWR). I do not know how to use this kind of funcionality.

Arthur Ronald F D Garcia
thx for your reply - EJB Seam Interceptor is configured and I'm using JNDI to retrieve an instance.It works so far, but I'm facing problems. Example: A logins in (call goes to the servlet, to the EJB, Identity instance is injected and used for authentication). Then the user calls two services in rapid succession. In the servlets, both calls end up in the same session (I checked using the SessionID), but in the EJB, two different instances of Identity are injected. I'm guessing the Session context that Seam is using is not correctly linked to the Session context of the servlet? Any ideas?
wilth
@wilth See **UPDATE**
Arthur Ronald F D Garcia