Assume I have an EJB defining two views:
- Local business,
- Remote business.
Both interfaces share the same method signatures, so it's like:
public interface MyBusinessCommon {
void myMethod(Object o);
}
@Local
public interface MyBusinessLocal extends MyBusinessCommon { }
@Remote
public interface MyBusinessRemote extends MyBusinessCommon { }
@Stateless
public class MyBusinessBean implements MyBusinessLocal, MyBusinessRemote {
public void myMethod(Object o) {
// ...
}
}
Is there a way to figure out what EJB view was called from within the EJB itself (or its interceptor?)
Let's say I would like to perform different authorization procedures depending on used view. Remote should be more constrained and local shouldn't.
I can invoke SessionContext#getInvokedBusinessInterface()
but this gives me information only about the class object - not about EJB semantics of it. Plainly using reflection to check annotations presence on interfaces or bean is not enough (what about views defined in ejb-jar.xml
?)
I doubt it is possible using straight EJB specification but perhaps there's something I missed.
If not, is it possible to get this information from the inners of an application server? (let's consider only JBoss AS 7.x, Glassfish 3.x and TomEE 1.5.1).
MyBusinessLocal
ends withLocal
etc. A bit brittle, but conventions do work for e.g. JavaBeans. – Harter