Provided by the CDI javax.annotation.security package, it contains all we need to ensure an enterprise component as an EJB or a servlet. With these annotations, each bean can be authorized with default or custom roles by simply adding them in the bean that you want authorized. See now how to use these annotations. We need an EJB container because at difference of Weld it already works under an authentication and authorization system.
Start with an interface:
public interface Caller {
<V> V call(Callable<V> callable) throws Exception;
}
And two actors, the manager and the employee representing with implementations of the Caller interface. The manager runs with a role called Manager:
@RunAs("Manager")
public class ManagerBean implements Caller {
@PermitAll
public <V> V call(Callable<V> callable) throws Exception {
return callable...