Java Reference
In-Depth Information
LISTING 8-10 (continued)
//Do some security checks!
Logger.getLogger("SecurityLog").info(context.getMethod()
.getName()+ "is accessed!");
String user = context.getContextData.get("user");
if (user == null){
user = (String)context.getParameters()[0];
context.getContextData.put("user", user)'
}
return context.proceed();
}
@PostConstruct
public void onStart(){
Logger.getLogger("SecurityLog").info("Activating");
}
@PreDestroy
public void onShutdown(){
Logger.getLogger("SecurityLog").info("Deactivating");
}
}
Just like the EJB interceptors, the @Interceptor annotation needs to be used to promote the class
i le to an interceptor. The @Secure annotation binds the interceptor. Finally, the @AroundInvoke
annotation marks the method to be executed during intercepted calls.
The next step is to implement the annotation on an advice, as shown in Listing 8‐11.
LISTING 8‐11: Implementing the @Secure on an advice
package com.devchronicles.interceptor;
import javax.interceptor.Interceptors;
@Secure
public class SomeBusinessBean {
public void startService(){
//Complex business logic
Logger.getLogger("AppLog").info("done...");
}
public void startAnotherService(){
//Complex business logic
Logger.getLogger("AppLog").info("done again...");
}
}
Search WWH ::




Custom Search