I'm trying to log all EJB method authorization calls, but am having some difficulty configuring my aspect to be called. I've created my pointcut as generically as possible to advise my EJBs directly, but I'm not having success.
Primarily, I need to log any failed authorizations.
My application server is JBoss 4.2.1GA, but it's own authorization aspect/interceptor seems to be taking precedence over my own pointcut. I am not entirely sure why as I have set my pointcut to call()
instead of execute()
, expecting that my advice would be executed before anything else, but that does not seem to work.
I'm using LTW with AspectJ 1.6.
This is my aspect definition:
@Pointcut("call( @(javax.annotation.security..*) * *.*(..))")
public void securedEJB(){}
@Around( "securedEJB()" )
public Object logEJBAccess( ProceedingJoinPoint pjp ) throws Throwable{
logger.warn("EJB CHECK HERE!!!!!!!!!!!");
Object o = null;
try {
o = pjp.proceed();
} catch (Throwable e) {
logger.error("EJB Threw Exception " + e );
e.printStackTrace();
throw e;
}
return o;
}
Yet, for all my secured EJB methods, I get the JBoss aspect that is checking for security rights prior to my own calls to method and hence this advice is never ever run.
An example of a call is:
OrganizationManager om = (OrganizationManager)SessionBeanLocator.getSessionBean(OrganizationManager.class);
om.getThirdPartyOrgsForLogin( "asdf", null );
System.out.println( "OM" + om );
Where OM is the interface to the EJB bean:
@RolesAllowed({UserRole.ADMINISTRATOR})
@TransactionAttribute(TransactionAttributeType.NEVER)
public List getThirdPartyOrgsForLogin(String username, ContextInfo contextInfo) throws BusinessException {
...
...
}
When I add a debugger into the mix, and set a breakpoint on the first log statement, it doesn't even get hit. The logger isn't even called. But I do see JBoss' org.jboss.ejb3.security.RoleBasedAuthorizationInterceptor
class invoked.
I even tried adding a precendence to aop.xml
, but that failed (not surprisingly):
<aspectj>
<aspects>
<aspect name="security.ejbAccessLogger" />
<concrete-aspect name="security.ejbAccessLogger" precedence="security.logger.EJBAccessLogger,org.jboss.ejb3.security.RoleBasedAuthorizationInterceptor"/>
</aspects>
<weaver options="-verbose -showWeaveInfo -debug" />
</aspectj>
Is there a reason why JBoss' interceptor would be called prior to mine? Is there any way I can advise my EJB authorization calls?