Securing the endpoints

To secure the REST server, we will use a filter just like we used in Chapter 25, Taking Notes with Monumentum. We'll start by defining the annotation that will specify which endpoints need to be secured, as follows:

    @NameBinding 
    @Retention(RetentionPolicy.RUNTIME) 
    @Target({ElementType.TYPE, ElementType.METHOD}) 
    public @interface Secure {} 

We will apply this preceding annotation to each secured endpoint (annotations condensed to one line for brevity):

 @GET @Path("conversations") @Secure public Response getConversations() { ... @POST @Path("conversations") @Secure public Response sendMessage(Message message) throws InterruptedException { ... @GET @Path("status") @Produces(SseFeature.SERVER_SENT_EVENTS) @Secure public ...

Get Java 9: Building Robust Modular Applications now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.