Wednesday, July 30, 2008

Using EJBContext from an EJB 3 Interceptor

I got a question from a customer that he wants to use EJBContext from an EJB 3 Interceptor.

Yes, it’s very simple. Just inject the EJBContext into the interceptor using @Resource injection.

See the example code that uses methods of SessionContext as follows:


package actionbazaar.buslogic;

import javax.annotation.Resource;
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;

public class CheckPermissionInterceptor {
@Resource
private javax.ejb.SessionContext ctx;


@AroundInvoke
public Object checkUserRole(InvocationContext ic) throws Exception {
System.out.println("*** CheckPermission Interceptor invoked for "
+ ic.getTarget() + " ***");
if (!ctx.isCallerInRole("admin")) {
throw new SecurityException("User: '"
+ ctx.getCallerPrincipal().getName()
+ "' does not have permissions for method "
+ ic.getMethod());
}
return ic.proceed();
}
}

If you want the run-able version of the example code, you can download from http://manning.com/panda and look at Chapter 5 example.

Monday, July 28, 2008

My Sessions at Oracle Open World 2008

I’ve two sessions at Oracle Open World 2008, San Francisco. Here are my session details:

S298520 : Best Practices for Managing Your Oracle WebLogic Environment with Oracle Enterprise Manager
Track: Application Server and Transaction Processing
Room: Rm 2006
Date: 2008-09-22
Start Time: 11:30

S298522 : Top Five Things DBAs Must Know About Managing Middleware
Track: Application Server and Transaction Processing
Room: Rm 2003
Date: 2008-09-25
Start Time: 15:00

See you at San Francisco!



Friday, July 18, 2008

EJB 3 In Action available at Safari Online

If you enjoy reading online then it's a good news for readers of EJB 3 in Action. It is now available online at Safari

Monday, July 07, 2008