Implementing the authentication mechanism
In our example of implementing an authentication mechanism, we will create an application with resources that receive a request and return hello world messages to the user. However, this resource is protected and the user needs to be authenticated in order to access this resource. Further, we will set up some security policies and associations through the deployment descriptor file, some security policies to some resources using annotation, and some security policies to some resources using the programmatic configuration. We will also use basic authentication. To configure the security policies using the deployment descriptor file and programmatic configuration, we will use a JAX-RS resource. To configure the security policies using annotation, we will use a servlet. All of the examples used here are secure in a web application, but Java EE 8 permits the use of authentication mechanisms on the enterprise application. In this example, the following...