To implement the CDI interceptor, we need to create a qualifier to be used to configure a class or method to be intercepted. In the following code block, we have a qualifier, called Authentication, with a parameter, called roles, and these are used to declare the roles that are permitted to access a resource:
import javax.enterprise.util.Nonbinding;import javax.interceptor.InterceptorBinding;import java.lang.annotation.*;@Inherited@InterceptorBinding@Retention(RetentionPolicy.RUNTIME)@Target({ElementType.METHOD, ElementType.TYPE})public @interface Authentication { @Nonbinding String[] roles() default {};}
In the following code block, we have the AuthenticationInteceptor class, which is used as an interceptor. ...