Implementing the authentication interceptor
In our final example of implementing the authentication interceptor,we will create an application with resources that receives a user request and returns hello world messages to the user, but this resource is protected and the user needs to be authenticated in order to access the resource.However, this protection is achieved by authenticating the interceptor implemented using the CDI interceptor, which captures a call to a resource and validates the user access. Further, we will use the basic authentication mechanism to do an authentication validation; the source of the user data will not be managed by the application server and Java EE, but by a custom data source. In this example, the following classes are used:
DataSource
: This is the data source that contains security user information.Auth
: This is the interface used to define a method to validate authentication and authorization.AuthImpl
: This is the class that implements theAuth
interface...