O'Reilly logo

JBoss Weld CDI for Java Platform by Ken Finnigan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding interceptors for our services

Before we begin developing our services, as part of the design process, we decided that we wanted to restrict access to some methods based on the User role and that some methods would require a Transaction object to be present.

Securing methods with an interceptor

To be able to develop an interceptor that we can use in our services, there are a few pieces that must be created, as shown in the following list:

  1. We need to define an enum function for the possible roles using the following code:
    public enum RoleType {
        GUEST,
        USER,
        ORDER_PROCESSOR,
        ADMIN;
    }
  2. We also need an annotation that we can add to methods to inform CDI that we want them to be intercepted:
    @InterceptorBinding @Target( { TYPE, METHOD } ) @Retention( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required